Ios application hooking frida

From ShulkwiSEC/bb-huge · View interactive version

Ios application hooking frida is an AI agent skill from the GitHub repository ShulkwiSEC/bb-huge. Execute dynamic instrumentation utilizing Frida to inject custom JavaScript into running iOS applications (IPAs) on jailbroken devices. Hook native functions, bypass SSL Pinning, bypass Jailbreak Detection, and manipulate in-memory data at runtime.

How to use this skill

Skill file

iOS Application Hooking (Frida)

When to Use

Prerequisites

Workflow

Phase 1: Environment Setup (Jailbroken iOS)

# Concept: Frida operates via a client-server architecture. The Frida "Server" must be running 
# as root on the target device, listening for commands from the attacker's "Client" (your PC).

# 1. On the Jailbroken iOS Device:
# Open Cydia/Sileo -> Add Source: `https://build.frida.re` -> Install "Frida!"

# 2. On the Attacker PC:
pip3 install frida-tools objection

# 3. Verify Connectivity via USB:
frida-ps -U
# Output: Lists all processes currently executing on the iPhone. Look for the target application (e.g., `TargetBankApp`).

Phase 2: Injecting Custom JavaScript Hooks (The Core Mechanics)

// Concept: We write JavaScript on our PC. Frida injects the Google V8 Engine into the 
// iPhone's target application process, allowing our JS to seamlessly interact directly 
// with the underlying Objective-C / Swift architecture.

// Scenario: The app calls `-(BOOL)isJailbroken;` which returns TRUE, crashing the app.
// We intercept that call right before it finishes and permanently overwrite the return value back to FALSE.

if (ObjC.available) {
    // 1. Find the Class in the application memory
    var JailbreakDetectionClass = ObjC.classes.JailbreakDetector;
    
    // 2. Attach an Interceptor (Hook) to the specific method
    Interceptor.attach(JailbreakDetectionClass['- isJailbroken'].implementation, {
        
        onEnter: function(args) {
            console.log("[+] Intercepted isJailbroken execution!");
        },
        
        onLeave: function(retval) {
            console.log("[-] Original Return Value: " + retval);
            // 3. The Override: Change the boolean `TRUE` (1) to `FALSE` (0)
            var newRetval = ptr("0x0"); 
            retval.replace(newRetval);
            console.log("[+] Spofed Return Value: " + newRetval);
        }
    });
}

Phase 3: Launching the Frida Script

# Concept: You generally want to spawn the app via Frida so your hooks are loaded BEFORE 
# the jailbreak detection code executes upon startup.

# 1. Spawn the application (`-f`) on USB (`-U`), avoiding automatic resume (`--no-pause`), 
# and load your javascript payload (`-l`).
frida -U -f com.bank.targetapp -l jailbreak_bypass.js

# Output logs:
# [+] Intercepted isJailbroken execution!
# [-] Original Return Value: 0x1
# [+] Spoofed Return Value: 0x0

# The app launches successfully despite being on a fully jailbroken device!

Phase 4: Automated Evasion via Objection

# Concept: Writing custom JavaScript for every app takes hours. We highly utilize Objection, 
# a runtime mobile exploration toolkit powered natively by Frida, containing hundreds of 
# pre-built, massive hooking scripts.

# 1. Launch the target app attached to Objection
objection -g com.bank.targetapp explore

# 2. Execute automated universal SSL Pinning Bypass
# Instantly hooks and overrides all standard iOS networking libraries (NSURLSession, AFNetworking, TrustKit).
[usb] # ios sslpinning disable

# 3. Execute automated universal Jailbreak Detection Bypass
# Instantly hooks thousands of common JB detection files (e.g., checking for `/Applications/Cydia.app`, `fork()`).
[usb] # ios jailbreak disable

# 4. Extract Keychains and Secrets securely stored in memory
[usb] # ios keychain dump
Decision Point 🔀
flowchart TD
    A[Install App on Jailbroken iPhone] --> B[Launch App]
    B --> C{Does app crash immediately?}
    C -->|Yes (JB Detection)| D[Launch via `objection` & execute `ios jailbreak disable`]
    C -->|No| E[Configure iOS Proxy to Burp Suite]
    D --> E
    E --> F{Is traffic visible in Burp?}
    F -->|No (SSL Pinning)| G[Execute Objection `ios sslpinning disable` or custom Frida Script]
    F -->|Yes| H[Perform standard API penetration testing]
    G -->|Still Blocked?| I[Use `frida-trace` to identify custom native encryption functions in `libNet.dylib` and write bespoke JS to extract plaintext before encryption]

🔵 Blue Team Detection & Defense

Key Concepts

| Concept | Description |

|---------|-------------|

| Dynamic Instrumentation | The process of modifying or monitoring the execution of a compiled software application at runtime without requiring the original source code |

| Frida | The industry-standard dynamic instrumentation toolkit allowing researchers to inject snippets of JavaScript directly into native applications (Windows, Linux, iOS, Android) |

| Hooking | The interception of function calls, messages, or events between software components. In iOS, replacing the implementation pointer (IMP) of an Objective-C method |

| Objection | A mobile exploration toolkit encapsulating complex Frida scripts into a simple, rapid-deployment interactive terminal (REPL) |

Output Format

Mobile Pentest Exploit Capability: Custom SSL Pinning Bypass (Frida)
===================================================================
Target: `com.healthcare.portal` (Version 4.0.1)
Platform: iOS 16.5 
Tool: Frida v16.1

Description:
The target application implemented a heavily customized SSL Pinning architecture utilizing native C libraries, impervious to universal bypass tools like Objection or SSLKillSwitch2.

To restore API traffic visibility for vulnerability scanning, dynamic instrumentation was deployed via Frida. By utilizing `frida-trace` scanning the application's binary imports, the proprietary certificate validation function `SecTrustEvaluateWithError` was identified.

A bespoke JavaScript hook was authored to intercept this core iOS cryptography function specifically when invoked by the target application's thread. The script overrides the native validation mechanism, forcibly returning a `kSecTrustResultProceed` (Success) flag regardless of the presenting SSL certificate's validity.

Interceptor.attach(Module.findExportByName('Security', 'SecTrustEvaluateWithError'), {

onLeave: function(retval) {

// Override the return value to indicate the Trust is valid (0x1)

retval.replace(0x1);

console.log("[-] Successfully bypassed custom Trust Evaluation");

}

});


Impact:
The application fundamentally accepted the Burp Suite PortSwigger localized Certificate Authority. All application telemetry, including sensitive Personal Health Information (PHI) and authentication tokens, was successfully captured in plaintext over the encrypted SSL tunnel.

📚 Shared Resources

For cross-cutting methodology applicable to all vulnerability classes, see:

- CODE0 — Exploit chaining methodology and high-payout chain patterns

- CODE0 — HackerOne-optimized report writing, CWE quick reference

- CODE0 — Verified disclosed bounties by vulnerability class

References

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.