Posts The journey from (.apk) to Account TakeOver
Post
Cancel

The journey from (.apk) to Account TakeOver

centered image

^_^ السلام عليكم ورحمة الله وبركاته, يالله حيهم


Agenda:

  • SSL Pinning Bypass
  • Network Traffic Analysis
  • Basic Dynamic Analysis(Genymotion, adb, Frida, Objection)
  • Basic Static Analysis( Jadx-GUI )
  • Weak Encryption Algorithm
  • Password Generator(Crunch + Cusom Java script)
  • Account TakeOver


SSL Pinning Bypass:


طيب قبل نتكلم عن طرق التخطي خلونا ناخذ فكرة بسيطة وسطحية عن إيش هو من الأساس ؟
SSL Pinning:
بطرق مختلفة مثل(Pinned == Hard Coded) بداخل التطبيق تكون trustful certificates بكل بساطة خلونا نقول فيه

  • Certificate
  • Public Key
  • Hash

Conection Establishment وفي خلال عملية الـ
Certificate يقوم الكلاينت سايد بالتأكد من الـ

الكونيكشن بيتوقفMisMatch وإذا كان فيه أي
طيب بعد ماأخذنا نبذة سطحية عن الموضوع (الموضوع أكبر من كذا بكثير جدا) خلونا الحين نذكر بعض طرق التخطي
Check زي ماقلنا فوق فيه عملية
لازم بطريقة أو بأخرى نوقف العملية هذي علشان نصير قادرين نكون طرف ثالث في منتصف الكونيكشن ونقدر نعترض الترافيك

:التالي Process فيه بعض الطرق تعتمد على الـ

  • Identifying the CLASS
  • Identifying the method
  • Finding the return value
  • Hooking the method and modifying the return value

من هذي الطرق

  • SSLUnpinning - Xposed Module ( تطبيقات جاهزة وهذا سيناريو اليوم )
  • Objection
  • Custom Frida Scripts

الطريقتين الثانية والثالثة بإذن الله بشرحها مستقبلا , وهي إن شاء الله سهلة في حال الوصول للدالة المعنيًة

طيب ندخل في سيناريو اليوم , زي ماذكرت استخدمنا الطريقة الأولى بس قبل مانستخدمها على عماها خلونا نفهم وش اللي يصير خلف الكواليس
UnSSLPinning هنا كلام من الريبو الرسمي الخاص ببروجكت

1
If you need to intercept the traffic from an app which uses certificate pinning, with a tool like Burp Proxy, the SSLUnpinning will help you with this hard work! The SSLUnpinning through Xposed Framework, makes several hooks in SSL classes to bypass the certificate verifications for one specific app, then you can intercept all your traffic

طيب معليكم من فلسفتهم الزايدة , بكل إختصار لو نشوف السورس كود الخاص بالبروجكت
Common Libraries هو يعتمد بشكل كامل على بعض الـ
ويطبق عليه البروسيس المذكور فوق
okhttp3 ومنها اللي كانت موجودة بسيناريو اليوم
طيب كيف عرفنا التطبيق يستخدمها ؟
decompiled apk source code عن طريق الـ


:وبكذا بعد ماعرفنا خلونا نطبق

SSL Pinning هنا أول ماإكتشفت إن فيه



راح نفهم في قسم الستاتيك اناليسس كيف طلعناها okhttp3 library وهنا نشوف الـ

وعشان نفهم أكثر كيف قدر البروجكت يتخطاها , زي ماقلت لكم بتطبيق البروسيس المذكور فوق
بالسطرين 10 , 13 Check وهنا نشوف عملية الـ

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
public void check(String hostname, List<Certificate> peerCertificates) 
throws SSLPeerUnverifiedException {
    List<Pin> pins = findMatchingPins(hostname);
    if (pins.isEmpty()) return;
 
      for (int p = 0, pinsSize = pins.size(); p < pinsSize; p++) {
        Pin pin = pins.get(p);
        if (pin.hashAlgorithm.equals("sha256/")) {
          if (sha256 == null) sha256 = sha256(x509Certificate);
          if (pin.hash.equals(sha256)) return; // Success!
        } else if (pin.hashAlgorithm.equals("sha1/")) {
          if (sha1 == null) sha1 = sha1(x509Certificate);
          if (pin.hash.equals(sha1)) return; // Success!
        } else {
          throw new AssertionError();
        }
      }
    }

}



SSLUnpinning - Xposed Module وهنا الـ


طريقة إستعماله سهلة جدا


وأخيرا


Network Traffic Analysis:

:توصلت لثلاث أشياء API endpoints بعد فحص بعض الـ

  • Rate Limit مافيه أي
  • بمجرد عمل ريسيت للباسورد راح يتم عمل باسوورد جديد مكون من 4 أرقام فقط ( بإعتبار الشخص مفروض يدخل وبعدين يغيره )
  • Encryption صاير لها Request Body النقطة الأخيرة وهي اللي جابت كل الشغل اللي تحت كانت قيم المتغيرات فالـ

فهنا كل اللي علينا نسوي ريسيت باسوورد على أي حساب وبعد مايصير الباسوورد مجرد 4 أرقام نبدأ بتخمينها بحكم إن مافيه ريت ليمت
Encrypted لكن المشكلة قيم البارامترز كانت

مثل 0000 أو 9999 وأبدأ أخمن لأن الباك ايند سيرفر ماراح يتعرف عليها أبدأ Clear Text Passwords ماأقدر أرسل



بلشة صح ؟ اتفق

لاحظوا هنا قيمة الباسوورد , على فكرة أنا أدخلتها 0000
Encryption بس زي ماذكرت فيه عملية


Login endpoint وهنا للتأكيد مافيه أي ريت ليمت على الـ


:والآن نقول بسم الله تونا نبدأ


Basic Dynamic Analysis(Genymotion, adb, Frida, Objection):

Encryption بعد ماشفنا فوق إن فيه عملية
Encryption Algorithm الحين الهدف صار إننا ندور على الـ
ونحاول بطريقة ما نسوي باسووردز ليست من 0000 إلى 9999 بنفس المبدأ

طيب عشان ندور على الفنكشن المسؤولة عندنا طريقتين , الأولى ستاتيك نقعد نبحث بالكود لين تطلع عيوننا أو نخمن إسم الفنكشن ونسوي سيرش سريع
والثانية عن طريق الداينمك , بكل إختصار نشوف الكلاسس والميثودز
that are being loaded at run-time
وبعدها نروح ندور عليها فالكود

  • Dynamic Analysis:is the process of testing and evaluation of a program by executing data at run-time
  • Genymotion: Emulator that gives us rooted devices
  • Android Debug Bridge(adb): Android Debug Bridge (adb) is a versatile command-line tool that lets you communicate with a device. The adb command facilitates a variety of device actions, such as installing and debugging apps, and it provides access to a Unix shell that you can use to run a variety of commands on a device
  • Frida:it’s a dynamic code instrumentation toolkit. It lets you inject snippets of JavaScript or your own library into native apps on Windows, macOS, GNU/Linux, iOS, Android, and QNX. Frida also provides you with some simple tools built on top of the Frida API
  • Objection:is a runtime mobile exploration toolkit, powered by Frida, built to help you assess the security posture of your mobile applications

بعد ماعرفنا التولز نبدأ بسم الله نطبق

Emulator بعد ماننزل التولز اللي فوق نتصل بالجهاز الموجود بالـ
adb عن طريق
Frida-server بعدها ننقل الـ
Frida toolsلداخل الجهاز عشان نقدر نستفيد من بعض الـ



Objection طيب الحين راح نبدأ نستخدم الـ
هنا من الريبو الرسمي الخاص بالبروجكت

For all supported platforms, objection allows you to:

  • Patch iOS and Android applications, embedding a Frida gadget that can be used with objection or just Frida itself.
  • Interact with the filesystem, listing entries as well as upload & download files where permitted.
  • Perform various memory related tasks, such as listing loaded modules and their respective exports.
  • Attempt to bypass and simulate jailbroken or rooted environments.
  • Discover loaded classes and list their respective methods.
  • Perform common SSL pinning bypasses.
  • Dynamically dump arguments from methods called as you use the target application.
  • Interact with SQLite databases inline without the need to download the targeted database and use an external tool.
  • Execute custom Frida scripts.

    اللي يهمنا حاليا هو الشي اللي ضللته .
    بسم الله نشوف كيف نسويها

    Package قبل نسويها نحتاج نطلع إسم الـ
    Frida-tools هنا راح نستخدم وحدة من الـ
    frida-ps -U : list running processes


    بعد ماطلعت إسم الباكج الحين راح نستخدمه في الـ
    objection --gadget Package_Name explore
    هنا نسوي ليست لكل الكلاسز
    that are being loaded at run-time
    android hooking list classes



    وبعد ماوصلنا لأسماء الكلاسز نبدأ نسوي دمب لكل الميثودز الموجودة بكل كلاس
    android hooking watch class Class_Name
    Login وهنا نشوف وصلنا للـ
    لأن كان هدفي من البداية أشوف وش من البارامترز بالضبط

    Encryption اللي يصير لها


    Encryption وهنا قدرت أوصل لإسم الكلاس والفنكشن المسوؤلة عن الـ


    وبعد ماوصلنا لإسم الكلاس والفنكشن خلاص نقدر نبحث عنها ونبدأ شغل الستاتيك بإذن الله


    Basic Static Analysis( Jadx-GUI ):

طيب بعد ماعرفنا إسم الكلاسس والفنكشنز الحين بكل بساطة
Decompile the (.apk) file using ( jadx-GUI )
على خفيف Code Review ونبدأ شغل
هنا قطعت الشك باليقين وعرفت إيش البارامترز بالضبط اللي قاعد يصير لها
Encryption


  • Weak Encryption Algorithm:

Encryptionهنا الفنكشن المسؤولة عن الـ
Symmetric Encryption (AES electronic codebook mode encryption)


Keyعلى طول راح بالي للـ
وفعلا ببحث سريع لقيته


Password Generator(Crunch + Cusom Java script):

وبكذا فهمنا كل اللي صاير , الحين وقت نبدأ نسوي الشي اللي كنا مخططين له من البداية وهو باسووردز ليست من 0000 إلى 9999
Encrypted لكن تكون
بإستخدام نفس الفنكشن المستخدمة بالتطبيق
بإستخدام Clear Text Passwords فالبداية سويت
Crunch


GitHubموجودة بـ Library طيب أنا لقيت الـ
بحطها تحت بالمصادر إن شاء الله
داخل الإكليبس وبكذا أكون جاهز أسوي السكريبت على السريع jar file للـ import كان علي أسوي
النتيجة النهائية للكود :


clearPass.txt الكود بكل إختصار ياخذ كل اللي بملف الـ
Crunch اللي سويناه بإستخدام
Encryption ويسوي للقيم
encryptedPass.txt وبعدها يكتبها بملف

النتيجة النهائية للملف قبل وبعد


Account TakeOver:

Intruder وبكذا صرنا جاهزييييين ننقل الليست على الـ
وناخذ أي حساب


Done.

Final word:

دعواتكم لي ولوالدي ولمن يعز علي , وإعذروني على القصور , وأي تعديل أو إقتراح بكون شاكر جدا
Happy Hacking ^_^…

References:

  • https://frida.re/docs/home/
  • https://frida.re/docs/frida-ps/
  • https://github.com/sensepost/objection
  • https://github.com/tsug0d/AndroidMobilePentest101
  • https://blog.securityevaluators.com/bypassing-okhttp3-certificate-pinning-c68a872ca9c8
  • https://github.com/BullyBoo/Encryption
This post is licensed under CC BY 4.0 by the author.
Contenido