아래 언급된 모든 단계는 macOS Mojave에 있습니다.
pip3을 사용하여 frida-tools
설치
$ pip --version
및 $ pip3 --version
명령을 실행하여 Python 3x 에서 어떤 pip가 나오는지 확인하세요. 예를 들어 아래와 같은 버전 정보가 표시됩니다.
$ pip 19.0.3 from /usr/local/lib/python3.7/site-packages/pip (python 3.7)
그런 다음 올바른 pip 명령을 실행하여 frida-tools
설치합니다(예: pip3
$ pip3 install frida-tools
성공 결과:
....
Successfully built frida-tools frida
Installing collected packages: colorama, frida, six, wcwidth, prompt-toolkit, pygments, frida-tools
Successfully installed colorama-0.4.1 frida-12.4.7 frida-tools-1.3.2 prompt-toolkit-2.0.9 pygments-2.3.1 six-1.12.0 wcwidth-0.1.7
설치 테스트
cat
바이너리를 임시 폴더(예: /tmp/cat
에 복사한 다음 해당 디렉토리에서 cat
실행합니다.
$ mkdir ~ /frida
$ cp /bin/cat /frida/cat
$ /frida/cat
다른 터미널에서 다음 내용으로 example.py
파일을 만듭니다.
import frida
def on_message ( message , data ):
print ( "[on_message] message:" , message , "data:" , data )
session = frida . attach ( "cat" )
script = session . create_script ( """'use strict';
rpc.exports.enumerateModules = function () {
return Process.enumerateModulesSync();
};
""" )
script . on ( "message" , on_message )
script . load ()
print ([ m [ "name" ] for m in script . exports . enumerate_modules ()])
그런 다음 아래 명령을 사용하여 example.py
스크립트를 실행하십시오.
$ python3 example.py
출력은 다음과 유사해야 합니다(플랫폼 및 라이브러리 버전에 따라 다름).
[ u'cat' , …, u'ld-2.15.so' ]
안드로이드 adb
명령
adb
장치를 볼 수 있는지 확인하십시오.
$ adb devices -l
이는 또한 adb 데몬이 데스크톱에서 실행되고 있는지 확인하여 Frida가 USB 또는 Wi-Fi를 통해 연결되어 있는지 여부에 관계없이 장치를 검색하고 통신할 수 있게 해줍니다.
frida-server
설치아래 단계는 macOS Majave의 Android Emulator Nexus 6P(x86) api 23을 기반으로 합니다.
먼저 frida-server 릴리스 페이지에서 Android용 최신 frida-server
다운로드합니다. 예를 들어 Android x86
에뮬레이터의 경우 frida-server-12.4.7-android-x86.xz를 다운로드하여 에뮬레이터에서 실행해야 합니다.
$ adb root # might be required
$ adb push frida-server /data/local/tmp/
$ adb shell " chmod 755 /data/local/tmp/frida-server "
$ adb shell " /data/local/tmp/frida-server & "
마지막 단계에서 아래 오류가 표시되는 경우:
Unable to load SELinux policy from the kernel: Failed to open file “/sys/fs/selinux/policy”: Permission denied
그런 다음 루트 셸을 사용하여 frida-server
실행해야 합니다. 예:
$ adb shell
angler:/ $ su
angler:/ # /data/local/tmp/frida-server &
[1] 12089
angler:/ #
[1] 12089
frida-server
의 프로세스 ID입니다.
이제 데스크탑에서 기본 사항이 작동하는지 확인할 차례입니다. 달리다:
frida-ps -U
그러면 다음과 같은 프로세스 목록이 제공됩니다.
PID Name
----- ---------------------------------------------------
721 ATFWD-daemon
4450 adbd
730 [email protected]
407 [email protected]
408 [email protected]
409 [email protected]
410 [email protected]
406 [email protected]
Java 소스 코드 내에서 Boolean
값을 변조하려면 즉, Boolean bTamperingSucces = false;
, 또는 관심 있는 다른 코드.
apktool
Apktool 웹사이트에서 가져올 수 있습니다. 이 페이지의 단계에 따라 apktool을 설치하세요.
adb
Android SDK와 함께 제공되며 <your-some-path>/Android/sdk/platform-tools/adb
디렉터리에서 찾을 수 있습니다.
apksigner
키스토어 파일로 apk에 서명하는 것입니다. 이 도구는 <ANDROID_HOME>/Android/sdk/build-tools/28.0.3/apksigner
디렉터리에서 찾을 수 있으며 사용법은 명령줄 apksigner에 문서화되어 있습니다.
DecompileApk에서 예제 프로젝트를 복제합니다.
이미 컴파일된 apk 파일 DecompileApk/app/release/app-release.apk
찾으세요.
apktool을 사용하여 디컴파일합니다.
$ cd < your-path > /DecompileApk/app/release/
$ apktool d --no-res -f app-release.apk
아래 출력이 표시됩니다.
I: Using Apktool 2.4.0 on app-release.apk
I: Copying raw resources...
I: Baksmaling classes.dex...
I: Copying assets and libs...
I: Copying unknown files...
I: Copying original files...
smali 코드 디렉토리에서 DecompileApk/app/release/app-release/smali/com/arophix/decompileapk/MainActivity.smali
를 찾아 아래 코드를 찾으세요.
const / 4 p1 , 0x0
0x0
( false
의미)을 0x1
( true
의미)로 변경하고 파일을 저장하면 됩니다.
apktool을 사용하여 변조된 apk를 빌드합니다.
apktool b app - release
아래 출력이 표시됩니다.
I: Using Apktool 2.4.0
I: Checking whether sources has changed...
I: Smaling smali folder into classes.dex...
I: Checking whether resources has changed...
I: Copying raw resources...
I: Copying libs... (/lib)
I: Building apk file...
I: Copying unknown files/dir...
I: Built apk...
dist
디렉토리 DecompileApk/app/release/app-release/dist/app-release.apk
에서 새로 빌드된 apk를 찾으세요.
DecompileApk/app/decompileapk.jks
에 있는 apksigner 및 키 저장소를 사용하여 apk에 서명합니다(해당 사례에 따라 키 저장소 및 apk 경로를 수정하십시오).
$ < ANDROID_HOME > /sdk/build-tools/28.0.3/apksigner sign --ks ../decompileapk.jks app-release.apk
아래 출력이 표시되고 비밀번호 123456
입력해야 합니다.
Keystore password for signer # 1:
adb 명령을 사용하여 서명된 apk를 설치합니다.
$ adb install < path-to-the-tampered-apk > /app-release.apk
화면에 "Hello from C++"
표시되는 대신 이제 "Hello, Android reverse engineer!"
가 표시됩니다. .
Frida를 사용하여 Android Java 소스 코드를 연결합니다.
Hook_java_methods.py에서 스크립트를 찾아 아래 명령을 사용하여 실행한 후 시작된 Android 앱의 버튼을 클릭하세요.
$ python3 hook_java_methods.py
[ * ] Running CTF
[ * ] onClick
[ * ] Called - isPhoneRooted ()
[ * ] onClick
[ * ] Called - isPhoneRooted ()
아래와 같은 오류가 표시되는 경우:
$ frida.ServerNotRunningError: unable to connect to remote frida-server: closed
에뮬레이터에서 frida-server
시작했음을 기억하십시오.
한편, 성공하면 에뮬레이터 화면에서 토스트 메시지가 Device not rooted
로 변경된 것을 볼 수 있습니다.
Frida를 사용하여 Android C 소스 코드를 연결합니다.
APK 디컴파일
먼저, apktool을 사용하여 apk를 디컴파일하여 공유 라이브러리, 즉 libnative-lib.so
추출합니다.
$ cd DecompileApk/app/release
$ apktool d --no-res app-release.apk
대상 JNI 메소드 찾기
둘째, 아래 명령을 사용하여 후크할 JNI 함수를 찾습니다.
$ nm --demangle --dynamic app-release/lib/x86/libnative-lib.so
아래 출력이 표시됩니다.
00004d80 T Java_com_arophix_decompileapk_MainActivity_stringFromJNI
000090b0 T std::bad_typeid::what () const
00005cf0 T std::bad_exception::what () const
00005e70 T std::bad_array_length::what () const
00005df0 T std::bad_array_new_length::what () const
00008ff0 T std::bad_cast::what () const
...
이름으로 후크 C 함수
Hooknative-by-function-name.py에서 스크립트를 찾아 아래 명령을 사용하여 실행한 후 시작된 Android 앱의 버튼을 클릭하세요.
$ python3 hooknative-by-function-name.py
[ * ] Running Arophix Hook Test ...
Java_com_arophix_decompileapk_MainActivity_stringFromJNI called with:
ret: 0x200019
아래와 같은 오류가 표시되는 경우:
$ frida.ServerNotRunningError: unable to connect to remote frida-server: closed
에뮬레이터에서 frida-server
시작했음을 기억하십시오.
한편, 에뮬레이터 화면에서는 Frida is hooking this displayed text from Native layer by function name.
성공하면.
주소별 Hook C 함수
Hooknative-by-function-address.py에서 스크립트를 찾아 아래 명령을 사용하여 실행한 후 시작된 Android 앱의 버튼을 클릭하세요.
$ python3 hooknative-by-function-address.py
[ * ] Running Arophix Hook Test ...
[+] membase: 0xb2acd000
[+] addressOfStringFromJni: 0xb2ad1d80
[++] addressOfStringFromJni: 0xb2ad1d80
ret: 0x19
아래와 같은 오류가 표시되는 경우:
$ frida.ServerNotRunningError: unable to connect to remote frida-server: closed
에뮬레이터에서 frida-server
시작했음을 기억하십시오.
한편, 에뮬레이터 화면에서는 Frida is hooking this displayed text from Native layer by function address.
성공하면.