جميع الخطوات المذكورة أدناه موجودة على نظام التشغيل macOS Mojave
تثبيت frida-tools
مع pip3
قم بتشغيل الأمر $ pip --version
و $ pip3 --version
للتحقق من النقطة التي تأتي من Python 3x . على سبيل المثال، يجب أن تشاهد معلومات الإصدار كما هو موضح أدناه:
$ 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 أو WiFi.
frida-server
على المحاكي (أو الجهاز الحقيقي)تعتمد الخطوات أدناه على Android Emulator Nexus 6P (x86) api 23 على macOS Majave.
أولاً، قم بتنزيل أحدث إصدار من 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
.
الآن، على سطح المكتب الخاص بك، حان الوقت للتأكد من أن الأساسيات تعمل. يجري:
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]
للتلاعب بقيمة Boolean
داخل كود مصدر Java، أي 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...
ابحث عن DecompileApk/app/release/app-release/smali/com/arophix/decompileapk/MainActivity.smali
ضمن دليل كود 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...
ابحث عن ملف APK الذي تم إنشاؤه حديثًا من دليل dist
DecompileApk/app/release/app-release/dist/app-release.apk
قم بتسجيل ملف APK باستخدام apksigner وkeystore الموجود في DecompileApk/app/decompileapk.jks
(يُرجى تعديل مسارات keystore وapk وفقًا لحالتك وفقًا لذلك)،
$ < ANDROID_HOME > /sdk/build-tools/28.0.3/apksigner sign --ks ../decompileapk.jks app-release.apk
يجب أن تشاهد النتائج أدناه وأدخل كلمة المرور 123456
Keystore password for signer # 1:
قم بتثبيت APK الموقع باستخدام أمر adb.
$ adb install < path-to-the-tampered-apk > /app-release.apk
بدلاً من رؤية "Hello from C++"
من الشاشة، يجب أن ترى الآن "Hello, Android reverse engineer!"
.
ربط كود مصدر Android Java باستخدام Frida.
ابحث عن البرنامج النصي من 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
في حالة النجاح.
ربط كود مصدر Android C باستخدام Frida.
فك APK
أولاً، قم بفك ترجمة ملف apk باستخدام أداة apktool لاستخراج المكتبة المشتركة، أي 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.
إذا النجاح.
وظيفة ربط 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.
إذا النجاح.