'전체 글'에 해당되는 글 587건

 

 

환경 : 윈도 10

IDA 7.2 version

IDA dbgsrv 폴더 내 android_server, android_server64 

루팅된 기기로 adb push

 

아래 경로 참고

https://kinggod-daddong.tistory.com/3

 

IDA에서 안드로이드 원격 디버깅 방법

IDA가 설치된 경로로 이동하면 dbgsrv 디렉토리가 있다. dbgsrv 디렉토리에 있는 android_server를 data/local/tmp 위치로 push 한다. 이때 애뮬레이터의 CPU가 arm 속성을 가져야 한다. (실기기도 가능!) adb..

kinggod-daddong.tistory.com

 

/data/local/tmp 경로에

> adb push android_server /data/local/tmp

chmod 777 권한 변경

 

./android_server64 실행

파워쉘 창 하나더 열어서

adb forward tcp:23946 tcp:23946

 

모바일 디바이스 기기에서

ifconfig 후 wlan0 확인

 

IDA hostname : 192.168.X.X  Port : 디폴트

프로세스 확인 후 접근

 

- IDA64비트와 android_server64 로 원격디버깅 실행

 

'모바일' 카테고리의 다른 글

Android debugging Anti-cheating  (0) 2020.07.29
ios 환경에서 gdb 이용  (0) 2020.07.15
Android 안티디버깅 관련 대응방안  (0) 2020.07.15
frida source share  (0) 2020.07.14
iOS frida 환경 셋팅  (0) 2020.07.14
블로그 이미지

wtdsoul

,

 

참고

mobile-security.gitbook.io/mobile-security-testing-guide/android-testing-guide/0x05j-testing-resiliency-against-reverse-engineering

 

Android Anti-Reversing Defenses

 

mobile-security.gitbook.io

IDA 원격 디버깅이 가능하여 네이티브 단에서 대응방안이 필요함

 

1. ptrace 선점하는 자식프로세스 생성
2. 시간체크 함수 만들어서 일정시간 이상이면 디버깅 탐지
3. /proc/self/status 에서 tracerPid 값 확인해서 디버깅 탐지

- Using Fork and ptrace
- Timer Checks
- Checking TracerPid

 

Timer Checks

Debug.threadCpuTimeNanos indicates the amount of time that the current thread has been executing code. Because debugging slows down process execution, you can use the difference in execution time to guess whether a debugger is attached.

 

static boolean detect_threadCpuTimeNanos(){

long start = Debug.threadCpuTimeNanos();

 

for(int i=0; i<1000000; ++i)

continue;

 

long stop = Debug.threadCpuTimeNanos();

 

if(stop - start < 10000000) {

return false;

}

else {

return true;

}

}

 

Checking TracerPid

When you debug an app and set a breakpoint on native code, Android Studio will copy the needed files to the target device and start the lldb-server which will use ptrace to attach to the process. From this moment on, if you inspect the status file of the debugged process (/proc/<pid>/status or /proc/self/status), you will see that the "TracerPid" field has a value different from 0, which is a sign of debugging.

Remember that this only applies to native code. If you're debugging a Java/Kotlin-only app the value of the "TracerPid" field should be 0.

This technique is usually applied within the JNI native libraries in C, as shown in Google's gperftools (Google Performance Tools)) Heap Checker implementation of the IsDebuggerAttached method. However, if you prefer to include this check as part of your Java/Kotlin code you can refer to this Java implementation of the hasTracerPid method from Tim Strazzere's Anti-Emulator project.

When trying to implement such a method yourself, you can manually check the value of TracerPid with ADB. The following listing uses Google's NDK sample app hello-jni (com.example.hellojni) to perform the check after attaching Android Studio's debugger:

 

$ adb shell ps -A | grep com.example.hellojni

u0_a271 11657 573 4302108 50600 ptrace_stop 0 t com.example.hellojni

$ adb shell cat /proc/11657/status | grep -e "^TracerPid:" | sed "s/^TracerPid:\t//"

TracerPid: 11839

$ adb shell ps -A | grep 11839

u0_a271 11839 11837 14024 4548 poll_schedule_timeout 0 S lldb-server

You can see how the status file of com.example.hellojni (PID=11657) contains a TracerPID of 11839, which we can identify as the lldb-server process.

 

Using Fork and ptrace

You can prevent debugging of a process by forking a child process and attaching it to the parent as a debugger via code similar to the following simple example code:

 

void fork_and_attach()

{

int pid = fork();

 

if (pid == 0)

{

int ppid = getppid();

 

if (ptrace(PTRACE_ATTACH, ppid, NULL, NULL) == 0)

{

waitpid(ppid, NULL, 0);

 

/* Continue the parent process */

ptrace(PTRACE_CONT, NULL, NULL);

}

}

}

With the child attached, further attempts to attach to the parent will fail. We can verify this by compiling the code into a JNI function and packing it into an app we run on the device.

 

root@android:/ # ps | grep -i anti

u0_a151 18190 201 1535844 54908 ffffffff b6e0f124 S sg.vantagepoint.antidebug

u0_a151 18224 18190 1495180 35824 c019a3ac b6e0ee5c S sg.vantagepoint.antidebug

Attempting to attach to the parent process with gdbserver fails with an error:

 

root@android:/ # ./gdbserver --attach localhost:12345 18190

warning: process 18190 is already traced by process 18224

Cannot attach to lwp 18190: Operation not permitted (1)

Exiting

You can easily bypass this failure, however, by killing the child and "freeing" the parent from being traced. You'll therefore usually find more elaborate schemes, involving multiple processes and threads as well as some form of monitoring to impede tampering. Common methods include

 

 

이하 생략

 

'모바일' 카테고리의 다른 글

ios 환경에서 gdb 이용  (0) 2020.07.15
IDA Remote debugging 안드로이드  (0) 2020.07.15
frida source share  (0) 2020.07.14
iOS frida 환경 셋팅  (0) 2020.07.14
frida iOS 환경 셋팅 (Clutch, class-dump-ios, etc)  (0) 2020.07.14
블로그 이미지

wtdsoul

,

frida source share

모바일 2020. 7. 14. 18:19

https://codeshare.frida.re/browse

 

Frida CodeShare

27 | 68K Android SSL Re-Pinning, more information can be found here https://techblog.mediaservice.net/2017/07/universal-android-ssl-pinning-bypass-with-frida/ 9 | 19K Android antiroot checks bypass 7 | 6K Show useful info about AES encryption/decryption at

codeshare.frida.re

 

 

 

 

'모바일' 카테고리의 다른 글

IDA Remote debugging 안드로이드  (0) 2020.07.15
Android 안티디버깅 관련 대응방안  (0) 2020.07.15
iOS frida 환경 셋팅  (0) 2020.07.14
frida iOS 환경 셋팅 (Clutch, class-dump-ios, etc)  (0) 2020.07.14
frida ios dump ipa 추출  (0) 2020.07.14
블로그 이미지

wtdsoul

,