Skip to content

hypnguyen1209/offensive-claude / skills/mobile-pentest

mobile-pentest

Unverified

Use when pentesting an Android/iOS app — Frida 17 instrumentation, SSL-pinning & root/jailbreak bypass, Android 14/15 CA injection, exported-component/content-provider abuse, deep-link/WebView chains, biometric bypass, Flutter/React-Native RE

scripts/hermes_triage.py

View on GitHub
#!/usr/bin/env python3
"""
hermes_triage.py — Identify the cross-platform framework of an APK and emit the right next-step
commands for interception/RE: React Native (Hermes vs plain JS), Flutter, or native NDK.

For Hermes it reads the HBC version from the bundle header so you pick a compatible tool
(hermes-dec / hbctool / hermes-decomp). For Flutter it locates the split APK / ABI dir holding
libflutter.so so you point reFlutter at the correct file.

USAGE:
    python3 hermes_triage.py base.apk
    python3 hermes_triage.py base.apk split_config.arm64_v8a.apk   # pass multiple split APKs
    python3 hermes_triage.py base.apk --flutter                     # only Flutter detection/guidance
    python3 hermes_triage.py base.apk --extract bundle.hbc          # dump the Hermes bundle to a file

DEPENDENCIES: Python 3 stdlib only (zipfile/struct). Suggests external tools to install.
SCOPE: static triage helper for authorized assessments.
"""
import argparse, struct, sys, zipfile, os

# Hermes bytecode magic (little-endian uint64): 0x1F1903C103BC1FC6
HERMES_MAGIC = 0xC61FBC03C103191F
BUNDLE_NAMES = ("assets/index.android.bundle", "assets/main.jsbundle", "index.android.bundle")


def read_member(apk, names):
    with zipfile.ZipFile(apk) as z:
        members = set(z.namelist())
        for n in names:
            if n in members:
                return z.read(n), n
    return None, None


def hermes_version(data):
    """Return HBC version if data is a Hermes bundle, else None.
    Header layout: u64 magic, u32 version, ... (version is at offset 8)."""
    if len(data) < 12:
        return None
    magic = struct.unpack_from("<Q", data, 0)[0]
    if magic != HERMES_MAGIC:
        return None
    return struct.unpack_from("<I", data, 8)[0]


def list_native_libs(apk):
    libs = {}
    with zipfile.ZipFile(apk) as z:
        for n in z.namelist():
            if n.startswith("lib/") and n.endswith(".so"):
                abi = n.split("/")[1]
                libs.setdefault(abi, []).append(os.path.basename(n))
    return libs


def hermes_tool_for(ver):
    if ver is None:
        return ""
    if ver <= 99:
        return ("hermes-decomp (v40-99, structured) | hermes-dec (broad, jump-labels) | "
                "hbctool (patch/reassemble if version supported)")
    return "hermes-dec (try latest; very new versions may be partial)"


def main():
    ap = argparse.ArgumentParser()
    ap.add_argument("apks", nargs="+", help="base.apk and any split config APKs")
    ap.add_argument("--flutter", action="store_true", help="only show Flutter detection/guidance")
    ap.add_argument("--extract", metavar="OUT", help="write the Hermes bundle to OUT and exit")
    args = ap.parse_args()

    found_flutter = found_hermes = found_native = False

    for apk in args.apks:
        if not os.path.isfile(apk):
            print("[!] missing: " + apk); continue
        print("\n=== %s ===" % apk)
        libs = list_native_libs(apk)

        # Flutter
        flutter_abis = [abi for abi, files in libs.items() if "libflutter.so" in files]
        if flutter_abis:
            found_flutter = True
            print("[FLUTTER] libflutter.so in ABI(s): %s" % ", ".join(flutter_abis))
            print("  next: pip install reflutter && reflutter '%s'  (patch the split holding libflutter.so)" % apk)
            print("        then re-sign: apksigner sign --ks debug.keystore release.RE.apk")
            print("        fallback (anti-proxy): iptables -t nat -A OUTPUT -p tcp --dport 443 -j DNAT --to <PROXY>:8080")
            print("        target verify fn: ssl_crypto_x509_session_verify_cert_chain (BoringSSL in libflutter.so)")

        if args.flutter:
            continue

        # React Native / Hermes
        rn_libs = [f for abi in libs for f in libs[abi] if f in
                   ("libhermes.so", "libjsc.so", "libreactnativejni.so")]
        data, name = read_member(apk, BUNDLE_NAMES)
        if data is not None:
            ver = hermes_version(data)
            if ver is not None:
                found_hermes = True
                print("[REACT-NATIVE/HERMES] %s -> HBC version %d" % (name, ver))
                print("  tools: %s" % hermes_tool_for(ver))
                print("  disasm: hbc-disassembler '%s_extracted' out.hasm" % name)
                print("  dynamic: Frida-hook CatalystInstanceImpl.loadScriptFromFile to inject JS")
                if args.extract:
                    with open(args.extract, "wb") as fh:
                        fh.write(data)
                    print("  [+] bundle written to %s" % args.extract)
                    return
            else:
                print("[REACT-NATIVE] %s is plain/minified JS (not Hermes) -> just beautify & read" % name)
        elif rn_libs:
            print("[REACT-NATIVE] RN libs present (%s) but no bundle found in this APK (check splits)"
                  % ", ".join(sorted(set(rn_libs))))

        # Native NDK
        ndk = sorted({f for abi in libs for f in libs[abi]
                      if f not in ("libflutter.so", "libapp.so", "libhermes.so", "libjsc.so", "libreactnativejni.so")})
        if ndk:
            found_native = True
            print("[NATIVE] .so libraries: %s" % ", ".join(ndk[:12]) + (" ..." if len(ndk) > 12 else ""))
            print("  next: nm -D libX.so | grep -E 'Java_|JNI_OnLoad' ; decompile JNI_OnLoad in Ghidra/IDA")

    print("\n[summary] flutter=%s hermes=%s native=%s" % (found_flutter, found_hermes, found_native))
    if not (found_flutter or found_hermes or found_native):
        print("  no hybrid/native markers -> treat as standard Java/Kotlin app (jadx + universal_unpin.js)")


if __name__ == "__main__":
    main()
rea-analysis-optimizationmorluto/reaOptimize REA providers and shared analysis workflows for agent context, latency, CPU, and memory while preserving correctness and Evidence. Use for analysis bottlenecks and cache or query design; CI/test-suite optimization belongs to rea-ci-tests-audit.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-ci-tests-auditmorluto/reaAudit REA CI and test suites for correctness, fixture drift, false passes, and measured performance; use for suite or workflow investigations and efficiency changes, rather than ordinary feature testing or a single test failure.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
rea-tool-designmorluto/reaAudit, investigate, design, or change REA investigation tools, CLI/MCP contracts, provider capabilities, and Evidence semantics.Stars: 472kUpdated Claude CodeCodexVerifiedInstall
ponytail-auditDietrichGebert/ponytailQuality audit of the whole repo: bugs, security, real load, missing tests, speed, and what to delete. Most important first.Stars: 194kUpdated Claude CodeCodexVerifiedInstall