서론
프로젝트를 진행하는 과정에서, 정리해두면 좋겠다는 부분이 있어서 오랜만에 글을 쓴다
글을 안 쓴지 이렇게 오래되었을 줄이야..
본론으로 넘어가서, 오늘 작성할 내용은 Java 코드를 사용하여, Frida Server를 감지하는 코드이다
해당 코드를 여러 번 시도해본 결과, 특징과 주의사항은 아래와 같다
1. Android 14에서는 작동하지 않는다 ( 현재, Android 9까지 작동되는 것을 확인하였다 )
2. Runtime.getRuntime.exec()를 사용하는 것이 아닌, ProcessBuilder 객체를 사용해야한다
3. ProcessBuilder에 Argument를 줄 때, "ps -a" 가 아닌, "ps", "-a" 이런식으로 주어야 한다
본론으로 들어가보자
- Runtime.getRuntime.exec()을 사용하는 방식
public static boolean isFridaServerOn(){
boolean bool = false;
try {
Process process = Runtime.getRuntime().exec("netstat");
if(process != null){
InputStream is = process.getInputStream();
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
String line;
if( (line = reader.readLine()) != null ){
Log.i(TAG, "isFridaServerOn : " + line);
if(line.contains("frida")){
bool = true;
}
}
}
} catch(Exception e){
e.printStackTrace();
}
Log.i(TAG, "isFridaServerOn : " + bool);
return bool;
}
해당 방식을 사용하면 정확하게 인터넷 연결 내용을 보여주지 않는다
위에는 Runtime.getRuntime.exec("ps", "-a")를 사용한 결과이다
이것 또한 제대로 보여주지 않는다
하지만 ProcessBuilder는 다르다
- ProcessBuilder를 사용하는 방법
public static boolean test() {
boolean bool = false;
try {
ProcessBuilder processBuilder = new ProcessBuilder("netstat");
Process process = processBuilder.start();
BufferedReader reader = new BufferedReader(new InputStreamReader(process.getInputStream()));
String line;
if( (line = reader.readLine()) != null ){
while ((line = reader.readLine()) != null) {
Log.i("Detect", "test() : " + line );
if(line.contains("frida")){
Log.i("Detect", "test() : " + "frida Server Detected - " + line );
bool = true;
break;
}
}
}
// 프로세스 종료
process.waitFor();
} catch (IOException | InterruptedException e) {
e.printStackTrace();
}
Log.i("Detect", "tesT() : " + String.valueOf(bool) );
return bool;
}
frida server를 실행한 후, ProcessBuilder를 사용하면 위와 같이, frida server를 detect 할 수 있다
위에서 언급하였듯, Android 14에서는 작동하지 않는다 Android 9까지는 작동을 확인하였다
마치며
현재, 취약한 앱을 개발하는 개인 프로젝트를 진행하고 있다
Java코드 단에서 Root detection과 frida detection을 구현하고 있는 단계인데,
의외로 구글링해서 나온 코드들은 Android 14버전에서 제대로 detection을 못해주는 경우가 많았다
Java 코드 단에 구현이 마무리 되면 JNI를 통해, Native단에서도 detection 코드를 구현할 계획이다
화이팅 !@!@
'Mobile' 카테고리의 다른 글
[붉은외계인] Mobile - OWASP UnCrackable L3 (0) | 2024.03.12 |
---|---|
[붉은외계인] Mobile - OWASP UnCrackable L2 (0) | 2024.03.05 |
[붉은외계인] Mobile - OWASP UnCrackable L1 (0) | 2024.03.04 |
[붉은외계인] Mobile - FridaLab 풀이 (1) | 2024.02.26 |
[붉은외계인] Mobile - smali 코드 분석 1 with KGB Messenger (0) | 2024.02.14 |