PinkArmor
    • Create new note
    • Create a note from template
      • Sharing URL Link copied
      • /edit
      • View mode
        • Edit mode
        • View mode
        • Book mode
        • Slide mode
        Edit mode View mode Book mode Slide mode
      • Customize slides
      • Note Permission
      • Read
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Write
        • Only me
        • Signed-in users
        • Everyone
        Only me Signed-in users Everyone
      • Engagement control Commenting, Suggest edit, Emoji Reply
    • Invite by email
      Invitee

      This note has no invitees

    • Publish Note

      Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

      Your note will be visible on your profile and discoverable by anyone.
      Your note is now live.
      This note is visible on your profile and discoverable online.
      Everyone on the web can find and read all notes of this public team.

      Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

      Explore these features while you wait
      Complete general settings
      Bookmark and like published notes
      Write a few more notes
      Complete general settings
      Write a few more notes
      See published notes
      Unpublish note
      Please check the box to agree to the Community Guidelines.
      View profile
    • Commenting
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
      • Everyone
    • Suggest edit
      Permission
      Disabled Forbidden Owners Signed-in users Everyone
    • Enable
    • Permission
      • Forbidden
      • Owners
      • Signed-in users
    • Emoji Reply
    • Enable
    • Versions and GitHub Sync
    • Note settings
    • Note Insights New
    • Engagement control
    • Make a copy
    • Transfer ownership
    • Delete this note
    • Save as template
    • Insert from template
    • Import from
      • Dropbox
      • Google Drive
      • Gist
      • Clipboard
    • Export to
      • Dropbox
      • Google Drive
      • Gist
    • Download
      • Markdown
      • HTML
      • Raw HTML
Menu Note settings Note Insights Versions and GitHub Sync Sharing URL Create Help
Create Create new note Create a note from template
Menu
Options
Engagement control Make a copy Transfer ownership Delete this note
Import from
Dropbox Google Drive Gist Clipboard
Export to
Dropbox Google Drive Gist
Download
Markdown HTML Raw HTML
Back
Sharing URL Link copied
/edit
View mode
  • Edit mode
  • View mode
  • Book mode
  • Slide mode
Edit mode View mode Book mode Slide mode
Customize slides
Note Permission
Read
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Write
Only me
  • Only me
  • Signed-in users
  • Everyone
Only me Signed-in users Everyone
Engagement control Commenting, Suggest edit, Emoji Reply
  • Invite by email
    Invitee

    This note has no invitees

  • Publish Note

    Share your work with the world Congratulations! 🎉 Your note is out in the world Publish Note No publishing access yet

    Your note will be visible on your profile and discoverable by anyone.
    Your note is now live.
    This note is visible on your profile and discoverable online.
    Everyone on the web can find and read all notes of this public team.

    Your account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Your team account was recently created. Publishing will be available soon, allowing you to share notes on your public page and in search results.

    Explore these features while you wait
    Complete general settings
    Bookmark and like published notes
    Write a few more notes
    Complete general settings
    Write a few more notes
    See published notes
    Unpublish note
    Please check the box to agree to the Community Guidelines.
    View profile
    Engagement control
    Commenting
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    • Everyone
    Suggest edit
    Permission
    Disabled Forbidden Owners Signed-in users Everyone
    Enable
    Permission
    • Forbidden
    • Owners
    • Signed-in users
    Emoji Reply
    Enable
    Import from Dropbox Google Drive Gist Clipboard
       Owned this note    Owned this note      
    Published Linked with GitHub
    • Any changes
      Be notified of any changes
    • Mention me
      Be notified of mention me
    • Unsubscribe
    # Frida for Android Pentesting — A Beginner’s Guide > Mục tiêu: Giới thiệu Frida, cách setup lab và các kỹ thuật dynamic instrumentation căn bản dùng trong pentest Android. --- ## 1. Giới thiệu - [Frida](https://frida.re/) là một dynamic instrumentation toolkit — tức là một công cụ cho phép bạn tiêm, quan sát và can thiệp vào code của một ứng dụng khi nó đang chạy. ![image](https://hackmd.io/_uploads/BkEX0qSige.png) - Frida cho phép chèn code vào app đang chạy để thay đổi hành vi (ví dụ thay return value, override hàm) mà không cần recompile. - Dễ dùng để tắt SSL pinning, anti-debug, root/emulator-detection… tức thì, giúp tiếp cận chức năng ẩn. ![image](https://hackmd.io/_uploads/HyxoYT5Bjeg.png) ## 2. REPL ![image](https://hackmd.io/_uploads/BJpq-oBilx.png) - REPL = Read → Eval → Print → Loop - Read: Nhận input (lệnh hoặc script bạn gõ). - Eval: Thực thi code đó trong ngữ cảnh của ứng dụng đang chạy. - Print: Xuất kết quả ra màn hình. - Loop: Quay lại bước Read, tiếp tục vòng lặp. ➤ Với Frida, điều này nghĩa là bạn có thể gõ lệnh hook, thay đổi hàm… và thấy kết quả ngay không cần biên dịch lại app. - Runtime tracing of - Classes: Xem hoặc hook vào các class được load. - Methods: Hook vào các phương thức/hàm cụ thể. - Parameters: In ra giá trị tham số được truyền vào hàm. - Return values: Xem hoặc chỉnh sửa giá trị trả về. ## 3. Setup lab ### 3.1. Frida injection ![image](https://hackmd.io/_uploads/B1UWEsSsgg.png) - Frida client (máy PC) - Là thứ bạn tương tác trực tiếp (qua frida, frida-trace, Python API, v.v.). - Gửi script/hook code của bạn sang thiết bị. - Nhận kết quả log/traced data trả về. - Frida server (thiết bị Android, iOS, hoặc máy đích): - Chạy với quyền đủ cao (thường là root trên Android). - Nhận script từ client, inject vào process của app (APK process). - Giao tiếp ngược lại để trả dữ liệu/log cho client. - APK Process (ứng dụng bạn hook): - Frida-server sẽ chèn script của bạn vào bộ nhớ của process này, hook vào class/method/parameter/return value tùy bạn viết. ### 3.2. Frida-server > Để push được frida-server lên emulator thì emulator của bạn phải root được. Với genymotion thì cài android 10 trở xuồng. Còn android studio thì bạn tham khảo 2 video sau để root emulator. > [Root android studio emulator.](https://www.youtube.com/watch?v=pcwRWBHFAlg) > [Push frida server on android studio emulator.](https://www.youtube.com/watch?v=R3ptGaFW1AU&t=513s) - Đầu tiên bạn tải [frida-server](https://github.com/frida/frida/releases) ở đây. ![image](https://hackmd.io/_uploads/SJnzwjSogg.png) - Xem kiến trúc của emulator và chọn bản frida-server thích hợp. ![image](https://hackmd.io/_uploads/HJsHPjHole.png) - Một cách kiểm tra khác. - i686 là một kiến trúc x86. ![image](https://hackmd.io/_uploads/HyjdvsHolx.png) - Tải về và đổi tên. ![image](https://hackmd.io/_uploads/Byj5wiHiee.png) - Push lên thư mục `/data/local/tmp`. ![image](https://hackmd.io/_uploads/B1NaDsrslg.png) - Cấp quyền cho nó và chạy. ![image](https://hackmd.io/_uploads/rJ1Zusrolg.png) ### 3.3. Objection ![image](https://hackmd.io/_uploads/S1iAdiBigl.png) - Objection là một tool hỗ trợ pentest mobile (Android/iOS), build dựa trên Frida. - Đầu tiên máy phải có python trước đã. - Xem doc [objection](https://github.com/sensepost/objection/wiki/Installation#prerequisites) tại đây. - Tải objection. ![image](https://hackmd.io/_uploads/S1EdYiHsgx.png) ![image](https://hackmd.io/_uploads/rJ_OKjroll.png) #### Cách tải app cho điện thoại chưa root - Patch APK (dành cho máy không root) `objection patchapk --source hello-app.apk -a <architecture>` - Nếu gặp lỗi: `objection patchapk --source hello-app.apk -a architecture --use-aapt` > ref: https://github.com/sensepost/objection/issues/253 https://github.com/iBotPeaches/Apktool/issues/1978 3.4. Frida-client - Tải frida-client: `pip install frida-tools` . ![image](https://hackmd.io/_uploads/SJSXnjBjxx.png) ![image](https://hackmd.io/_uploads/ryKThsSogl.png) ![image](https://hackmd.io/_uploads/r1TansBsxg.png) - Xem các tiến trình đang chạy trên điện thoại. - Hook vào app `frida -U -n "App Name"`. ![image](https://hackmd.io/_uploads/Bylt2irole.png) ## 4. Cách sử dụng frida - Kiểm tra [frida](https://frida.re/docs/javascript-api/#java) đã chạy hay chưa. ![image](https://hackmd.io/_uploads/rJBnRoSjxe.png) - Khi tắt emulator bật lại thì nhớ vào `shell` bật `su` và chạy lại lệnh `./frida-server &`. - Có nhiều cách hook vào app như gắn vào PID hoặc package name. ![image](https://hackmd.io/_uploads/Hy1wShHoge.png) ![image](https://hackmd.io/_uploads/HJHPShHjxx.png) ![image](https://hackmd.io/_uploads/BJwuB2rile.png) - Chạy một số lệnh cơ bản. Các bạn mở app ra mà bị trắng thì gõ `%resume`. ## 5. Hello world ![image](https://hackmd.io/_uploads/Skx_arhriex.png) ![image](https://hackmd.io/_uploads/rJG0BnHjxx.png) ![image](https://hackmd.io/_uploads/r1w0rnHige.png) ![image](https://hackmd.io/_uploads/SJiRShHsgx.png) - `Ctrl + C` rồi `exit` để thoát nhá. ## 6. List classes ![image](https://hackmd.io/_uploads/H1IjPnroeg.png) ![image](https://hackmd.io/_uploads/Bk2oD2roeg.png) ![image](https://hackmd.io/_uploads/rJn2Dnrixl.png) ![image](https://hackmd.io/_uploads/B1zaP2Ssel.png) - Liệt kê các class giúp biết app có những class nào — từ đó chọn class/namespace khả dĩ chứa logic quan trọng (auth, crypto, network, checks). ![image](https://hackmd.io/_uploads/ryEmdhHole.png) ![image](https://hackmd.io/_uploads/SkhmdnSjll.png) ## 7. List method and properties - List method / property trước khi hook: - Hiểu API của class: biết class có những phương thức/thuộc tính nào, tên, số tham số, kiểu trả về → chọn đúng mục tiêu để hook. - Xác định overloads / signatures: nhiều method cùng tên nhưng khác tham số; cần biết chính xác signature để hook đúng (tránh crash). - Tìm chỗ chứa secret / state: nhiều bí mật (token, key, flag) nằm trong fields (properties) hoặc trả về từ method — liệt kê giúp phát hiện. ![image](https://hackmd.io/_uploads/rkuP_nSiee.png) ![image](https://hackmd.io/_uploads/Sk6vO2rjll.png) ![image](https://hackmd.io/_uploads/BJvs5nBoex.png) ![image](https://hackmd.io/_uploads/ryischBoee.png) ## 8. Hooking function and bypass root detection - Tải [app](https://github.com/OWASP/owasp-mstg/blob/master/Crackmes/Android/Level_01/UnCrackable-Level1.apk) đây nhá. `adb install UnCrackable-Level1.apk` ![image](https://hackmd.io/_uploads/ryar2hBseg.png) ![image](https://hackmd.io/_uploads/ryFRn2rieg.png) - Chỗ này trong hàm `MainActivity` của app kiểm tra xem điện thoại có bị root ko. ![image](https://hackmd.io/_uploads/rkeJgp2rixe.png) - Trong hàm `c()`, vẫn là cách kiểm tra đường dẫn quen thuộc và kiểm tra sự tồn tại của `su` để xác định xem thiết bị có bị root hay ko. ![image](https://hackmd.io/_uploads/r1gmphBogl.png) - Ta sẽ hook vào 3 hàm `c.a()` , `c.b()` và `c.c()`. ![image](https://hackmd.io/_uploads/ryDda2rolx.png) ![image](https://hackmd.io/_uploads/ByDXa3Sjgx.png) ![image](https://hackmd.io/_uploads/HyA2ahHslg.png) ![image](https://hackmd.io/_uploads/ByL6a3Bill.png) ## 9. Dumping function parameters ![image](https://hackmd.io/_uploads/BJ9xC3Bige.png) ![image](https://hackmd.io/_uploads/SkhbRhBjge.png) - Hàm này check xem input nhập vào có đúng ko và in ra dialog tương ứng. - Hàm `a.a(string)` kiểm tra mật khẩu. ![image](https://hackmd.io/_uploads/SJQUChBiee.png) - `a(str)` kiểm tra xem `str` có phải là chuỗi bí mật (secret) sau khi giải mã Base64 + decrypt bằng key từ chuỗi hex hay không. Đây thường là check để xác thực license, flag, mật khẩu cứng trong app. ![image](https://hackmd.io/_uploads/SJH3ypBoxx.png) ![image](https://hackmd.io/_uploads/H1_nJaSjgl.png) - Nhớ đừng tắt cái tab chạy hook bypass lần trước nhá. - Hook hàm để ép hàm `sg.vantagepoint.uncrackable.a` luôn trả về `true`. - Tham khảo thêm [write-up](https://1337.dcodx.com/mobile-security/owasp-mstg-crackme-1-writeup-android). ## 10. Re-using app functions and decrypt password ![image](https://hackmd.io/_uploads/B1sSxTrjle.png) - Nếu không hook để ép hàm trả về true như trên thì nó sẽ trả thông báo như này khi nhập kết quả sai. Vậy thì gét go tìm mật khẩu thôi. ![image](https://hackmd.io/_uploads/ryePxpBjlg.png) - Hàm `a.a(string)` kiểm tra mật khẩu. ![image](https://hackmd.io/_uploads/S1IugTSjeg.png) ![image](https://hackmd.io/_uploads/BJtdgpBsxe.png) - Đến đây nếu phân tích tĩnh thì có thể reverse lại code được rồi. Nhưng ta đang dùng frida để hook hàm và phân tích động. ![image](https://hackmd.io/_uploads/BkTKxTBieg.png) ![image](https://hackmd.io/_uploads/H1-9gprigx.png) ![image](https://hackmd.io/_uploads/SkSibTSoxe.png) - `Java.perform(...)` — đảm bảo code chạy khi JVM sẵn sàng. - `base64.decode(..., 0)` — decode chuỗi Base64 thành `byte[]`. Tham số 0 là flag (DEFAULT). - `bfunctionclass.b("...")` — gọi method `b(String)` trong class đã thấy trước đó, chuyển hex string thành `byte[]` (được dùng làm key/iv). - `afunctionclass.a(enckey, arrayOfBytes)` — gọi method giải mã (tên class/method thay theo APK). Kết quả là `byte[]` plaintext. - `new java.lang.String(byte[])` — chuyển mảng byte thành chuỗi đọc được, in ra console. ## Frida for windows >Trên Windows, Frida giúp bạn hook API hệ thống (Win32), hàm trong DLL, và theo dõi luồng dữ liệu (file, network, crypto...) trong các ứng dụng native/desktop. --- ### 1. Listing windows modules (DLL libraries) - [Lab](https://github.com/cspinstructor/github-crackmes/blob/master/CrackMe1.zip) cho module này. - Password: `crackinglessons.com` ![image](https://hackmd.io/_uploads/B1feOTSslg.png) ![image](https://hackmd.io/_uploads/rk9eOpBsll.png) ### 2. Hook Message box function - [MessageBoxA](https://learn.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox) / `MessageBoxW` là hàm `Win32` trong `user32.dll` dùng để hiển thị hộp thoại thông báo đơn giản. ![image](https://hackmd.io/_uploads/Bk0fYaSile.png) ![image](https://hackmd.io/_uploads/SyfXKTBogx.png) ![image](https://hackmd.io/_uploads/SkqQYpHsxl.png) - `Module.findExportByName("user32.dll", "MessageBoxA")` tìm địa chỉ (pointer) của hàm export `MessageBoxA` trong `user32.dll`. Nếu hàm tồn tại, trả về một `NativePointer`; nếu không tìm thấy sẽ trả `null`. - `onEnter: function(args){ ... }`: `args` là mảng các tham số truyền cho hàm native (kiểu NativePointer). Với `MessageBoxA` signature là (`HWND hWnd`, `LPCSTR lpText`, `LPCSTR lpCaption`, `UINT uType`). - `onLeave: function(retval){ ... }` chạy khi `MessageBoxA` kết thúc. `retval` là `NativePointer` giữ giá trị trả về (ID button được nhấn). Ở đây chỉ in log thông báo đã thoát hộp thoại. Bạn có thể thay giá trị trả về bằng `retval.replace(ptr(<value>))` nếu muốn ép kết quả. ### 3. Modifying the windows MessageBox API - [msdn messagebox ](https://docs.microsoft.com/en-us/windows/win32/api/winuser/nf-winuser-messagebox) - [frida native pointers ](https://frida.re/docs/javascript-api/#nativepointer) - [frida best practices for windows strings](https://frida.re/docs/best-practices/) ![image](https://hackmd.io/_uploads/Syaa_jUjll.png) ![image](https://hackmd.io/_uploads/ByxRdi8jgx.png) ![image](https://hackmd.io/_uploads/S1gJto8jgx.png) ![image](https://hackmd.io/_uploads/rkBkYoLigl.png) - Đoạn hook này log nội dung message box gốc, thay nội dung + tiêu đề thành `well done` / `congrats`, và thay đổi kiểu hộp thoại bằng `uType`. ### 4. Listing process function - [enumerate imports(list functions)](https://blog.karthisoftek.com/a?ID=01750-671ab62c-c687-45c9-894c-8bdf7c6fe5e1) - [msdn createfile](https://docs.microsoft.com/en-us/windows/win32/api/fileapi/nf-fileapi-createfilea) - [file access rights constants](https://docs.microsoft.com/en-us/windows/win32/fileio/file-access-rights-constants) - [Frida docs for javascript api](https://frida.re/docs/javascript-api/) ![image](https://hackmd.io/_uploads/B14Wjj8ixl.png) ![image](https://hackmd.io/_uploads/HyvWoo8ilx.png) ![image](https://hackmd.io/_uploads/B1hbisUieg.png) ### 5. Hooking file reading ![image](https://hackmd.io/_uploads/r1p93ZPjgx.png) ![image](https://hackmd.io/_uploads/By5nnbDslx.png) - Tạo file `keyfile.txt` trong cùng thư mục với CrackMe2.exe và chạy lại. ![image](https://hackmd.io/_uploads/rk3CnZwjge.png) ![image](https://hackmd.io/_uploads/BJ7kpWDseg.png) ### 6. Memory scanning - [Memory scanning](https://frida.re/docs/javascript-api/#memory) ![image](https://hackmd.io/_uploads/By576-Doxg.png) ![image](https://hackmd.io/_uploads/BJBN6bvsel.png) - `"52 65 67 69 73 74 65 72 65 64 20 74 6F"` tương ứng với `Registered to` trong ascii. - `Memory.scan(base, size, pattern, callbacks)` quét bộ nhớ từ `base` với `size` để tìm pattern. - `onMatch(address, size)` gọi khi tìm thấy 1 match: - `console.log(address);` in địa chỉ (NativePointer). - `address.readUtf8String()` đọc chuỗi bắt đầu từ address đến dấu NULL (UTF-8) — dùng để in nội dung hiện tại (nếu vùng chứa C-string). - `address.writeUtf8String("Registed to: PinkArmor");` ghi đè chuỗi mới vào bộ nhớ bắt đầu tại address. - In lại `address.readUtf8String()` để show thay đổi. ## Hextree > Mình có giải challange frida trên [hextree](https://app.hextree.io/courses/android-dynamic-instrumentation/intro) các bạn có thể tham khảo. --- ### 1. The Frida REPL ![image](https://hackmd.io/_uploads/HyUkEMwsxl.png) - Cái này lý thuyết nó tựa như bên trên. ### 2. Javascript wrapper Java by Java.use() - Khi hook Android app, phần lớn code viết bằng `Java/Kotlin` và chạy trong `ART/Dalvik VM`. - Frida script bản chất là JavaScript, không thể gọi thẳng Java class được. ➤ Frida cung cấp API `Java.use()` để wrap (đóng gói) một Java class thành object JS, cho phép gọi/override method dễ dàng. - Cơ chế hoạt động của `Java.use("...")`: - Tìm class trong ART runtime. - Trả về một JavaScript wrapper object. - Wrapper này có: - Thuộc tính tương ứng với field trong class. - Hàm tương ứng với method của class. - implementation → cho phép bạn ghi đè (override) method. ➤ Tóm gọn: `Java.use("className")` = cách để Frida biến Java class thành object JS, cho phép gọi method, đọc field và hook/override implementation dễ dàng. ![image](https://hackmd.io/_uploads/BJma4zDsgx.png) ![image](https://hackmd.io/_uploads/rJRpNfDogg.png) ![image](https://hackmd.io/_uploads/HJ7C4fvoel.png) - Khi enter lại lỗi lý do là frida repl thường ko chạy trực tiếp trên luồng chính ứng dụng. - Vì sao: - `Java.use("")` cần `ART/Dalvik` runtime của Android đã khởi tạo đầy đủ (classloader, method table, v.v.). - Khi bạn chạy code từ Frida REPL hoặc từ script inject vào quá sớm (ngay sau khi process spawn) → ART chưa sẵn sàng → không resolve được class → lỗi ``"Java is not defined"`` hoặc ``"Class not found"``. - Vậy `Java.perform` làm gì? - Nó đợi đến khi `VM (ART/Dalvik)` đã lên đầy đủ, sau đó mới chạy callback của bạn. - Bản chất: Frida inject script không chạy trong main thread của app mà trong một thread riêng (JS runtime của Frida). ➤ Nếu bạn gọi `Java.use` bên ngoài, bạn đang gọi trước khi Frida attach được vào VM. ![image](https://hackmd.io/_uploads/H1zUHGDixx.png) ![image](https://hackmd.io/_uploads/HkSLBMvsex.png) ![image](https://hackmd.io/_uploads/Bk9ISMPiex.png) ![image](https://hackmd.io/_uploads/Hy4DSMvieg.png) ![image](https://hackmd.io/_uploads/SkOPrzwslg.png) ![image](https://hackmd.io/_uploads/BywdrMPjgg.png) ### 3. Trace activities ![image](https://hackmd.io/_uploads/HJb6HMDjle.png) ![image](https://hackmd.io/_uploads/HJNaBGDogx.png) - Trace Fragment ![image](https://hackmd.io/_uploads/BJnCrzDoel.png) ![image](https://hackmd.io/_uploads/BkJJLMDiel.png) - Khi trace bằng frida những hàm chuẩn Android framework thì không cần xem source của app. Vì: - Chúng chuẩn theo Android API. - Hầu hết app phải dùng (UI, network, crypto, file…). - Hook trúng sẽ luôn ra log giúp bạn map lại flow của app. ### 4. frida-trace - Là tool đi kèm với Frida, giúp bạn tự động generate script hook và trace function dễ dàng. - Thay vì phải tự viết code Frida bằng tay (Java.use, Interceptor.attach...), bạn chỉ cần chạy một lệnh → Frida tự tạo sẵn boilerplate JS để bạn sửa/hook thêm. - Nó giống như auto-skeleton cho việc hook. ![image](https://hackmd.io/_uploads/rkpELzwsxe.png) - Dấu `!` để nói ``"hook tất cả overload"``. ![image](https://hackmd.io/_uploads/rkPLUGvixe.png) ![image](https://hackmd.io/_uploads/r1TIUfPsxx.png) ### 5. Frida Interception Basics - Interceptor là API core của Frida cho phép bạn hook vào hàm native (C/C++/JNI). Nó hoạt động bằng cách patch mã máy tại địa chỉ hàm (export hoặc offset trong module). - Khi process gọi tới hàm đó, Frida sẽ chuyển luồng thực thi sang script của bạn trước, cho bạn cơ hội: - `onEnter`: xem / sửa tham số input. - `onLeave`: xem / sửa giá trị trả về. - Có giống Burp Suite không? - Giống ở ý tưởng: đều là "man-in-the-middle" - Burp Suite chặn request HTTP(S) từ app ↔ server → bạn xem/sửa rồi mới cho đi. - Frida Interceptor chặn hàm native/Java trong chính app ↔ hệ điều hành ↔ library. - Khác nhau về tầng (layer): - Burp: chặn ở tầng network (HTTP/HTTPS). - Frida Interceptor: chặn ở tầng process / system call / library function. ![image](https://hackmd.io/_uploads/ByoR8fPsle.png) ![image](https://hackmd.io/_uploads/r1aRLfDoxg.png) ![image](https://hackmd.io/_uploads/r1eJDGDjgx.png) ```js Java.perform(() => { // Lấy reference tới class InterceptionFragment var InterceptionFragment = Java.use("io.hextree.fridatarget.ui.InterceptionFragment"); // Ghi đè implementation của method function_to_intercept InterceptionFragment.function_to_intercept.implementation = function(argument){ // Gọi lại hàm gốc với cùng argument (để giữ hành vi ban đầu nếu cần) this.function_to_intercept(argument); // Trả về giá trị mới, override kết quả gốc return "Something different"; } }) ``` ![image](https://hackmd.io/_uploads/HJWD_fvsee.png) - `Bypass License 1` ![image](https://hackmd.io/_uploads/S1vY_Mwjel.png) ![image](https://hackmd.io/_uploads/Bk5F_fDiex.png) ![image](https://hackmd.io/_uploads/SyZ5_zPixl.png) ![image](https://hackmd.io/_uploads/rJ49uMvoex.png) ![image](https://hackmd.io/_uploads/Hkd9_Gwoxe.png) - `Bypass license 2` ![image](https://hackmd.io/_uploads/rkFsuMwolg.png) ![image](https://hackmd.io/_uploads/SJ6s_GPixx.png) ![image](https://hackmd.io/_uploads/rkM3OGvjxe.png) - Bypass theo logic check ![image](https://hackmd.io/_uploads/HJ5aOGPieg.png) ![image](https://hackmd.io/_uploads/ryRTufDjgx.png) - Hook dialog theo ý mình ![image](https://hackmd.io/_uploads/HkgkYGDjgg.png) ![image](https://hackmd.io/_uploads/Sk7JFGDoxl.png) - `Dice game` ![image](https://hackmd.io/_uploads/SyGZtMvsxl.png) - Game này bạn xoay 6 con xúc xắc ra số 6 thì bạn win. ![image](https://hackmd.io/_uploads/HkXXYfDilx.png) ![image](https://hackmd.io/_uploads/SJ5mYfwiex.png) ![image](https://hackmd.io/_uploads/By14YMPoee.png) ![image](https://hackmd.io/_uploads/SJ7NFMvoll.png) ### 6. SSL Validation Bypasses - Ae có thể xem cộng động [share code frida](https://codeshare.frida.re/) ở đây nhé. - SSLContext & Network-Security-Config Bypass ![image](https://hackmd.io/_uploads/BJ_AtMwsel.png) - `X509TrustManager` có 3 phương thức chính: - `void checkClientTrusted(X509Certificate[] chain, String authType)` : Được gọi khi server yêu cầu client authentication (client cert). - `void checkServerTrusted(X509Certificate[] chain, String authType)` : Được gọi khi kết nối tới server. Kiểm tra chuỗi certificate do server gửi. Nếu `chain` không hợp lệ thì phải ném `CertificateException;` nếu hợp lệ thì không ném (return bình thường). - `X509Certificate[] getAcceptedIssuers()` : Trả về danh sách `CA certificates` mà `TrustManager` này chấp nhận (dùng cho client-cert selection). Thường trả `new X509Certificate[0]` nếu không cần cung cấp. - Ghi chú quan trọng: - `checkServerTrusted` là nút then chốt để quyết định liệu TLS connection tới server có được chấp nhận hay không. - Kiểm tra chain (signature, validity period). - Kiểm tra revocation (CRL/OCSP) nếu được cấu hình. - (Có thể) so sánh public key / fingerprint (pinning). - `checkClientTrusted` ít dùng hơn — chỉ thực sự cần khi server yêu cầu client certificate. - `getAcceptedIssuers` cung cấp meta info; hiếm khi app mobile dùng trực tiếp. - Ứng dụng cần bypass SSL pinning, ban đầu không thể thực thi các chức năng cho có SSL pinning. ![image](https://hackmd.io/_uploads/HyNYRSOjll.png) ![image](https://hackmd.io/_uploads/rkAj0rOole.png) ![image](https://hackmd.io/_uploads/r1C2CSOsge.png) ![image](https://hackmd.io/_uploads/rJHpCr_jeg.png) ![image](https://hackmd.io/_uploads/B1ppRHdoxx.png) ![image](https://hackmd.io/_uploads/r1ex1Idiee.png) ![image](https://hackmd.io/_uploads/r1DbyLOoxx.png) ![image](https://hackmd.io/_uploads/Skxzy8uixl.png) ```js Java.perform(() => { var PlatformClass = Java.use("com.android.org.conscrypt.Platform"); PlatformClass.checkServerTrusted .overload( 'javax.net.ssl.X509TrustManager', '[Ljava.security.cert.X509Certificate;', 'java.lang.String', 'com.android.org.conscrypt.AbstractConscryptSocket' ) .implementation = function (trustManager, certs, authType, socket) { console.log("Check server trusted"); }; }); ``` ![image](https://hackmd.io/_uploads/ryv31UOixg.png) - `OKHTTP3 bypass` ![image](https://hackmd.io/_uploads/S1tlgUOjex.png) - OkHttp3 là một HTTP client library cho Java và Android. Nó được dùng rất nhiều trong Android app để: - Gửi HTTP/HTTPS requests (GET, POST, PUT, DELETE...). - Quản lý kết nối mạng hiệu quả, tái sử dụng connection (connection pooling). - Hỗ trợ HTTP/2, WebSocket, SPDY. - Tự động xử lý redirects, retries. - Tích hợp sẵn caching, cookie handling. - Hỗ trợ certificate pinning → nhiều app Android dùng để chống MITM. ➤ Nói đơn giản: Nếu app Android có kết nối tới API (server), khả năng cao nó dùng OkHttp3 để gửi/nhận dữ liệu. ![image](https://hackmd.io/_uploads/B12ixU_slg.png) ![image](https://hackmd.io/_uploads/rkUhgIdjel.png) ![image](https://hackmd.io/_uploads/Bkt2xI_jll.png) ![image](https://hackmd.io/_uploads/Hkp2eI_jlg.png) - `2048` ![image](https://hackmd.io/_uploads/HyTVZLdsll.png) ![image](https://hackmd.io/_uploads/HJxS-Udsxl.png) ![image](https://hackmd.io/_uploads/ryNrZIdjee.png) ![image](https://hackmd.io/_uploads/SJurb8_jxx.png) ![image](https://hackmd.io/_uploads/SJqrZ8_jex.png) ![image](https://hackmd.io/_uploads/H1yIZIOsgg.png) ![image](https://hackmd.io/_uploads/H1zIZUOixg.png) ![image](https://hackmd.io/_uploads/B1DLbUuoxe.png) ![image](https://hackmd.io/_uploads/Bk2Lb8_oee.png) --- <p align="center"><strong>🎯 Hack Smart, Hack Safe 🎯</strong></p>

    Import from clipboard

    Paste your markdown or webpage here...

    Advanced permission required

    Your current role can only read. Ask the system administrator to acquire write and comment permission.

    This team is disabled

    Sorry, this team is disabled. You can't edit this note.

    This note is locked

    Sorry, only owner can edit this note.

    Reach the limit

    Sorry, you've reached the max length this note can be.
    Please reduce the content or divide it to more notes, thank you!

    Import from Gist

    Import from Snippet

    or

    Export to Snippet

    Are you sure?

    Do you really want to delete this note?
    All users will lose their connection.

    Create a note from template

    Create a note from template

    Oops...
    This template has been removed or transferred.
    Upgrade
    All
    • All
    • Team
    No template.

    Create a template

    Upgrade

    Delete template

    Do you really want to delete this template?
    Turn this template into a regular note and keep its content, versions, and comments.

    This page need refresh

    You have an incompatible client version.
    Refresh to update.
    New version available!
    See releases notes here
    Refresh to enjoy new features.
    Your user state has changed.
    Refresh to load new user state.

    Sign in

    Forgot password
    or
    Sign in via Facebook Sign in via X(Twitter) Sign in via GitHub Sign in via Dropbox Sign in with Wallet
    Wallet ( )
    Connect another wallet

    New to HackMD? Sign up

    By signing in, you agree to our terms of service.

    Help

    • English
    • 中文
    • Français
    • Deutsch
    • 日本語
    • Español
    • Català
    • Ελληνικά
    • Português
    • italiano
    • Türkçe
    • Русский
    • Nederlands
    • hrvatski jezik
    • język polski
    • Українська
    • हिन्दी
    • svenska
    • Esperanto
    • dansk

    Documents

    Help & Tutorial

    How to use Book mode

    Slide Example

    API Docs

    Edit in VSCode

    Install browser extension

    Contacts

    Feedback

    Discord

    Send us email

    Resources

    Releases

    Pricing

    Blog

    Policy

    Terms

    Privacy

    Cheatsheet

    Syntax Example Reference
    # Header Header 基本排版
    - Unordered List
    • Unordered List
    1. Ordered List
    1. Ordered List
    - [ ] Todo List
    • Todo List
    > Blockquote
    Blockquote
    **Bold font** Bold font
    *Italics font* Italics font
    ~~Strikethrough~~ Strikethrough
    19^th^ 19th
    H~2~O H2O
    ++Inserted text++ Inserted text
    ==Marked text== Marked text
    [link text](https:// "title") Link
    ![image alt](https:// "title") Image
    `Code` Code 在筆記中貼入程式碼
    ```javascript
    var i = 0;
    ```
    var i = 0;
    :smile: :smile: Emoji list
    {%youtube youtube_id %} Externals
    $L^aT_eX$ LaTeX
    :::info
    This is a alert area.
    :::

    This is a alert area.

    Versions and GitHub Sync
    Get Full History Access

    • Edit version name
    • Delete

    revision author avatar     named on  

    More Less

    Note content is identical to the latest version.
    Compare
      Choose a version
      No search result
      Version not found
    Sign in to link this note to GitHub
    Learn more
    This note is not linked with GitHub
     

    Feedback

    Submission failed, please try again

    Thanks for your support.

    On a scale of 0-10, how likely is it that you would recommend HackMD to your friends, family or business associates?

    Please give us some advice and help us improve HackMD.

     

    Thanks for your feedback

    Remove version name

    Do you want to remove this version name and description?

    Transfer ownership

    Transfer to
      Warning: is a public team. If you transfer note to this team, everyone on the web can find and read this note.

        Link with GitHub

        Please authorize HackMD on GitHub
        • Please sign in to GitHub and install the HackMD app on your GitHub repo.
        • HackMD links with GitHub through a GitHub App. You can choose which repo to install our App.
        Learn more  Sign in to GitHub

        Push the note to GitHub Push to GitHub Pull a file from GitHub

          Authorize again
         

        Choose which file to push to

        Select repo
        Refresh Authorize more repos
        Select branch
        Select file
        Select branch
        Choose version(s) to push
        • Save a new version and push
        • Choose from existing versions
        Include title and tags
        Available push count

        Pull from GitHub

         
        File from GitHub
        File from HackMD

        GitHub Link Settings

        File linked

        Linked by
        File path
        Last synced branch
        Available push count

        Danger Zone

        Unlink
        You will no longer receive notification when GitHub file changes after unlink.

        Syncing

        Push failed

        Push successfully