Lab 05 — CTF: The Vault¶
Difficulty: CTF Time: 4–8 hours Prerequisites: Lab 01 through Lab 04, Chapter 40 §6.1 in full, 34-Cryptography, 57-Ghidra
The challenge¶
You are handed vault.apk. It installs, it runs, and it shows one screen with a text field and a
button marked OPEN. Whatever you type, it says:
Locked.
jadx shows you thirty-one classes, none of which resemble an application. strings on the DEX
returns nothing you can use. apktool completes but the Smali is meaningless. There is a 2.4 MB file
in assets/ with entropy 7.99, a native library with two exported symbols, and a manifest whose
<application android:name> you have never seen before.
Recover the flag. It has the form OBFLAB{...} and it is displayed when the correct passphrase is
entered.
You may not brute-force the passphrase, and you may not patch the comparison and read the flag off the screen — the flag is derived from the passphrase, so a patched comparison shows you a decryption failure and nothing else. You must actually recover it.
Objective¶
Run the entire deobfuscation methodology, in order, against a target that stacks every protection in the chapter:
| Layer | Technique | Chapter section |
|---|---|---|
| 1 | Packer: stub Application, encrypted asset, ClassLoader surgery |
§3.7 |
| 2 | Anti-debug in .init_array, before JNI_OnLoad |
§3.7.1 |
| 3 | R8 renaming across the payload | §3.1 |
| 4 | Per-class string encryption | §3.2 |
| 5 | Control-flow flattening on the key-derivation method | §3.3.2 |
| 6 | Part of the key computed in native code, registered with RegisterNatives |
§3.6 |
| 7 | Reflection instead of direct calls at the crypto boundary | §3.4 |
The point is not any individual layer — you have defeated each one already in labs 01 to 04. The point is ordering. Attack these in the wrong sequence and you will spend a day; attack them in the methodology's order and it is an afternoon.
Why this matters¶
Real targets do not present you with one technique at a time. A hardened banking app is packed and renamed and string-encrypted and partly native and watching for your debugger, and the panic that produces in an analyst who has only ever practised techniques in isolation is the actual protection.
The methodology exists to remove that panic. It is a repeatable procedure, which is what makes it teachable and what makes your results consistent under time pressure:
Phase 0 acquire and verify
Phase 1 triage — what protection is present?
Phase 2 static or dynamic?
Phase 3 UNPACK, if packed
Phase 4 RECOVER STRINGS FIRST
Phase 5 recover control flow — only for methods the strings flagged
Phase 6 semantic renaming from the evidence
Phase 7 write the model down
Every ordering decision in that list is load-bearing, and this lab is constructed so that violating any of them costs you visibly:
- Skip Phase 1 and you will read the stub for an hour.
- Do Phase 5 before Phase 4 and you will deflatten the wrong method.
- Skip Phase 6 and you will lose track of what you already understood.
- Skip Phase 7 and you will miss the native component entirely.
Rules¶
- No brute force on the passphrase, and no dictionary attacks.
- No patching the comparison to bypass it. The flag is derived from the passphrase; a bypass shows you a failed decryption and nothing more.
- You must be able to state, for each of the seven layers, which phase of the methodology defeated it and roughly how long it took.
- Solve it, then write the two-page model that Phase 7 demands. The model is the deliverable; the flag is the receipt.
Building the challenge¶
Build it yourself. Constructing the stack is what teaches you why the ordering matters — you will see, from the inside, which layers depend on which.
Start from the packer in lab 04 and the string encryption from
lab 02. Full sources for both are in ../examples/.
Part 1 — the payload app¶
Package com.obflab.vault.
VaultActivity.java
package com.obflab.vault;
import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.LinearLayout;
import android.widget.TextView;
public class VaultActivity extends Activity {
@Override protected void onCreate(Bundle b) {
super.onCreate(b);
final EditText input = new EditText(this);
input.setHint("passphrase");
final TextView out = new TextView(this);
out.setTextSize(15f);
out.setPadding(0, 48, 0, 0);
Button open = new Button(this);
open.setText("OPEN");
open.setOnClickListener(new View.OnClickListener() {
@Override public void onClick(View v) {
String r = Vault.open(VaultActivity.this, input.getText().toString());
out.setText(r == null ? "Locked." : r);
}
});
LinearLayout root = new LinearLayout(this);
root.setOrientation(LinearLayout.VERTICAL);
root.setPadding(48, 96, 48, 48);
root.addView(input);
root.addView(open);
root.addView(out);
setContentView(root);
}
}
Vault.java — the crypto, reached through reflection so there are no direct Cipher references
for a static cross-reference search to find.
package com.obflab.vault;
import android.content.Context;
import android.util.Base64;
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.security.MessageDigest;
public final class Vault {
static { System.loadLibrary("vaultcore"); }
/** Registered dynamically in JNI_OnLoad — no Java_* symbol to grep for. */
private static native int mix(int seed, int rounds);
public static String open(Context ctx, String passphrase) {
try {
if (passphrase == null || passphrase.isEmpty()) return null;
// S1.a(int) is the per-class string decryptor for this class.
String salt = S1.a(0); // "obflab-vault-2024"
String algo = S1.a(1); // "AES/CBC/PKCS5Padding"
String kAlg = S1.a(2); // "AES"
String hAlg = S1.a(3); // "SHA-256"
String asset = S1.a(4); // "vault.bin"
int seed = KeySchedule.derive(passphrase, salt); // FLATTENED
int mixed = mix(seed, 17); // NATIVE
MessageDigest md = MessageDigest.getInstance(hAlg);
md.update(passphrase.getBytes(StandardCharsets.UTF_8));
md.update(salt.getBytes(StandardCharsets.UTF_8));
md.update(new byte[] {
(byte) (mixed >>> 24), (byte) (mixed >>> 16),
(byte) (mixed >>> 8), (byte) mixed
});
byte[] key = new byte[16];
System.arraycopy(md.digest(), 0, key, 0, 16);
byte[] blob = readAsset(ctx, asset);
byte[] iv = new byte[16];
System.arraycopy(blob, 0, iv, 0, 16);
byte[] ct = new byte[blob.length - 16];
System.arraycopy(blob, 16, ct, 0, ct.length);
// Reflection instead of direct Cipher calls (section 3.4).
Class<?> cipherCls = Class.forName(S1.a(5)); // "javax.crypto.Cipher"
Class<?> skCls = Class.forName(S1.a(6)); // "javax.crypto.spec.SecretKeySpec"
Class<?> ivCls = Class.forName(S1.a(7)); // "javax.crypto.spec.IvParameterSpec"
Object cipher = cipherCls
.getMethod(S1.a(8), String.class) // "getInstance"
.invoke(null, algo);
Object sk = skCls.getConstructor(byte[].class, String.class)
.newInstance(key, kAlg);
Object ivSpec = ivCls.getConstructor(byte[].class).newInstance((Object) iv);
Method init = cipherCls.getMethod(S1.a(9), // "init"
int.class,
Class.forName(S1.a(10)), // "java.security.Key"
Class.forName(S1.a(11))); // "java.security.spec.AlgorithmParameterSpec"
init.invoke(cipher, 2 /* DECRYPT_MODE */, sk, ivSpec);
byte[] pt = (byte[]) cipherCls
.getMethod(S1.a(12), byte[].class) // "doFinal"
.invoke(cipher, ct);
String s = new String(pt, StandardCharsets.UTF_8);
return s.startsWith(S1.a(13)) ? s : null; // "OBFLAB{"
} catch (Throwable t) {
return null; // every failure looks identical
}
}
private static byte[] readAsset(Context ctx, String name) throws Exception {
InputStream in = ctx.getAssets().open(name);
ByteArrayOutputStream bos = new ByteArrayOutputStream();
byte[] buf = new byte[8192];
int n;
while ((n = in.read(buf)) > 0) bos.write(buf, 0, n);
in.close();
return bos.toByteArray();
}
private Vault() { }
}
KeySchedule.java — flattened. Write it unflattened first, verify it works, then flatten by hand
using the pattern from §3.3.2 with
randomised state constants.
package com.obflab.vault;
public final class KeySchedule {
// ORIGINAL — keep this only in your build notes, not in the shipped APK.
//
// static int derive(String pass, String salt) {
// int acc = salt.length() * 131;
// for (int i = 0; i < pass.length(); i++) {
// char c = pass.charAt(i);
// if ((c & 1) == 0) acc = acc * 31 + c;
// else acc = acc ^ (c << (i % 8));
// if (acc < 0) acc = ~acc;
// }
// return acc + salt.charAt(0);
// }
static int derive(String pass, String salt) {
int acc = 0, i = 0;
char c = 0;
int state = 0x3D71A2;
while (true) {
switch (state) {
case 0x3D71A2: acc = salt.length() * 131; i = 0; state = 0x08C4F5; break;
case 0x08C4F5: state = (i < pass.length()) ? 0x5A20BE : 0x71E9C3; break;
case 0x5A20BE: c = pass.charAt(i); state = ((c & 1) == 0) ? 0x2F8D41 : 0x66B017; break;
case 0x2F8D41: acc = acc * 31 + c; state = 0x1948DA; break;
case 0x66B017: acc = acc ^ (c << (i % 8)); state = 0x1948DA; break;
case 0x1948DA: state = (acc < 0) ? 0x4C3E82 : 0x7B5F09; break;
case 0x4C3E82: acc = ~acc; state = 0x7B5F09; break;
case 0x7B5F09: i++; state = 0x08C4F5; break;
case 0x71E9C3: return acc + salt.charAt(0);
default: return 0;
}
}
}
private KeySchedule() { }
}
S1.java — the per-class decryptor. Generate the arrays with the script in
../examples/StringEncryption.java and ../examples/gen-string-table.py, using a different key per class. Add S2, S3,
… for the other classes so the app has several decryptors rather than one.
package com.obflab.vault;
final class S1 {
private static final byte[][] D = { /* generated */ };
private static final int K = 0x4B; // different in S2, S3, ...
static String a(int i) {
byte[] e = D[i];
char[] o = new char[e.length];
for (int j = 0; j < e.length; j++) {
o[j] = (char) ((e[j] ^ K) - (j & 7));
}
return new String(o);
}
private S1() { }
}
Note the - (j & 7): a position-dependent term, so a naive single-byte-XOR guess from a static reader
fails while a runtime call is unaffected. That asymmetry is the lab's point in miniature.
Part 2 — the native component¶
app/src/main/cpp/vaultcore.c
#include <jni.h>
#include <stdlib.h>
#include <string.h>
#include <stdio.h>
#include <sys/ptrace.h>
#include <android/log.h>
#define TAG "VAULTCORE"
/* ---- anti-debug in .init_array: runs during dlopen, before JNI_OnLoad ---- */
__attribute__((constructor))
static void guard(void) {
FILE *f = fopen("/proc/self/status", "r");
if (f) {
char line[256];
while (fgets(line, sizeof line, f)) {
if (strncmp(line, "TracerPid:", 10) == 0 && atoi(line + 10) != 0) {
__android_log_print(ANDROID_LOG_ERROR, TAG, "traced");
fclose(f);
exit(1);
}
}
fclose(f);
}
if (ptrace(PTRACE_TRACEME, 0, 0, 0) == -1) {
__android_log_print(ANDROID_LOG_ERROR, TAG, "traceme failed");
exit(1);
}
}
/* ---- the mixing function: part of the key, computed in native code ------ */
static jint mix_impl(jint seed, jint rounds) {
unsigned int x = (unsigned int) seed;
for (int i = 0; i < rounds; i++) {
x ^= x << 13;
x ^= x >> 17;
x ^= x << 5;
x += 0x9E3779B9u;
}
return (jint) x;
}
static jint JNICALL native_mix(JNIEnv *env, jclass c, jint seed, jint rounds) {
(void) env; (void) c;
return mix_impl(seed, rounds);
}
/* Registered dynamically, so there is no Java_com_obflab_vault_Vault_mix
* symbol in .dynsym for anyone to grep for. */
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM *vm, void *reserved) {
(void) reserved;
JNIEnv *env = NULL;
if ((*vm)->GetEnv(vm, (void **) &env, JNI_VERSION_1_6) != JNI_OK) return JNI_ERR;
jclass cls = (*env)->FindClass(env, "com/obflab/vault/Vault");
if (cls == NULL) return JNI_ERR;
static const JNINativeMethod m[] = {
{ "mix", "(II)I", (void *) native_mix }
};
if ((*env)->RegisterNatives(env, cls, m, 1) != JNI_OK) return JNI_ERR;
(*env)->DeleteLocalRef(env, cls);
return JNI_VERSION_1_6;
}
Part 3 — generate the vault blob¶
Choose a passphrase, compute the key exactly as the app does, and encrypt the flag.
#!/usr/bin/env python3
# host — make-vault.py. Run from a scratch directory.
import hashlib, os, struct
from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
PASS = "the-order-is-the-lesson"
SALT = "obflab-vault-2024"
FLAG = b"OBFLAB{strings_before_control_flow}"
def derive(pw, salt):
acc = (len(salt) * 131) & 0xFFFFFFFF
for i, ch in enumerate(pw):
c = ord(ch)
if (c & 1) == 0:
acc = (acc * 31 + c) & 0xFFFFFFFF
else:
acc = acc ^ ((c << (i % 8)) & 0xFFFFFFFF)
if acc & 0x80000000: # Java int is signed
acc = (~acc) & 0xFFFFFFFF
return (acc + ord(salt[0])) & 0xFFFFFFFF
def mix(seed, rounds):
x = seed & 0xFFFFFFFF
for _ in range(rounds):
x ^= (x << 13) & 0xFFFFFFFF
x ^= x >> 17
x ^= (x << 5) & 0xFFFFFFFF
x = (x + 0x9E3779B9) & 0xFFFFFFFF
return x
seed = derive(PASS, SALT)
mixed = mix(seed, 17)
h = hashlib.sha256()
h.update(PASS.encode()); h.update(SALT.encode())
h.update(struct.pack(">I", mixed))
key = h.digest()[:16]
iv = os.urandom(16)
pad = 16 - (len(FLAG) % 16)
pt = FLAG + bytes([pad]) * pad
enc = Cipher(algorithms.AES(key), modes.CBC(iv)).encryptor()
open("vault.bin", "wb").write(iv + enc.update(pt) + enc.finalize())
print(f"seed={seed:#x} mixed={mixed:#x} -> vault.bin")
Warning Run this from a scratch directory, outside the repository. It writes
vault.binand nothing else.
Part 4 — assemble¶
- Build the payload app with R8 enabled (
minifyEnabled true), withvault.binand the native library included. - Extract its
classes.dex. - Pack it with
pack.pyfrom lab 04. - Build the stub, with
payload.datinassets/andvault.bincarried through. - Sign, install, verify it says
Locked.for a wrong passphrase and shows the flag for the right one. - Delete your build notes, or hand the APK to someone else. Knowing the passphrase spoils it.
Your first three attempts (all of which will fail)¶
Do them. Failing deliberately, in order, is the fastest way to internalise why the order exists.
Attempt 1 — open it in jadx and read the code¶
# host
jadx -d v_jadx --no-res vault.apk
find v_jadx/sources -name '*.java' | wc -l
Q1. How many classes? Do any of them mention a vault, a passphrase, or a cipher? What are you
actually looking at, and which single command would have told you that before you opened jadx?
Attempt 2 — attach Frida and hook something¶
# host
frida -U -n com.obflab.vault -l ../scripts/frida-string-decryptor.js
Q2. What happens? Now try frida -U -f com.obflab.vault -l ... --pause. What happens then, and at
which point does the process die?
Q3. Explain the death mechanically. Which section of the chapter predicted it, and what are the two things you can hook instead?
Attempt 3 — grep for the flag¶
# host
strings vault.apk | grep -i obflab
unzip -p vault.apk classes.dex | strings -n 6 | grep -iE 'vault|pass|key|aes'
Q4. Nothing. Name the three independent reasons the flag is not greppable, and rank them by which one you must defeat first.
The methodology, in order¶
Phase 0 — acquire and verify¶
Q5. Record the hash and the signer. Why does this belong in the report even for a CTF?
Phase 1 — triage¶
# host
../scripts/apk-obfuscation-triage.sh vault.apk --deep
Q6. Fill in the six-row table. For each row, name the phase that will address it.
Q7. The triage flags a large high-entropy asset and a second one. What are they, and why is noticing that there are two important?
Phase 2 — static or dynamic¶
Q8. The app has anti-debug. Work through the Phase 2 decision tree (§6.1) out loud and state your decision with the reason.
Phase 3 — unpack¶
# host
frida -U -f com.obflab.vault -l ../scripts/frida-classloader-dump.js --pause
Remember what attempt 2 taught you before you %resume.
Q9. Which configuration change did you need? Was it sufficient on its own?
Q10. State Phase 3's success criterion and confirm you met it. Which manifest-named component did you look for?
Q11. You now have the payload DEX. Re-run triage against it. Which rows changed, and what does that tell you about triaging a packed app before unpacking it?
Phase 4 — recover strings FIRST¶
# host
frida -U -f com.obflab.vault -l ../scripts/frida-string-decryptor.js --pause
sd.candidates()
sd.loaders()
sd.useLoader(<n>)
Q12. Java.use("com.obflab.vault.Vault") fails at first. Why, and what fixes it? What does this
tell you about instrumenting any unpacked app?
Q13. How many decryptors did candidates() rank? Exhaust them all — write the loop. How many
strings did you recover in total?
Q14. Triage the dump. Which recovered string tells you the salt? Which tells you the cipher configuration? Which tells you the asset filename? Which tells you the flag's prefix, and why did the developer have to include that one?
Q15. Annotate the Smali:
# host
apktool d -f -o v_out unpacked.dex 2>/dev/null || baksmali d unpacked.dex -o v_out
python3 ../scripts/annotate-smali-strings.py --smali v_out --json strings-dump.json --write --triage
grep -rn '\[str\]' v_out/ | head -30
Which method is the crypto now? How long did that take, and how long would it have taken without Phase 4?
Phase 5 — recover control flow¶
Only now, and only for the method the strings flagged.
Q16. Which method is flattened? How did the strings tell you it was the one that mattered — and name a flattened method in this app that you should not spend time on.
Q17. Build the state-transition table for KeySchedule.derive. Reconstruct the original. What does
it return for derive("test", "obflab-vault-2024")?
Q18. Verify with Frida rather than trusting your reconstruction. Which is faster here, and under what circumstance would the reconstruction have been worth the extra time anyway?
Phase 5b — the native component¶
Q19. readelf --dyn-syms on the library shows no Java_* symbols. How do you find the
implementation of mix anyway? Name two routes.
Q20. Reconstruct mix from Ghidra. Which well-known algorithm family is it, and what gave it away?
What is the constant 0x9E3779B9 and why does recognising it save you time?
Q21. You do not actually need to reconstruct it. Explain why, and produce the flag using that shortcut instead.
Phase 6 — semantic renaming¶
Q22. Rename at least eight things. List each rename and the evidence category it came from (recovered string, manifest, framework API, JNI signature, structure).
Phase 7 — the model¶
Q23. Write it. What does the app do, which classes implement it, where are the trust boundaries, and what have you not looked at?
Q24. Recover the flag. State the passphrase and the flag.
Hints¶
Hint 1 — you are not stuck, you are out of order
If you are reading flattened Smali and have not recovered strings, stop. If you are recovering strings and have not unpacked, stop — you are recovering the stub's strings, and the stub has none worth having. The phases are ordered because each one makes the next cheaper. Working out of order is not slower by a constant factor; it is slower by a factor that grows with the size of the target.Hint 2 — the ClassLoader after unpacking
`Java.use` resolves against `Java.classFactory.loader`, which after unpacking is **not** the loader holding the real classes. `sd.loaders()` lists them; `sd.useLoader(n)` switches. Everything else works normally afterwards. This is not specific to this lab. It is true of every unpacked app, and it is the second most common "Frida cannot see my class" cause after attaching too late.Hint 3 — you do not need to understand `mix`
Re-read [§3.3.2's Pentester's Note](../README.md#332-control-flow-flattening--the-important-one). The question is not "how do I reverse this?" but "**do I need to?**" You need one number: what `mix` returns for the seed the app computes. That is a boundary question, and boundary questions are answered by hooks in thirty seconds regardless of what is inside.Hint 4 — the passphrase
You are not meant to guess it, and you cannot derive it from the key — that is the wrong direction through a hash. Look at where it comes from. It is not in the crypto path at all. Consider: the app must be *able* to be opened by someone. Where would that someone learn the passphrase? Check every resource, every asset, every string you recovered, and the manifest. Then check what the string decryptor returns for indices your annotation pass left unused — `exhaust` recovers strings from code paths that never run, and this is exactly the case it exists for.Solutions¶
Do not read until you have made a genuine attempt at each phase.
Solution — Phases 0 to 3: getting to the real code
**Q1.** Thirty-one classes, none of them an application. You are looking at the packer stub. The single command that would have told you first:unzip -l vault.apk | grep -E 'classes.*\.dex'
// in the REPL, BEFORE %resume
var f = Module.findExportByName("libc.so", "fopen");
Interceptor.attach(f, {
onEnter: function (a) {
this.deny = false;
try { this.deny = a[0].readUtf8String() === "/proc/self/status"; } catch (e) { }
},
onLeave: function (r) { if (this.deny) r.replace(ptr(0)); }
});
Solution — Phase 4: strings, and why they unlock everything
**Q12.** `Java.use` resolves against `Java.classFactory.loader`, which is the *original* loader — the one the stub's `attachBaseContext` replaced. The real classes live in the `InMemoryDexClassLoader` the packer created.sd.loaders()
sd.useLoader(1) // whichever index is the InMemoryDexClassLoader
sd.candidates()
Java.perform(function () {
Java.enumerateLoadedClasses({
onMatch: function (name) {
if (name.indexOf("com.obflab.vault") !== 0) return;
var C;
try { C = Java.use(name); } catch (e) { return; }
var ms;
try { ms = C.class.getDeclaredMethods(); } catch (e) { return; }
for (var i = 0; i < ms.length; i++) {
var sig = ms[i].toString();
if (sig.indexOf("java.lang.String ") === -1) continue;
if (sig.indexOf("(int)") === -1) continue;
sd.exhaust(name, ms[i].getName(), 0, 128);
}
},
onComplete: function () { sd.stats(); sd.save(); }
});
});
grep -rn '\[str\].*AES/CBC' v_out/
Solution — Phase 5: control flow and native, and the shortcut
**Q16.** `KeySchedule.derive` is flattened. The strings told you it mattered indirectly but decisively: the annotated Smali showed `Vault.open` as the crypto method, and `derive` is the only non-framework call in its key-construction path. The one **not** to spend time on: any other flattened method in the payload — the UI helper, the string table initialiser, whatever else the flattener touched. They are equally unreadable and completely irrelevant, and without Phase 4 you would have had no way to tell them apart. That is the whole reason Phase 5 comes after Phase 4 rather than before it. **Q17.** Transition table: | State | Does | Next | |---|---|---| | `0x3D71A2` (entry) | `acc = salt.length()*131; i = 0` | `0x08C4F5` | | `0x08C4F5` | test `i < pass.length()` | `0x5A20BE` if yes, `0x71E9C3` if no | | `0x5A20BE` | `c = pass.charAt(i)`, test `(c & 1) == 0` | `0x2F8D41` if even, `0x66B017` if odd | | `0x2F8D41` | `acc = acc*31 + c` | `0x1948DA` | | `0x66B017` | `acc = acc ^ (c << (i % 8))` | `0x1948DA` | | `0x1948DA` | test `acc < 0` | `0x4C3E82` if yes, `0x7B5F09` if no | | `0x4C3E82` | `acc = ~acc` | `0x7B5F09` | | `0x7B5F09` | `i++` | `0x08C4F5` | | `0x71E9C3` | `return acc + salt.charAt(0)` | — | Sorted by reachability, that is a `for` loop with an `if`/`else` body and a sign correction — exactly the commented original. Compute the value for your test input by hand, then check it. **Q18.** The Frida check is faster:Java.perform(function () {
var K = Java.use("com.obflab.vault.KeySchedule");
console.log(K.derive("test", "obflab-vault-2024"));
});
// Frida REPL — read the registration table as it is submitted
var lib = Process.getModuleByName("libvaultcore.so");
// or resolve RegisterNatives through the JNIEnv function table
// Frida REPL — after unpacking, with the right ClassLoader selected
Java.perform(function () {
var V = Java.use("com.obflab.vault.Vault");
V.mix.implementation = function (seed, rounds) {
var r = this.mix(seed, rounds);
console.log("mix(" + seed + ", " + rounds + ") = " + r);
return r;
};
var K = Java.use("com.obflab.vault.KeySchedule");
K.derive.implementation = function (p, s) {
var r = this.derive(p, s);
console.log("derive(" + p + ", " + s + ") = " + r);
return r;
};
});
Solution — Phases 6 and 7, and the flag
**Q22.** Representative renames and their evidence categories: | Renamed to | Evidence | Category | |---|---|---| | `Vault.open` | contains `AES/CBC/PKCS5Padding` and `vault.bin` | recovered string | | `VaultActivity` | named in `AndroidManifest.xml` as the launcher | manifest | | `KeySchedule.derive` | only non-framework call in the key path | structure | | `S1.decryptString` | returns `String`, called from everywhere | structure + behaviour | | `Vault.mix` | `JNINativeMethod` name `"mix"`, signature `"(II)I"` | JNI registration table | | `readAsset` | calls `Context.getAssets().open` | framework API | | `SALT`, `CIPHER_SPEC`, `ASSET_NAME` fields | the strings they hold | recovered string | | `StubApplication` | `OBFLAB{strings_before_control_flow}
Debrief questions¶
Answer in writing. They are the actual assessment.
- For each of the seven layers, name the methodology phase that defeated it and roughly how long it took. Which layer cost the most, and was that cost proportional to its security value?
- You did Phase 4 before Phase 5. Estimate, concretely, what doing them in the other order would have cost, and name the specific wasted work.
- Which single protection, removed, would have cost you the most additional time? Is it the same one the developer probably thinks is strongest?
- The
mixfunction is a keyless PRNG step. What did it actually protect, and what would have been a better use of the same engineering effort? - The anti-debug ran once, in
.init_array, and stopped mattering thereafter. Design a stronger version, then say honestly what it would and would not buy. - Write the finding, as it would appear in a client report, for the fact that the flag ciphertext, the key derivation, and the passphrase are all shipped inside the APK.
- Rank the seven layers by cost-to-the-attacker per unit of cost-to-the-developer. Which two would you tell a client to keep, and which would you tell them to drop?
- You have five hours and a similar target. Write your plan as a numbered list before opening anything. How does it differ from what you actually did here?
Success criteria¶
- You recovered the flag without brute force and without patching the comparison
- You ran all seven phases in order and can name what each one contributed
- You identified the packing in under two minutes, from the file listing
- You diagnosed the
.init_arrayanti-debug from the timeline and defeated both checks, at the native layer - You unpacked and met Phase 3's criterion by finding a manifest-named component
- You re-triaged the payload and can explain why triaging a packed app describes the packer
- You switched
Java.classFactory.loaderand can explain why that is required for any unpacked app - You exhausted every per-class decryptor with one loop, and can say why per-class decryption costs dynamic recovery nothing
- You annotated the Smali and found the crypto method by grep
- You identified the flattened method from the strings and can name a flattened method you correctly ignored
- You built the transition table for
deriveand verified it against a hook - You located
mixdespiteRegisterNatives, by at least one of the two routes - You recognised
0x9E3779B9and the xorshift shape, and used that to stop reading - You produced the flag using a boundary hook rather than a reimplementation, and can justify it
- You renamed at least eight things, spanning at least four evidence categories
- You wrote the Phase 7 model including "what I have not looked at"
- You answered all eight debrief questions in writing
Note for instructors¶
The pedagogical goal is ordering, not any individual technique. Participants have already defeated each of the seven layers in isolation in labs 01 to 04; what they have not done is choose the sequence under pressure.
Run it as follows. Hand out only the APK. Give no hint that it is packed. Watch how long each
participant spends in jadx before someone runs unzip -l — that interval is the single most
instructive measurement of the session, and it is usually between fifteen and forty minutes.
Bring the group back with one question: "What are you currently reading, and how do you know it is the app?"
Then let them proceed, and intervene only when someone starts deflattening before recovering strings. The intervention is again a question, not an answer: "Which method are you deflattening, and what told you it was the right one?"
Debrief on question 2. Participants who did Phase 5 early will have concrete, personal numbers for what it cost them, and a lesson someone has paid for in their own time is the only kind that survives contact with a real engagement.
Finally, land question 6. The flag ciphertext, the key derivation and the passphrase are all inside the APK, which means the vault was never protected by any of the seven layers — it was protected by the reader's patience. That is the chapter's thesis as a concrete artefact, and it is worth more than the flag.