반응형

android 앱 진단시 so파일 디버깅은 주로 IDA를 활용하나, gdb를 이용한 동적디버깅도 가능함.

 

■환경구성 및 attach까지

- 칼리(2019.04버전)에서

apt-get install adb

android-ndk 다운로드(https://developer.android.com/ndk/downloads/index.html)    // ndk에 gdb 클라이언트 파일은 포함되어 있지 않음

aarch64-linux-android-4.9-gdb 다운로드(https://android.googlesource.com/platform/prebuilts/gcc/linux-x86/aarch64/aarch64-linux-android-4.9/+/a7bb6f39cd99b2fb26ecc2d3cb984d18cd259d24/bin)

다운로드한 "aarch64-linux-android-gdb" 파일을 "android-ndk-r21d/toolchains/aarch64-linux-android-4.9/prebuilt/linux-x86_64/bin/" 으로 이동

 

vi ~/.bashrc --> PATH 설정

ndk 디렉터리(android-ndk-r21d/prebuilt/android-arm64/gdbserver/)에 있는 gdbserver를 안드로이드 단말기의 /system/bin/ 하위로 복사

 

 

- 안드로이드에서

tar cvfz /sdcard/so.tar.gz /system/lib64    // 64비트 시스템 library 압축. 

cp /data/app/<대상 앱>/lib/<대상 .so파일> /sdcard    // 분석 대상 .so파일 복사

 

안드로이드 단말기에서 gdbserver 실행.

gdbserver :<port> --attach <pid>

 

 

- 칼리에서

mkdir gdbtest

cd gdbtest

 

adb pull /system/bin/app_process64

adb pull /sdcard/so.tar.gz

adb pull /sdcard/<대상 .so파일>

tar xvfz so.tar.gz

 

aarch64-linux-android-gdb app_process64

set solib-search-path ~/gdbtest

target remote <단말기IP>:<port>    // target process attach

 

 

■so파일 동적디버깅(OWASP UnCrackable level2 대상 test)

layout regs    // reigsters 정보 TUI 모드 전환.

layout asm    // TUI 모드 전환. 보기 편함

 

info shared [so파일 이름]   // 대상 so파일의 주소정보 파악

 

info functions [관심 함수명]    // 관심 함수의 주소정보 파악. 관심함수는 IDA에서 확인 가능.

 

x/ni <주소>    // 관심 함수의 주소값에서 i(Instruction) 기준 n줄의 Instruction 출력. ida로 같이 보면서 breakpoint를 설정할 주소값을 파악하는게 중요.

 

b *<주소값>    // breakpoint 설정

info breakpoints     // 설정된 breakpoint 출력

 

display/ni $pc    // 지금 주소부터 n개 Instruction 출력. 이 display명령은 등록되어 instruction을 진행할때마다 n개의 instruction을 출력.(auto-display).

display/ni $pc-n*4    // instruction 주소값이 4만큼씩 증가한 경우, 이전 n개의 instruction 출력. ex. display/3i $pc-12 

info display    // 등록된 display 명령 확인

delete display <no.>    // 등록된 display 명령 삭제

 

continue    // process continue until hit the breakpoint

x/s <address>    // 주소값에 저장되어 있는 정보를 문자열로 출력

 

※ gdb, lldb 명령어 비교

https://lldb.llvm.org/use/map.html#executable-and-shared-library-query-commands 

 

※ Reference

https://simoneaonzo.it/gdb-android/

https://resources.infosecinstitute.com/android-hacking-and-security-part-20-debugging-apps-on-android-emulator-using-gdb/#gref

https://say2.tistory.com/entry/android-gdb-%EB%94%94%EB%B2%84%EA%B9%85%ED%95%98%EB%8A%94%EB%B2%95

https://mitny.github.io/articles/2016-08/gdb-command

https://stackoverflow.com/questions/1902901/show-current-assembly-instruction-in-gdb

 

반응형

+ Recent posts