Hack/No filtered

iOS 취약점 진단 (메모리 덤프, 파일 비교)

Jaden.. 2022. 2. 3. 12:50

[메모리 덤프]
1. gdb 설치

2. ssh로 연결
  > 대상 App의 PI 및 앱 저장경로 확인 (ps -ef | grep Appname)
  > PID를 이용하여 gdb Attach (gdb -p PID)
  > break point 설정으로 heap 구역 리턴값 확인
   (gdb) b malloc : malloc에 breakpoint 설정 후 breakpoint 된 메모리 주소 확인
   (gdb) c : 실행
   (gdb) finish
   (gdb) i r r0 : into register 현재 레지스터 상태 확인 (r0 : return address 확인)
   (gdb) i mach-region 0x00000000 : 해당 주소의 memory map 및 구역의 속성 확인 (덤프 시작 주소 및 끝 주소 확인)
   (gdb) dump memory Test.dump 0x시작주소 0x끝주소
   (gdb) q

[메모리 덤프 2]
1. lldb 사용 (맥북에서 가능)

[파일 및 폴더 비교]
diff -qs directory1 directory2
identical : 동일
differ : 다름
Only in : 하나의 폴더에만 존재

[메모리덤프] lldb
필요 프로그램 : lldb, debugserver, iproxy(or tcprelay)

1. 연결설정 (iproxy, tcprelay 사용) - usb muxd 패키지 설치 필요 (iproxy 설치 됨, usb 터널링 용 패키지)
   1) ssh 터널링 설정 : # iproxy 22 2222
   2) debugserver 터널링 설정 : # iproxy 1234 1234

2. iPhone에서 APP 디버깅 설정
   1) debugserver 명령어로 포트 오픈 : # ./debugserver *:1234 -a appname
./debugserver *:1234 —attach=[pid]

3. 맥북에서 lldb로 디버깅 모드 진입 후 덤프
   1) # lldb
   2) (lldb) process connect connect://127.0.0.1:1234
   3) (lldb) image dump sections appname
   4) (lldb) memory read --outfile /tmp/mem 0x11003300 0x11003500 -force


4. sublime 등 메모장을 이용하여 메모리 내용 확인

Debugerserver signing
# hdiutil /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneos.platform/DeviceSupport/8.4/DeveloperDiskImage.dmg
# cp /Volumes/Developer/DiskImage/usr/bin/debugserver /Users/jongwook/
# vi entitlements.plist

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/ PropertyList-1.0.dtd"> 
<plist version="1.0"> 
<dict>
    <key>com.apple.springboard.debugapplications</key> <true/>
    <key>run-unsigned-code</key>
    <true/>
    <key>get-task-allow</key>
    <true/>
    <key>task_for_pid-allow</key>
    <true/>
</dict>
</plist>

#codesign -s - —entitlements entitlements.plist -f debug server

USB Muxd 설치 방법
https://github.com/libimobiledevice/usbmuxd
Brew install -v —fresh automaker autoconf lib tool wget libimobiledevice
Brew install -v —HEAD —fresh —build-from-source ideviceinstaller