Writeup · 31 Nights of Root

Better Watch Your Back

reversingeasysolvedFlag: r00t{REDACTED}

Overview

The bundle contains two packet captures in a custom BWYB format, three stripped x86-64 ELF binaries, two Python “analysis” scripts and a methodology note. The data is hidden in a timing covert channel: the payload bytes are random noise, and the message is carried entirely by the inter-arrival times (IATs) between packets.

Most of the bundle is deliberate misdirection. Only one of the three binaries (monitor) and one of the two captures (capture.bwyb) lead to the real flag.

File Type Role
capture.bwyb 180 packets, 9 672 B Real data. timing_spec.txt calls it “an older, incomplete session”
capture2.bwyb 180 packets, 9 809 B Decoy. Described as “PRIMARY”
monitor ELF Real decoder. Reads a capture, compares its decode to 20 bytes on stdin
check ELF Flag oracle. XORs a blob with 0x5c and strcmps it against stdin
validator ELF Same code as check, but a decoy blob
protocol_spec.py Python Decoy decoder (wrong seed, wrong polynomial, wrong bit order)
pattern_match.py Python Decoy decoder (FFT), outputs only zeros
timing_spec.txt text Red-herring methodology (Hurst exponent / ARFIMA)
flowchart LR
    A[capture.bwyb<br/>180 packets] --> B[timestamps]
    B --> C[IATs<br/>9 packets per group<br/>8 deltas]
    C --> D{IAT > threshold g?}
    D -->|bit j, LSB first| E[20 bytes]
    E --> F[sha256 first 24 hex]
    F --> G["r00t{bwyb_...}"]
    H[LFSR seed 0x1EF7<br/>stepped g+1 times] --> D

Prerequisites / Setup

  • Python 3 (struct, hashlib)
  • objdump / readelf / strings for ELF inspection
  • The extracted bundle in the working directory

Recon

Step 1 — Unpack and identify file types

Goal: List the bundle contents and confirm which files are ELF vs. data.

unzip -l 01_BETTER-WATCH-YOUR-BACK.zip
file *
capture.bwyb:     data
capture2.bwyb:    data
check:            ELF 64-bit LSB pie executable, x86-64, stripped
monitor:          ELF 64-bit LSB pie executable, x86-64, stripped
validator:        ELF 64-bit LSB pie executable, x86-64, stripped

check and validator are the same size (14 488 B) but have different hashes, so they differ only in data.

Step 2 — Understand the capture format

Goal: Parse the BWYB records and confirm payloads are noise.

Each record is "BWYB" | u64 LE timestamp | u16 LE length | payload. Both files parse cleanly to exactly 180 records with no trailing bytes. The payloads are random, so there is nothing to find in them. The IATs, however, have an obvious bimodal look (short ~50–150 k, occasional ~1 M outliers), which marks a timing channel.

Exploitation

Step 3 — Confirm the shipped scripts are decoys

Goal: Verify that the provided Python scripts and methodology note are wrong.

Running the shipped scripts is the trap:

python3 pattern_match.py capture2.bwyb   # decoded: 19 bytes of 00
python3 protocol_spec.py capture2.bwyb   # junk bytes, flag candidate rejected by every binary

The header of protocol_spec.py says “correct method, wrong bit order”. Flipping the shift to 1<<j produces a repetitive low-entropy result (7a 00 7a 7a fe ff fb fb ...) that no binary accepts.

Step 4 — Probe the binaries

Goal: Identify which binary actually reads the capture.

echo test | ./check capture2.bwyb      # INCORRECT
echo test | ./validator capture2.bwyb  # INCORRECT
echo test | ./monitor capture2.bwyb    # DENIED

strings shows monitor is the only one that touches the capture (fopen, fread, fseek, memcmp, bad capture, DENIED, CORRECT). check/validator only use fgets and strcmp.

Step 5 — Reverse monitor

Goal: Recover the true decoding rule from the disassembly.

Key observations from the disassembly:

  • It opens argv[1], then loops 180 times: fread 4 bytes, compare to 0x42595742 ("BWYB" little endian), read the 8-byte timestamp, read the 2-byte length and fseek over the payload. This stores 180 timestamps on the stack.
  • For each of 20 groups (r8d counts to 0x14) it:
    1. Sets the LFSR state to 0x1ef7 (reloaded every group).
    2. Picks a polynomial from the group parity. sbb r10d,r10d gives -1 when g is even; then and r10w,0xe3f8 and sub r10w,0x2ff8 give 0xB400 (even) or 0xD008 (odd).
    3. Steps the LFSR g+1 times. r12d holds the result of the last fread (1), then is incremented once per group.
    4. Computes threshold = (state & 0xFF) * 300 + 50000 (imul rdx,rdx,0x12c; add rdx,0xc350).
    5. Walks 8 consecutive deltas. cmovb sets bit rcx of the output byte when threshold < delta, which is LSB first.
    6. Advances rsi by 0x48 (9 packets), so each group consumes 9 timestamps and 8 deltas.
  • Finally it reads 20 raw bytes from stdin and memcmps them with the 20 decoded bytes.

Step 6 — Reimplement the decoder

Goal: Reproduce monitor’s decode in Python.

def lfsr_step(state, poly):
    lsb = state & 1
    state >>= 1
    if lsb:
        state ^= poly
    return state & 0xFFFF

def threshold(g):
    poly = 0xB400 if g % 2 == 0 else 0xD008
    state = 0x1EF7
    for _ in range(g + 1):
        state = lfsr_step(state, poly)
    return 50000 + (state & 0xFF) * 300

def decode(ts):
    out = bytearray()
    for g in range(20):
        thr, byte = threshold(g), 0
        for j in range(8):
            if ts[g*9 + j + 1] - ts[g*9 + j] > thr:
                byte |= 1 << j
        out.append(byte)
    return bytes(out)

Step 7 — Choose the capture

Goal: Decode both captures and pick the one whose output is high-entropy (hash-like).

Capture Decoded (hex) Distinct bytes monitor self-check
capture.bwyb f97955…1995 (masked middle) 20 / 20 CORRECT
capture2.bwyb 7a007a00fe6afbff7affffff7ffb78ff6a7afb7a 8 / 20 CORRECT

capture2 is full of repeats (7a, ff, 00), so it is crafted to look like data while carrying none. capture.bwyb decodes to 20 distinct high-entropy bytes, which is what the hash-based flag format implies.

Step 8 — Derive the flag and confirm with check

Goal: Hash the 20 decoded bytes, format the flag, and confirm with check.

protocol_spec.py is a decoy as a decoder, but its last two lines reveal the flag format, which is consistent with the real decoder:

flag = "r00t{REDACTED}"

check copies a 36-byte blob from .rodata (0x2020), XORs every byte with 0x5c and strcmps the result with a line from stdin. Decoding it statically:

blob = open("check", "rb").read()[0x2020:0x2044]
print(bytes(b ^ 0x5C for b in blob).split(b"\x00")[0])
b'r00t{REDACTED}'

That string is identical to the flag from capture.bwyb, and piping the computed flag into the binary prints CORRECT. Doing the same on validator yields a different, obviously fake deadbeef…-style string, and the flag computed from capture2.bwyb is rejected by check.

Flag

r00t{REDACTED}

Lessons / Takeaways

  • Trust the binary, not the documentation. When a bundle ships both docs and executables, the executable is ground truth. Every Python script and the methodology note were wrong; the stripped ELF was right.
  • Beware of “primary” / “supersedes” language. The note that told us to use capture2.bwyb was the misdirection. A decoder that agrees with itself (monitor accepts any capture’s own decode) is not validation, so seek an independent oracle (here check).
  • Timing covert channels carry data in IATs, not payloads. A bimodal IAT histogram is the tell.
  • Sanity-check decodes by entropy. 20 bytes from a hash should be mostly distinct; heavy repetition is a sign you are on the decoy.
  • Single-byte-XOR blobs in .rodata are quick wins: strings first, then try the key from the loop (xor eax,0x5c).
  • Reading sbb reg,reg / cmov idioms is key to recovering branch-free logic (here the even/odd polynomial and the bit-set).

Techniques

  • Timing Covert Channel
  • LFSR
  • Static Reverse Engineering
  • XOR Obfuscation
  • Decoy Analysis

References