Writeup · 31 Nights of Root

The Cutout's Relay

miscmediumsolvedFlag: r00t{REDACTED}

Overview

A decommissioned server’s last system log was pulled before the disk was wiped. Whatever was on that machine, it isn’t in the log text itself. See what you can recover…

Only one file is provided, system.log:

wc system.log
  40892  214291 3986194 system.log

The wording is the first hint. The data is not in the readable text of the log, so it must be in an encoded field that looks like noise. The title (a cutout is an intermediary in espionage, a relay passes a message along) suggests data handed from one carrier to the next.

Prerequisites / Setup

  • Python 3 (re, base64, wave, numpy, cryptography, Pillow)
  • system.log in the working directory

Recon

Step 1 — Inspect the log

Goal: Confirm the file is pure ASCII and identify the two line types.

file system.log
# system.log: ASCII text

head -3 system.log
2026-09-14T02:10:01 INFO seq=438 stream=A chunk=IL6MP7IFAHUPY7ICD36ER7F47VBQEWPY...
2026-09-14T02:10:02 INFO cache flush complete
2026-09-14T02:10:04 INFO cache flush complete

The file is pure ASCII with no control characters, so there is no raw binary appended. The log spans 2026-09-14T02:10:01 to 2026-09-15T06:34:10.

Normalising numbers to N and counting line templates shows two kinds of lines:

  • Filler (about 24,500 lines): ten message templates, each appearing roughly 2,400 to 2,500 times (heartbeat ok, cache flush complete, queue depth N, session N expired, retry attempt N succeeded, disk usage at N%, config reload triggered, connection pool resized to N, replication lag Nms, scheduled maintenance window starting). The log levels (INFO/DEBUG/WARN) are random and carry no signal.
  • Chunk lines (16,357 lines): seq=<int> stream=<X> chunk=<string>.

The chunk alphabet is only A-Z and 2-7, with = padding on the shortest ones. That is base32.

grep -c 'chunk=' system.log
# 16357

grep -o 'stream=[^ ]*' system.log | sort | uniq -c
#   16356 stream=A
#       1 stream=B

There are two streams: a big one (A) and a single line (B).

Exploitation — Layer 1: reassemble the streams

Step 2 — Extract stream A

Goal: Parse seq=... stream=A chunk=... lines, order by seq, and base32-decode.

Stream A has 16,356 chunks. Parsing out the seq values shows they are unique and span exactly 0 to 16355, so nothing is missing or duplicated, but the lines are shuffled through the log. Every chunk is 120 characters except the last (seq 16355, 16 characters, ending in ====).

import re, base64

rx = re.compile(r'seq=(\d+) stream=A chunk=(\S+)')
d = {}
for line in open('system.log'):
    m = rx.search(line)
    if m:
        d[int(m[1])] = m[2]

s = ''.join(d[i] for i in range(len(d)))
s += '=' * (-len(s) % 8)
raw = base64.b32decode(s)
open('stage1.wav', 'wb').write(raw)

That is 1,962,616 base32 characters, which decode to 1,226,632 bytes beginning with RIFF....WAVEfmt:

file stage1.wav
# stage1.wav: RIFF (little-endian) data, WAVE audio, Microsoft PCM, 16 bit, mono 44100 Hz

The header is consistent (RIFF size and data chunk size match the file length), which confirms the ordering by seq is correct.

Step 3 — Extract stream B

Goal: Decode the single stream=B chunk; it is a 32-byte key.

Stream B is one line (seq=0, timestamp 2026-09-14T06:51:22):

chunk=OPXQEGFSEQOCGW3WJQFPYNCGDJU354BC6HFAOHVIPSACM3DUI4NQ====

Unlike the A chunks it is properly padded, and it decodes to exactly 32 bytes:

73ef0218b2241c235b764c0afc34461a69bef022f1ca071ea87c80266c74471b

32 random-looking bytes is the size of an AES-256 key, or a SHA-256 digest. It is not the SHA-256 of the WAV. Set it aside as a probable key.

Layer 2: the WAV

Step 4 — Rule out dead ends

Goal: Confirm the WAV’s payload is not in the obvious places.

  • Spectrogram image. Rendering 0 to 22 kHz shows a featureless noise floor with two horizontal notches (about 8.8 kHz and 17.6 kHz) and nothing resembling text or a picture.
  • LSB of the samples. The LSB mean is 0.5003 and the bit-1 plane is 0.4989. Packing the LSB or the two lowest bits into bytes gives high-entropy junk with no file magic.
  • Whole-file FFT peak picking. No dominant peaks stand out over a median-filtered noise floor.

Step 5 — Confirm the noise is synthetic

Goal: Show that deviations from the white-noise model are deliberate.

The autocorrelation of the samples is a perfect triangle:

lag:   1      2      3      4      5
acf:   0.797  0.595  0.396  0.199  0.004

This is white noise passed through a 5-tap moving average (a boxcar filter), which explains the spectral nulls at fs/5 = 8820 Hz and 2fs/5 = 17640 Hz. The signal is generated noise rather than a recording, so any deviation from this model is deliberate. After lag 5 the autocorrelation should be zero, but it shows a small persistent oscillation of about +/-0.03 with a period near 12.5 samples (about 3.5 kHz). Something narrowband is hiding around 3 to 4 kHz.

Step 6 — Find the tones

Goal: Locate the narrowband carriers.

The whole-file FFT has three strong peaks at 3100.7, 3445.5 and 3789.9 Hz. Their spacing is 344.5 Hz, which is exactly fs/128 = 44100/128 = 344.53 Hz. So the tones sit on DFT bins 9, 10 and 11 of a 128-point transform.

Zooming into the first second shows the three tones switching on and off together between about 0.2 and 0.9 s, and they reappear faintly near the end. Flattening the spectrogram by dividing each frequency row by its median shows faint lines at the same three frequencies running through the whole file.

To confirm nothing else is hiding, compute the log-variance of the STFT power per frequency bin after the first 1.2 s. Apart from the DC and Nyquist bins, the only bins with abnormally high variance were 3100.8, 3445.3 and 3789.8 Hz. These three bins are keyed throughout the file.

Step 7 — Slice the bits with a block DFT

Goal: Demodulate the BPSK signal (one bit per 128-sample block on bins 9/10/11).

Split the audio into non-overlapping 128-sample blocks and take the DFT of each, then look at bins 9, 10, 11 specifically:

import wave, numpy as np

w = wave.open('stage1.wav')
x = np.frombuffer(w.readframes(w.getnframes()), dtype='<i2').astype(float)
n = len(x) // 128
F = np.fft.rfft(x[:n * 128].reshape(n, 128), axis=1)
g = (F[:, 9].imag + F[:, 10].imag + F[:, 11].imag) / 3
bits = (g <= 0).astype(np.uint8)          # inverted polarity
raw = np.packbits(bits[:n // 8 * 8]).tobytes()

Key observations behind this:

  1. Cross-bin correlation. Normalised complex correlation between bins 9, 10 and 11 within the same block is 0.77 (essentially purely real). For every other adjacent bin pair it is about 0.00 to 0.03.
  2. Real vs imaginary. For most bins the real and imaginary parts have the same standard deviation (ratio about 1.0). In bins 9, 10 and 11 the ratio is about 0.12. The cosine component has been suppressed and only the sine component carries energy.
  3. Common value. Averaging the imaginary parts of the three bins gives one value g per block. Its histogram is clearly bimodal, with two lobes at roughly +1 and -1 (in units of the standard deviation), and only 60 of 4,791 blocks within 0.3 sigma of zero.

That is BPSK: one bit per 128-sample block (344.53 baud), carried by three phase-locked tones for redundancy. There are 4,791 symbols in total.

Why did the tones look like on/off keying at the start? A burst of identical consecutive symbols adds coherently into a pure tone for as long as the run lasts, while alternating symbols cancel into noise. The first symbols are 22 identical bits, which turn out to be the leading zeros of a length field, and the visible bursts are the long zero runs of the PNG header. That is also why 128-sample blocks look like plain noise individually but non-Gaussian when summed over 256 or more samples.

Brute-forcing the unknowns (polarity, bit offset 0 to 7, bit order) and scoring each candidate by printable ratio and common file magic: exactly one combination produced a file signature — inverted polarity, offset 0, MSB-first:

00 00 02 46 | 89 50 4e 47 0d 0a 1a 0a ...

The leading four bytes are a big-endian length, 0x246 = 582, followed by a PNG signature. The recovered stream is 598 bytes (4,791 bits, with 7 bits left over):

[ 4-byte length = 582 ][ 582-byte PNG ][ 12 trailing bytes ]

The 12 trailing bytes are 63b4e9522118da0ccc4e5757. Remember them — they cause trouble later.

Layer 3: the PNG

Step 8 — Read the PNG LSB plane

Goal: Extract the LSBs and confirm the framing convention.

The PNG is 20×20, 8-bit RGB, non-interlaced, with three chunks only (IHDR, IDAT of 525 bytes, IEND). There are no text or ancillary chunks. Visually it is a flat slate blue (R 84 to 94, G 104 to 115, B 124 to 135), but the small pixel variation is suspicious, since a deliberately flat image would be constant.

Checking the LSB plane, read row-major with R, G, B interleaved and packed MSB-first:

from PIL import Image
img = np.array(Image.open('stage2.png'))
lsb = np.packbits((img & 1).reshape(-1).astype(np.uint8)).tobytes()
print(lsb[:8].hex())   # 0000003bced1e782...

The first four bytes are 00 00 00 3b, a 4-byte length of 59, and the next 59 bytes are high-entropy ciphertext. The rest of the 150 bytes of LSB capacity is just natural pixel noise. The same length-prefix framing convention as in layer 2 confirms this is the intended reading order.

The ciphertext is 59 bytes. We have a 32-byte key (stream B) and 12 unused bytes after the PNG, which look like a nonce. The prime suspect is an AEAD cipher.

Decryption (and the mistake that cost time)

What failed

Goal: Try the obvious layouts and confirm they fail, so the correct one is trusted.

I first assumed the 12 trailing bytes from layer 2 were the nonce, with all 59 bytes as ciphertext:

  • AES-256-GCM, key = stream B, nonce = trailer: InvalidTag
  • ChaCha20-Poly1305, same inputs: InvalidTag
  • Raw ChaCha20 (counters 0 to 3, little and big endian), AES-CTR (several counter layouts), AES-CFB/OFB, plain XOR with the key or nonce: no printable output

None of the outputs scored above about 0.5 printable, which is what random bytes score.

The fix

Goal: Use the arithmetic hint to find the real layout.

The arithmetic gives the hint: 59 = 12 + 47, and 47 = 31 + 16. A 16-byte GCM tag at the end plus a 12-byte nonce at the start would leave a 31-byte plaintext, a very plausible flag length. So the nonce is embedded in the LSB payload itself, and the 12 bytes after the PNG are just padding (or a decoy).

from cryptography.hazmat.primitives.ciphers.aead import AESGCM

body  = lsb[4:4 + 59]
nonce, ct = body[:12], body[12:]          # ct includes the 16-byte tag
print(AESGCM(key).decrypt(nonce, ct, None))
# b'r00t{REDACTED}'

It works with no associated data. A successful AEAD decrypt is unambiguous because the tag authenticates the result, so trying several layouts is safe: a wrong layout can never produce a false positive.

Flag

r00t{REDACTED}

The flag text itself describes the solution: three layers, no shortcuts.

Complete solver

This condensed script reproduces the whole chain from system.log (dependencies: numpy, pillow, cryptography):

#!/usr/bin/env python3
import base64, io, re, sys, wave
import numpy as np
from PIL import Image
from cryptography.hazmat.primitives.ciphers.aead import AESGCM

def b32(s):
    s = s.rstrip('=')
    return base64.b32decode(s + '=' * (-len(s) % 8))

# 1. log -> payload (stream A) + key (stream B)
rx = re.compile(r'seq=(\d+) stream=(\w+) chunk=([A-Z2-7=]+)')
streams = {}
for line in open(sys.argv[1], errors='replace'):
    m = rx.search(line)
    if m:
        streams.setdefault(m[2], {})[int(m[1])] = m[3]
(_, a), (_, b) = sorted(streams.items(), key=lambda kv: -len(kv[1]))[:2]
wav = b32(''.join(a[i] for i in sorted(a)))
key = b32(''.join(b[i] for i in sorted(b)))

# 2. WAV -> PNG
with wave.open(io.BytesIO(wav)) as w:
    x = np.frombuffer(w.readframes(w.getnframes()), dtype='<i2').astype(float)
n = len(x) // 128
F = np.fft.rfft(x[:n * 128].reshape(n, 128), axis=1)
g = (F[:, 9].imag + F[:, 10].imag + F[:, 11].imag) / 3
bits = (g <= 0).astype(np.uint8)
raw = np.packbits(bits[:n // 8 * 8]).tobytes()
png = raw[4:4 + int.from_bytes(raw[:4], 'big')]
assert png.startswith(bytes.fromhex('89504e470d0a1a0a'))

# 3. PNG LSB -> AES-GCM
img = np.array(Image.open(io.BytesIO(png)).convert('RGB'))
lsb = np.packbits((img & 1).reshape(-1).astype(np.uint8)).tobytes()
body = lsb[4:4 + int.from_bytes(lsb[:4], 'big')]
print(AESGCM(key).decrypt(body[:12], body[12:], None).decode())
python3 solve.py system.log
# r00t{REDACTED}

Lessons / Takeaways

  • Nested carriers require nested extraction. Each layer used a completely different medium (log lines, audio tones, pixel LSBs), so a single tool could not solve it.
  • A successful AEAD decrypt is an unambiguous oracle. A wrong layout can never produce a valid tag, so trying several nonce layouts is safe.
  • Length-prefix framing repeated across layers. Both the WAV stream and the PNG LSB stream used a 4-byte big-endian length before the payload — a convention that confirmed the reading order.
  • Synthetic noise is a cover. The WAV was generated noise with a boxcar filter; deviations from that model (the three keyed FFT bins) were the signal.

Techniques

References