Writeup · 31 Nights of Root

The Signal Key

mobilemediumsolvedFlag: r00t{REDACTED}

Overview

The Signal Key. Can you spot the signal?

The only artifact is index.android.bundle, the JavaScript bundle of a React Native app. The name of the game: the app contains an “Activate License” screen, and the secret is hidden inside the bundle.

Prerequisites / Setup

  • Python 3 (base64)
  • index.android.bundle in the working directory
  • Node.js (optional — the decoder is already in the bundle)

Recon

Step 1 — Recon

Goal: Confirm the bundle is plain-text JavaScript and locate the interesting module.

file index.android.bundle
# index.android.bundle: JavaScript source, ASCII text, with very long lines (412)

The bundle is plain-text JavaScript, not compiled Hermes bytecode, so it can be read directly with cat. Real React Native bundles are usually minified and huge. This one is small and hand-built: a module loader (__d / __r), a string table, two helper decoders, a cipher routine, and one real module, LicenseScreen (module 2).

Step 2 — Find the interesting code

Goal: Locate onVerifyPress in Module 2.

function onVerifyPress(_inputCode) {
  var _keyStr = __sidx(342);
  var _ctHex  = __sidx(343);
  var _keyBytes = __str2bytes(_keyStr);
  var _ctBytes  = __hex2bytes(_ctHex);
  var _ptBytes  = __cipherDecode(_ctBytes, _keyBytes);
  ...
  return _result;
}

Two observations:

  1. The function never uses _inputCode. Whatever you type, the same value is decrypted and returned, so no brute forcing or guessing is needed.
  2. The key and ciphertext are not literals. They come from __sidx(342) and __sidx(343), so the string table has to be decoded first.

Step 3 — Decode the string table

Goal: Undo the array rotation and the __sidx lookup to recover the key and ciphertext.

__STR_ARR holds 14 base64 strings. Two things happen before a string can be read:

Rotation. A self-invoking function rotates the array:

(function (arr, cnt) {
  var rotator = function (n) {
    while (--n) {
      arr.push(arr.shift());
    }
  };
  rotator(++cnt);
})(__STR_ARR, 11);

With cnt = 11, rotator gets n = 12, and while (--n) runs 11 times. That is a left rotation by 11.

Lookup. __sidx(idx) uses table[idx - 336], base64-decodes the entry, then subtracts 3 from every character code (a Caesar shift of -3).

Decoding all entries after the rotation shows the layout:

idx value
336 Activate License
337 Enter activation code
338-341 UI strings (decoys)
342 dojo-signal-key! (key)
343 3be94dfe...298388 (64 hex chars, ciphertext)
344-349 more UI strings (decoys)

Indices 342 and 343 are the ones onVerifyPress uses. A common mistake is skipping the rotation, which gives garbage.

Exploitation — Step 4: Invert the cipher

Goal: Run __cipherDecode to recover the flag.

__cipherDecode is a custom 4-round routine. Despite the name, it is the decryption routine, so we can just run it. For each round r from 3 down to 0:

  1. Rotate every byte right by (r + 1) % 8 bits.
  2. For each byte i: subtract r*7 + 1 (mod 256), then XOR with key[(i + r) % len(key)].

The ciphertext is the hex string from index 343 converted to bytes, and the key is the ASCII bytes of dojo-signal-key!.

Step 5 — Solve

Goal: Decode and print the flag.

Running the decode gives:

[+] key        : dojo-signal-key!
[+] ciphertext : 3be94dfe52cf7bceef6d1218214a6a6d572fe857c230d0d7c2c48adc11298388
[+] flag       : r00t{REDACTED}

The flag text (“hermes hides in the bundle”) is a nod to Hermes, React Native’s JS engine.

Solver script

The full script is solve.py. It parses the table and rotation count straight from the bundle (or uses the embedded copy), so it works as:

python3 solve.py index.android.bundle

Core of it:

def sidx(table, idx):
    raw = base64.b64decode(table[idx - 336])
    return "".join(chr((b - 3) & 0xFF) for b in raw)

def cipher_decode(data, key):
    out = list(data)
    for r in range(3, -1, -1):
        s = (r + 1) % 8
        out = [((b >> s) | (b << (8 - s))) & 0xFF for b in out]
        for i in range(len(out)):
            out[i] = ((out[i] - (r * 7 + 1)) % 256) ^ key[(i + r) % len(key)]
    return bytes(out)

Flag

r00t{REDACTED}

Lessons / Takeaways

  • Client-side “verification” that ships the key and ciphertext together is not protection. Anything the app can decrypt, so can you.
  • String obfuscation (base64, Caesar shift, array rotation) only slows static reading. Find the lookup function, replay it, and everything falls out.
  • Start from the function that handles the user action (onVerifyPress) and work backwards to the data it consumes. The decoy strings are noise.
  • The decoder was already in the bundle, so no reimplementation was strictly needed. Running the bundle’s own functions in Node would also have worked.

Techniques

References