Summary
We're given an Android APK ("PhantomGate") and a remote endpoint. The app claims it won't run in unsafe environments. The goal is to forge an admin authentication proof and retrieve the flag before an auth window expires. The hint says we'll need the API system time.
The server exposes an admin flag endpoint GET /api/admin/flag but it rejects requests unless we provide 4 headers: X-Admin-OTP, X-Admin-Token, X-Admin-Nonce, and X-Caller-UID. The app itself only behaves like an OTP generator and never directly calls the admin endpoint, so we must recreate the proof generation outside the app.
Solution
Enrollment
The app performs enrollment via POST /api/enroll with {}. The response includes encrypted_bundle, bundle_hmac, accounts: ["user_account"], enrollment_token (JWT, exp ~900s), and session_id.
Important: the hint "need API system time" suggests OTP validation is time-sensitive. The server time is available via the HTTP Date header (Werkzeug adds it). The JWT iat in the token matched the Date header, confirming it's the canonical time. So we use server_unix = parse(Date header) instead of local machine time.
Static analysis: hidden accounts + TOTP
MainActivity loads the native library:
System.loadLibrary("phantom_crypto");
The real crypto logic lives in libphantom_crypto.so. The account list is obfuscated in native code.
In PhantomAuthService_nativeGetAccountList, one account is built as "user_account", while the second one is produced by XOR'ing a 12-byte array with 0x5A:
byte_64EF = 3B 3E 37 33 34 05 38 3B 39 31 2F 2A
XOR with 0x5A:
61 64 6D 69 6E 5F 62 61 63 6B 75 70
=> "admin_backup"
So the hidden admin account is admin_backup.
TOTP generation
In nativeGenerateTotp, two paths exist:
user_account: uses secrets produced during enrollmentadmin_backup: uses hardcoded secretxmmword_5530plus a small hardcoded constant
We recovered the admin secret bytes and the additional constant. The code only consumes specific bytes, giving us the admin TOTP key (20 bytes):
A9A4072AC55133F0B39DDBD6261A61B5D4D71DF2
OTP algorithm
sub_18290 implements standard RFC-style TOTP:
time(0)-> unix timestep = 30 seconds (t/0x1E)- HMAC with ipad/opad constants 0x36/0x5C
- Dynamic truncation (
offset = digest[19] & 0xF) % 1_000_000-> 6 digits
So: OTP = TOTP_HMAC_SHA1(key20, counter=floor(server_unix/30)) (6 digits)
Admin flag endpoint
Requesting /api/admin/flag with the properly generated headers returns the flag. The full proof includes computing the OTP from the admin TOTP key using the server's time, signing the nonce with the enrollment token, and setting X-Caller-UID to admin_backup.