Writeup · 31 Nights of Root

Domain Expansion

mobilemediumsolvedFlag: r00t{REDACTED}

“The barrier requires exactly 16 characters of Cursed Energy.”

Overview

Domain Expansion is a small Flutter app with one input field and one button. It asks for a 16-character “domain name”, runs it through an Int32x4 hash built from three hardcoded constant vectors, and — only if all four components match — XOR-decrypts a 49-byte table with the input to produce the flag body.

flowchart LR
    A[16-char input] --> B[4 little-endian int32 words]
    B --> H[Int32x4 hash]
    M[MAGIC / C2 / PI vectors] --> H
    H -->|4 checks pass| D[XOR-decrypt 49-byte table with input]
    D --> F[flag body]
    H -->|mismatch| X[DOMAIN OVERRIDE FAILED]
    A -->|length != 16| Y[INSUFFICIENT CURSED ENERGY]

Prerequisites / Setup

  • unzip / apktool — inspect APK contents and the Java shell
  • Blutter — recover Dart classes, functions, object pool, and native stubs
  • Capstone (python3) — manually disassemble the app’s ARM64 code
  • strings, grep — triage libraries, strings, and constant tables
  • python3 — invert the hash and decrypt the table

Recon

Step 1 — Unpack and identify the build type

Goal: List the APK contents and confirm it is a release (AOT) Flutter build.

unzip -l domain_expansion.apk

Relevant entries:

classes.dex
lib/arm64-v8a/libapp.so
lib/arm64-v8a/libflutter.so
lib/armeabi-v7a/libapp.so
lib/armeabi-v7a/libflutter.so
lib/x86_64/libapp.so
lib/x86_64/libflutter.so
assets/flutter_assets/...

The presence of libapp.so and the absence of assets/flutter_assets/kernel_blob.bin means this is a release (AOT) build, not a debug/JIT build. There is no Dart kernel to decompile, so the logic lives in native Dart snapshot code.

The manifest gives package com.example.domain_expansion, one launcher activity, minSdk 24, targetSdk 36. The Java layer contains no challenge logic.

Step 2 — Fingerprint the Dart snapshot

Goal: Determine the Dart version so Blutter parses the object pool correctly.

strings -a lib/arm64-v8a/libapp.so | grep -iE "Dart|snapshot|version"

This is a Dart 3.12.1 snapshot (ace654289f5abc240509fc941453ebc5), which matters because Blutter needs the matching Dart SDK / engine build to parse the object pool.

App-specific strings stand out immediately:

DOMAIN EXPANSION
DOMAIN OVERRIDE FAILED
INSUFFICIENT CURSED ENERGY

Step 3 — Run Blutter

Goal: Recover Dart classes, functions, object pool, and native stubs.

python3 blutter.py domain_expansion.apk out_dir

It emits an object-pool dump (pp.txt) and per-library pseudo-disassembly (asm/). The app’s Dart library is gie, and the challenge class is _wy. The successful and failing callbacks are anonymous closures:

Pool entry Closure Meaning
0x17b460 INSUFFICIENT CURSED ENERGY input length ≠ 16
0x17b398 DOMAIN OVERRIDE FAILED hash mismatch
0x17b3b8 success decrypt and display the flag body

Blutter reports app function sizes as -0x1, so it cannot produce reliable pseudocode for the app code. The pool dump is still extremely useful: it names the Int32x4 constants and lets us map native stubs. The validation function is the caller of the three closures, at 0x17a9f8, and was disassembled manually with Capstone.

Exploitation

Step 4 — The validation function

Goal: Confirm the length check and understand how the input is converted to four little-endian int32 words.

At entry the function checks the string length:

cmp  x4, #0x10            ; input.length == 16 ?
b.eq 0x17aa74

If not:

ldr  x1, [x27, #0x7830]   ; closure -> "INSUFFICIENT CURSED ENERGY"

The 16-character string is then converted into a byte collection and read as four consecutive 32-bit little-endian words:

ldrsw x2, [x16]           ; word 0  at data + offset + 0
ldrsw x5, [x1, x0]        ; word 1  at data + offset + 4
ldrsw x7, [x1, x0]        ; word 2  at data + offset + 8
ldrsw x3, [x1, x0]        ; word 3  at data + offset + 12
mov   v0.s[0], w2
mov   v0.s[1], w5
mov   v0.s[2], w7
mov   v0.s[3], w3

In Dart terms this is effectively:

final bytes = /* input as bytes */;
final words = Int32List.view(bytes.buffer);
final v = Int32x4(words[0], words[1], words[2], words[3]);

Because ARM64 is little-endian, word 0 is input[0] | input[1]<<8 | input[2]<<16 | input[3]<<24.

Step 5 — The Int32x4 hash

Goal: Extract the three constant vectors and the data flow from .rodata / the pool dump.

The pool dump supplies the three constant vectors:

Name Components
MAGIC 0x13371337, 0xdeadbeef, 0xcafebabe, 0x8badf00d
C2 0x11111111, 0x22222222, 0x33333333, 0x44444444
PI 0x31415926, 0x53589793, 0x23846264, 0x33832795

The native stubs used are Int32x4_xor, Int32x4_add, and the four component getters (getX/getY/getZ/getW). The data flow is:

V1 = MAGIC ^ Vinput
V2 = (V1.y, V1.z, V1.w, V1.x)     // getters rotate left by one
V3 = C2 + V2                      // componentwise add
V4 = PI ^ V3                      // componentwise xor

Then four comparisons are made against V4:

Component Expected value
V4[0] 0xF24AB2BD
V4[1] 0x4F9B6D66
V4[2] 0xFE439ECC
V4[3] 0x970A8D2D

Step 6 — The constant-decoding trap (Smi encoding)

Goal: Account for Dart Smi tagging when reading expected constants.

A first inversion attempt failed because two of the four comparisons do not use the raw int32. Dart represents small/boxed integers as tagged Smi values (value << 1), and the compiler folded two of the expected constants into their Smi encodings:

; V4[0] check
mov   x17, #-0x1b6a0001   ; 0xffffffffe495ffff
movk  x17, #0x657a        ; 0xffffffffe495657a
cmp   w0, w17

0xE495657A is 0xF24AB2BD << 1 (low 32 bits), so the real expected component is 0xF24AB2BD, not 0xE495657A. Likewise 0xFC873D98 is the Smi encoding of 0xFE439ECC.

The other two checks explicitly untag the getter result with sbfx before comparing, so their constants are already raw:

; V4[1] check
mov   x17, #0x6d66
movk  x17, #0x4f9b, lsl #16
cmp   x1, x17             ; x1 = getter result >> 1
V4 index Instruction constant Real int32
0 0xE495657A (Smi) 0xF24AB2BD
1 0x4F9B6D66 (raw) 0x4F9B6D66
2 0xFC873D98 (Smi) 0xFE439ECC
3 0x970A8D2D (raw) 0x970A8D2D

Reading MOVN/MOVK shifts correctly (and noticing the << 1) is what makes the inversion work.

Step 7 — Invert the hash

Goal: Compute the 16-character input from V4.

MASK = 0xFFFFFFFF
MAGIC = [0x13371337, 0xDEADBEEF, 0xCAFEBABE, 0x8BADF00D]
C2    = [0x11111111, 0x22222222, 0x33333333, 0x44444444]
PI    = [0x31415926, 0x53589793, 0x23846264, 0x33832795]

V4 = [0xF24AB2BD, 0x4F9B6D66, 0xFE439ECC, 0x970A8D2D]

V3 = [v ^ p for v, p in zip(V4, PI)]              # V4 = PI ^ V3
V2 = [(v - c) & MASK for v, c in zip(V3, C2)]     # V3 = C2 + V2
V1 = [V2[3], V2[0], V2[1], V2[2]]                 # V2 = (V1.y, V1.z, V1.w, V1.x)
Vin = [v ^ m for v, m in zip(V1, MAGIC)]          # V1 = MAGIC ^ Vin

key = b"".join(x.to_bytes(4, "little") for x in Vin)
print(key)
b'CursedWomb_0x99!'

That is the 16-character domain name the app expects.

Step 8 — Decrypt the table

Goal: XOR-decrypt the 49-byte table with the recovered key.

On success the function builds a 49-element list from Smi-encoded literals (each stored as value << 1), then XORs it with the input bytes:

ldur  w8, [x16, #0xf]        ; table[i] as Smi
...
sbfx  x1, x8, #1, #0x1f      ; untag table value
...
ldrb  w0, [x16, #0xf]        ; input[i % 16]
eor   x8, x1, x0             ; decoded[i] = table[i] ^ key[i % 16]

The loop bound is 49 (cmp x6, #0x31), and the key index is i & 0xf. Replaying it:

table = bytes([
    0x27,0x45,0x1f,0x12,0x54,0x0a,0x08,0x5c,0x15,0x12,
    0x6b,0x5e,0x0b,0x08,0x09,0x4f,0x1c,0x40,0x14,0x16,
    0x56,0x02,0x6e,0x57,0x5d,0x06,0x3e,0x52,0x49,0x0c,
    0x5d,0x47,0x76,0x14,0x41,0x41,0x00,0x55,0x63,0x0c,
    0x5d,0x01,0x6f,0x09,0x4c,0x58,0x0d,0x16,0x77,
])
key = b"CursedWomb_0x99!"
plain = bytes(table[i] ^ key[i % 16] for i in range(len(table)))
print(plain.decode())

The result is 49 printable characters: a 17-character leetspeak prefix followed by a 32-hex-character tail. That message is what the success callback displays.

Step 9 — Solver

Goal: Automate the full chain and assert the forward hash matches before decrypting.

The full script is solve.py at the challenge root:

python3 solve.py
[*] key     : CursedWomb_0x99!
[*] V4      : ['0xf24ab2bd', '0x4f9b6d66', '0xfe439ecc', '0x970a8d2d']
[*] expected: ['0xf24ab2bd', '0x4f9b6d66', '0xfe439ecc', '0x970a8d2d']
[+] checks pass: True
[+] decrypted: <REDACTED>
[+] flag: r00t{REDACTED}

Flag

r00t{REDACTED}

The decrypted text is the flag body; the platform adds the event wrapper:

r00t{REDACTED}

Lessons / Takeaways

  • Release Flutter builds are static-friendly, but not free. libapp.so has no kernel; Blutter gives the map, but constant folding and Smi tagging still require reading the ARM64.
  • Two representations for the same constant: 0xE495657A and 0xF24AB2BD are the same check once you account for Dart Smi tagging (value << 1). Always verify MOVN/MOVK shifts before trusting a disassembler’s printed immediate.
  • Invert algebraically instead of brute-forcing. Componentwise xor/add with a known rotation inverts directly and yields a unique key.
  • The encryption key is the password. The same 16 bytes are the validation input and the XOR key, so recovering one recovers the flag.
  • Check the build type first. Looking for kernel_blob.bin versus libapp.so immediately tells you whether to reach for jadx or Blutter.

Techniques

References