일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | ||||
4 | 5 | 6 | 7 | 8 | 9 | 10 |
11 | 12 | 13 | 14 | 15 | 16 | 17 |
18 | 19 | 20 | 21 | 22 | 23 | 24 |
25 | 26 | 27 | 28 | 29 | 30 | 31 |
- actuator heapdump
- so hooking
- Android 취약점진단
- native code hooking
- Frida
- actuator env
- actuator endpoint
- gdb 메모리 덤프
- source map
- 취약점진단
- gdb memory dump
- 취약점
- graphiql
- http request smuggling
- spring boot 취약점
- digest hooking
- Firebase Real-time Database
- hooking script
- trace cipher
- 보안진단원
- 휴대폰 번호 변조
- trace intent
- firebasescanner
- 무결성 검증 우회
- gdb debug
- Firebase 취약점
- Android
- APP 진단
- without frida
- android hooking
- Today
- Total
Und3r__Score__
Memory dump without frida 본문
Android APP 진단 시 메모리 내 중요정보가 노출되고 있는지 확인하는 항목이 있습니다. 해당 항목을 확인하기 위해 일반적으로 Frida를 이용해서 메모리 덤프를 수행하는데, 최근 Frida 없이 진단해야 하는 CASE가 존재했습니다.
그래서 대안방안으로 gdb를 이용하여 메모리 덤프를 수행했고, 관련 스크립트 및 절차는 아래와 같습니다.
스크립트 및 파일
- gdb.exe
/ Windows에서 실행시킬 gdb client 파일
/ 다운로드 페이지 (Windows 버전에 맞게 다운로드)
Debugger, gdb, for Windows
GNU Debugger for Windows This web page provides 32-bit and 64-bit binaries of gdb for Windows for download. Equation Solution build the debugger from GNU gdb. It is a free software under General Public License. Distribution of GNU compilers
www.equation.com
- gdbserver
/ Android 에뮬레이터에서 실행시킬 gdb server 파일
/ 다운로드 페이지 (adb shell getprop 명령어로 android 버전 확인)
ndk/prebuilt - android_tools - Git at Google
chromium.googlesource.com
- gdbdump.bat
/ line 2의 [process]를 덤프하고자하는 앱의 프로세스명으로 수정
/ memory를 덤프하려는 앱의 PID를 이용하여 메모리 매핑 정보를 가져오는 batch 파일
:::::::::: Get application pid
FOR /F "tokens=*" %%a IN ('adb shell ps -ef ^| findstr [process] ^| head -1 ^| awk "{print $2}"') do (SET pid=%%a)
@echo off
echo %pid%
:::::::::: Get application smaps info
adb shell grep "rw-p" /proc/%pid%/smaps | awk -F"[- ]" "{print $1, $2}" > maps.txt
::::/proc/[pid]/maps=Memory maps to executables and library files (2.4)
::::/proc/[pid]/smaps=An extension based on maps, showing the memory consumption of each mapping and flags associated with it
- gdbdump.py
/ Windows에서 실행시킬 python 파일
/ gdbdump.bat 실행 결과인 maps.txt 파일을 이용하여 실행 중인 gdb.exe에 dump memory 명령어 입력하여 메모리 덤프
/ 메모리 덤프 완료 후 strings를 이용하여 문자열만 출력
import pyautogui
import subprocess
import time
import string
import os
######Run Batch file
subprocess.call([r'gdbdump.bat'])
######Activate gdb.exe window
win = pyautogui.getWindowsWithTitle("gdb.exe")[0]
print(win)
win.activate()
######Dump memory function
def dumpMem(filenm, startAddr, endAddr):
cmd = "dump memory " + filenm + " 0x" + startAddr + " 0x" + endAddr + "\n"
pyautogui.write(cmd)
def stringsFile(filenm):
cmd = "strings64.exe " + filenm + ">> strings.txt"
os.system(cmd)
######Read maps.txt file
mapsFile = open("maps.txt", "r")
lines = mapsFile.readlines()
for line in lines[1:]:
addr = line.split(' ')
startAddr = addr[0].strip()
endAddr = addr[1].strip()
filenm = ".\\dump\\" + startAddr + "-" + endAddr + ".dump"
dumpMem(filenm, startAddr, endAddr)
time.sleep(2)
- strings.exe, strings64.exe / 다운로드 페이지
절차
① Windows에서 gdb.exe 파일 위치에 dump 폴더를 생성
② gdbserver 파일을 안드로이드 디바이스 내로 push, 권한 설정
앱의 PID를 확인/이용하여 gdbserver 실행
> adb push gdbserver /data/local/tmp
> adb shell
# cd /data/local/tmp
# chmod 777 gdbserver
# ps -ef | grep [process]
# ./gdbserver :9999 --attach [PID]

③ Windows에서 포트포워딩 수행
> adb forward tcp:9999 tcp:9999

④ gdb.exe 실행 및 원격 디버깅 설정
(gdb) target remote :9999

⑤ gdbdump.py 실행
> python gdbdump.py

strings.txt 파일과 dump 폴더 하위의 파일들 확인 가능
'취약점진단 > Mobile (Android, iOS)' 카테고리의 다른 글
_Frida Hooking Script 04_ 무결성 검증 우회 (0) | 2024.02.21 |
---|---|
_Frida Hooking Script 03_ native code hooking (0) | 2024.02.21 |
_Frida Hooking Script 02_ trace intent, cipher (0) | 2024.02.20 |
_Frida Hooking Script 01_ 휴대폰 번호 변조 (0) | 2024.02.20 |
Firebase Real-time Databases Misconfiguration (0) | 2024.02.20 |