Branch Engineering Gateway — CTF Writeup

Category: Reverse Engineering + Network/Protocol Exploitation Target: jackpot (ELF x86-64 binary) + TCP service on port 9100. Vibe solved.

Summary

The challenge ships a stripped Linux binary (jackpot) described as a bank’s internal “Terminal Engineering Tool,” plus a TCP service on port 9100 speaking a custom binary-framed protocol that bridges to an XFS (CEN/XFS — the standard ATM middleware API) Cash Dispenser Module. The binary converts a 6-digit session nonce into an 8-digit activation code; that code arms the dispenser over the network protocol, after which draining the vault completely yields the flag.

Step 1 — Triage the binary

$ file jackpot
jackpot: ELF 64-bit LSB pie executable, x86-64, ... stripped

$ strings -n 6 jackpot
ENBANK
[*] session nonce : %s
[*] activation code: %08u
Earth's National Bank - Terminal Engineering Tool
usage: %s <6-digit session code from ATM screen>

The strings alone establish the purpose: feed it a 6-digit session code, get back an 8-digit activation code. ENBANK stood out as a likely embedded salt rather than just a banner fragment, confirmed later in the disassembly.

Step 2 — Disassemble and recover the algorithm

objdump -d -M intel jackpot

The binary is tiny (everything lives in one function at 0x10a0). Key logic:

  1. Validate input: argc == 2 and strlen(argv[1]) == 6, else print usage and exit.
  2. Hash the input (0x10ed–0x113a): a textbook FNV-1a 64-bit hash over the session-code string:
    • offset basis 0xcbf29ce484222325
    • prime 0x100000001b3
    • per byte: h ^= byte; h *= prime (mod 2^64)
  3. Salted mixing loop (0x113a–0x116c): the FNV hash from step 2 seeds a second loop over the fixed 6-byte string "ENBANK" (found in .rodata at 0x2004). Each character:
    • t = (char ^ v) * prime (mod 2^64)
    • v = (t >> 29) ^ t (xorshift-style avalanche/finalizer)
  4. Reduce to 8 digits (0x116c–0x1184): activation_code = v % 100000000, printed zero-padded with %08u.

Verified Python reimplementation

MASK = (1 << 64) - 1
FNV_OFFSET = 0xcbf29ce484222325
FNV_PRIME  = 0x100000001b3
 
def fnv1a64(s: bytes) -> int:
    h = FNV_OFFSET
    for b in s:
        h ^= b
        h = (h * FNV_PRIME) & MASK
    return h
 
def activation_code(session: str) -> int:
    h = fnv1a64(session.encode())
    v = h
    for c in b"ENBANK":
        t = ((c ^ v) * FNV_PRIME) & MASK
        v = ((t >> 29) ^ t) & MASK
    return v % 100_000_000

Sanity-checked against the real binary on several inputs (e.g. 123456 → 47384178, 000001 → 46132288, 999999 → 13905705) — exact match, confirming the reversed algorithm before touching the live service.

Step 3 — Recon the network service

$ nc 10.112.129.168 9100

The service immediately sends a framed JSON banner (2-byte big-endian length + JSON, the same framing used for every reply):

{
  "service": "Branch Engineering Gateway",
  "protocol": "XFS bridge",
  "request_format": "1 byte msg_type + 4 byte big-endian command id + 2 byte big-endian length + <length> bytes of data",
  "reply_format": "2 byte big-endian length + <length> bytes of JSON",
  "msg_types": {"GETINFO": "0x01", "EXECUTE": "0x02"},
  "hint": "query command 0x0304 (WFS_INF_CDM_CAPABILITIES) with msg_type GETINFO for the full command table"
}

A small Python client wraps this framing:

import socket, json, struct
 
def recv_exact(sock, n):
    buf = b""
    while len(buf) < n:
        chunk = sock.recv(n - len(buf))
        if not chunk:
            raise ConnectionError("socket closed early")
        buf += chunk
    return buf
 
def recv_framed_json(sock):
    (length,) = struct.unpack(">H", recv_exact(sock, 2))
    payload = recv_exact(sock, length) if length else b""
    return json.loads(payload) if payload else None
 
def send_request(sock, msg_type, command_id, data=b""):
    pkt = struct.pack(">BIH", msg_type, command_id, len(data)) + data
    sock.sendall(pkt)

Following the hint, GETINFO 0x0304 returns the full XFS CDM (Cash Dispenser Module) command table:

CommandIDPurpose
WFS_INF_CDM_STATUS0x301Live device status, incl. session nonce
WFS_INF_CDM_CASH_UNIT_INFO0x303Cassette counts
WFS_INF_CDM_CAPABILITIES0x304Command table (the hinted query)
WFS_CMD_CDM_DISPENSE0x401Dispense notes (capped at max_dispense: 40 per call)
WFS_CMD_CDM_ARM0x4f0Arm the dispenser — needs the activation code
WFS_CMD_CDM_SET_MONITOR0x4f1Toggle audit/surveillance monitoring
WFS_CMD_CDM_GET_FLAG0x4ffRetrieve the flag, gated on state

GETINFO 0x301 (STATUS) handed over the live session nonce: 864430.

Step 4 — Compute and submit the activation code

$ ./jackpot 864430
[*] session nonce : 864430
[*] activation code: 89185916

EXECUTE 0x4f0 (ARM) needed the right encoding for data. Rather than guess once, several candidate encodings were tried in a single pass (raw ASCII digits, zero-padded ASCII, 4-byte big/little-endian integers, and a few JSON-wrapped forms) against the live service:

candidates = [
    ("raw ascii digits",      str(ACTIVATION).encode()),
    ("raw ascii zero-padded",  f"{ACTIVATION:08}".encode()),
    ("4-byte BE uint",         struct.pack(">I", ACTIVATION)),
    ("4-byte LE uint",         struct.pack("<I", ACTIVATION)),
    ('json {"activation_code": str}', json.dumps({"activation_code": f"{ACTIVATION:08}"}).encode()),
    # ... etc
]

Only the raw ASCII digit string (b"89185916") worked:

{"rc": "WFS_SUCCESS", "detail": "armed - supervisor mode"}

This told us the protocol’s EXECUTE payloads are plain values, not JSON-wrapped — a convention that held for every subsequent command.

Step 5 — Disable monitoring and dispense

STATUS confirmed state is global/device-wide, not per-connection (armed: true persisted across fresh TCP connections). An initial DISPENSE 0x401 with empty data succeeded immediately (max_dispense = 40 notes per call, pulling from the highest-denomination cassette with stock), but GET_FLAG 0x4ff refused:

{"rc": "WFS_ERR_CDM_CASHUNITERROR", "detail": "no proof of cashout on record"}

SET_MONITOR 0x4f1 with b"off" succeeded (monitor_on: false), but a dispense while unmonitored still didn’t satisfy GET_FLAG — same “no proof of cashout” error. This ruled out “monitor must be off during dispense” as the actual gate.

Step 6 — Drain the vault

Cross-checking STATUS after each dispense showed remaining_notes ticking down (280 → 240 → 200 → 160 → …) as each DISPENSE call pulled 40 notes from whichever cassette had the highest denomination in stock (CST4/50, etc.). This suggested “proof of cashout” meant the entire vault had to be emptied, not just a single successful dispense.

Looping DISPENSE until remaining_notes hit 0 confirmed it — the final call returned an explicit tell:

{"rc": "WFS_SUCCESS", "notes": 40, "value": 400, "remaining_notes": 0,
 "detail": "vault empty - cashout proven; GET_FLAG now available"}

STATUS afterward showed flag_released: true, and:

$ EXECUTE 0x4ff (GET_FLAG)
{"rc": "WFS_SUCCESS", "flag": "...."}

Full solve chain

  1. Reverse jackpot: FNV-1a-64(nonce) → salted mix with "ENBANK" (mul + xorshift-29 finalizer) → mod 1e8
  2. Connect to port 9100, parse the custom binary framing
  3. GETINFO 0x0304 → full CDM command table (from the banner’s hint)
  4. GETINFO 0x301 → live session nonce
  5. Run nonce through the reversed algorithm → activation code
  6. EXECUTE 0x4f0 (ARM) with the code as raw ASCII digits → armed
  7. EXECUTE 0x4f1 (SET_MONITOR) with b"off" → monitoring disabled
  8. Loop EXECUTE 0x401 (DISPENSE) until remaining_notes == 0 → vault fully drained, “proof of cashout” satisfied
  9. EXECUTE 0x4ff (GET_FLAG) → flag

Takeaways

  • The binary’s only job was to be an oracle for a keyed hash function — static analysis plus a couple of test runs against the real binary was enough to recover and verify the algorithm without ever needing to brute-force it.
  • The protocol banner self-documented its framing, which made writing a generic send_request/recv_framed_json pair trivial and reusable for every subsequent command.
  • “Armed” state was a red herring on its own — the actual gate for GET_FLAG was unrelated to monitoring and was only discovered by reading remaining_notes carefully across repeated DISPENSE calls.
  • XFS/CDM terminology (WFS_INF_*, WFS_CMD_*) is real ATM middleware vocabulary, which made the command table’s purpose easy to guess even without explicit documentation per command.