Writeup · 31 Nights of Root

Gravimetry

forensicsmediumsolvedFlag: r00t{REDACTED}

Overview

The challenge ships a simulated gravitational-wave strain recording (strain.dat) and a “detector” that decodes a hidden 20-byte message from it. The message is hidden as 160 signal windows, one per bit: a window is 1 if a chirp is injected and 0 if it is only noise. The flag is r00t{gr4v1m3try_<sha256(decoded)[:24]>}.

The provided documentation (detector_params.txt) and the helper script (wave_analysis.py) are decoys. They describe a plausible LIGO-style pipeline (bandpass, Hann template, noise-std SNR, 8.5 sigma threshold) that does not match what the real binary does. Following them gives a wrong flag. The real algorithm has to be recovered from the gravimetry binary.

Prerequisites / Setup

  • Python 3 (numpy, struct, hashlib)
  • radare2 (r2) or objdump / gdb (optional, for dynamic analysis)
  • gravimetry, strain.dat, check in the working directory

Recon

Step 1 — File inventory

Goal: List the files and confirm types.

ls
# check  detector_params.txt  gravimetry  strain.dat  validator  wave_analysis.py

file check
# ELF 64-bit LSB pie executable, x86-64, dynamically linked, stripped

checksec --file=gravimetry
# Partial RELRO | No canary | NX enabled | PIE enabled | No symbols

All three binaries (check, gravimetry, validator) are stripped PIE ELFs. Exploitation is not needed. Static analysis is enough.

Step 2 — Inspect the data file

Goal: Understand strain.dat’s layout.

strain.dat is raw little-endian float32 samples. The size works out as follows:

0xa100 floats = 41216 samples = 256 (calibration) + 160 * 256 (signal windows)

xxd on the head and tail shows ordinary float noise, with no obvious magic bytes or embedded text.

Step 3 — Run the binary

Goal: Observe how gravimetry is invoked.

./gravimetry
# Usage: ./gravimetry strain.dat
./gravimetry strain.dat
# (hangs, no output)

It hangs because it is waiting for input on stdin — the first hint that gravimetry is a verifier that takes a 20-byte guess.

Step 4 — Identify the decoy files

Goal: Confirm detector_params.txt and wave_analysis.py are misleading.

detector_params.txt claims:

  • Calibration pulse at offset 512 (after a 512-sample header)
  • Butterworth order-4 bandpass 50-150 Hz
  • Hann-windowed 100 Hz template, sigma 0.020 s
  • SNR = |dot(window * gain, template)| / noise_std(full signal)
  • Threshold 8.5 sigma

wave_analysis.py implements exactly this. Its own comments hint that something is off (# Hann window, NOT Gaussian, # wrong: AR(1) noise std is inflated). Running it produces a flag-shaped string, but it is not the real one.

Exploitation

Step 5 — Static analysis of main (radare2)

Goal: Recover the true detection algorithm from the disassembly.

r2 -A gravimetry
[0x000013b0]> pdf@main

Annotated behaviour of main:

Address What it does Meaning
0x1172 malloc(0x28400) buffer for 41216 floats
0x1193 fread(buf, 4, 0xa100, f) read the whole strain file
0x11ca loop sum of abs(x) over the first 0x400 bytes (256 floats) calibration at sample 0
0x1201 mulss by constant at 0x2004, then divss by constant at 0x2008 `gain = mean(
0x121f loop sum of squares over 256 floats at 0x2060 template norm squared, then sqrtf
0x1280 loop dot product of the window with the template at 0x2060 per-window matched filter
0x12b6-0x12cc * gain, abs, / norm, comiss against the constant at 0x200c threshold test
0x12d5-0x12df byte[i>>3] |= 1 << (i & 7) LSB-first bit packing
0x12eb cmp edx, 0xa0 exactly 160 windows
0x1311 fread(ptr, 1, 0x14, stdin) reads 20 bytes from stdin
0x132b memcmp(stdin_bytes, decoded, 0x14) compares guess with decoded message

Key observations:

  • gravimetry is really a verifier. It decodes the message from strain.dat and compares it to 20 bytes supplied on stdin. This explains the hang.
  • The template is precomputed in .rodata at 0x2060, 0x400 bytes = 256 floats. The next qword at 0x2460 is the abs mask 0x7fffffff.
  • The three scalar constants live at 0x2004, 0x2008, 0x200c.

Decoy vs. reality

Parameter Decoy (detector_params.txt / script) Real binary
Calibration offset sample 512 sample 0
Signal start sample 256 sample 256
Filtering Butterworth bandpass 50-150 Hz none
Template generated Hann sinusoid 256 floats embedded at 0x2060
Normalisation divide by noise_std(signal) divide by L2 norm of the template
Threshold 8.5 3.5 (read from 0x200c)
Bit order LSB-first LSB-first

Step 6 — Build and run the solver

Goal: Pull the template and constants directly out of the binary and decode the message.

The solver pulls the template and constants directly out of the binary instead of hard-coding them, which removes any chance of transcription error. The .rodata segment maps file offset 0x2000 to virtual address 0x2000, so the virtual addresses from the disassembly can be used as file offsets.

import numpy as np, struct, hashlib

blob = open('gravimetry', 'rb').read()
f32 = lambda off: struct.unpack_from('<f', blob, off)[0]

c1, c2, thr = f32(0x2004), f32(0x2008), f32(0x200c)
tmpl = np.frombuffer(blob[0x2060:0x2060 + 0x400], dtype='<f4').astype(np.float64)
print("consts:", c1, c2, thr)

x = np.fromfile('strain.dat', dtype='<f4').astype(np.float64)
assert len(x) == 0xa100

# calibration: first 256 samples
gain = np.abs(x[:256]).sum() * c1 / c2
tnorm = np.sqrt((tmpl ** 2).sum())

vals = []
for w in range(160):
    win = x[256 + w * 256: 256 + (w + 1) * 256]
    vals.append(abs(np.dot(win, tmpl) * gain) / tnorm)
vals = np.array(vals)

bits = vals > thr
out = bytearray(20)
for i, b in enumerate(bits):
    if b:
        out[i // 8] |= 1 << (i % 8)

print("sorted values near threshold:", np.sort(vals)[70:90])
print("decoded:", out.hex())
open('decoded.bin', 'wb').write(out)
print(f"r00t{REDACTED}}}")

The recovered constants were c1 = 0.00390625 (that is 1/256, so the calibration is a mean), c2 = 0.1 (that is REF_AMP) and thr = 3.5.

The sorted per-window scores split cleanly into two clusters:

... 2.14  2.19  2.33  2.44  2.46  2.59  2.77  2.95  3.00 | 5.57  5.63  5.75  6.00  6.10 ...
        noise windows (max ~3.0)       threshold 3.5       signal windows (min ~5.6)

There is a clear gap between ~3.0 (noise) and ~5.6 (chirp), with the 3.5 threshold in the middle. This confirms the offsets, template and normalisation are correct. If any of them were wrong, the scores would smear together with no gap.

Dynamic fallback (optional)

Break at base+0x132b and dump the decoded buffer from $rsi:

gdb -q ./gravimetry
(gdb) starti
(gdb) info proc mappings      # PIE base: 0x555555554000
(gdb) break *(0x555555554000+0x132b)
(gdb) run strain.dat < /dev/zero
(gdb) x/20xb $rsi

Flag

The flag is built as r00t{gr4v1m3try_ + first 24 hex characters of SHA256(decoded_20_bytes) + }.

./check
# r00t{REDACTED}
# CORRECT
r00t{REDACTED}

Lessons / Takeaways

  • Documentation can lie. Both detector_params.txt and wave_analysis.py were intentionally wrong. Reverse the binary and treat helper scripts as hypotheses.
  • Read constants from the binary, do not retype them. The embedded template and thresholds were extracted by offset, which avoids float-precision and transcription mistakes.
  • Look for a bimodal score distribution. In detection-style challenges a clean gap between two clusters is a strong signal that the decoder is right. A wrong pipeline smears the distribution.
  • A binary that hangs is usually reading stdin. The hang was the first hint that gravimetry is a verifier that takes a 20-byte guess.
  • Small details in disassembly decide everything. lea rbx, [r12+0x400] (signal start), and ecx, 7 / sar eax, 3 (LSB-first packing) and cmp edx, 0xa0 (160 windows) pinned down the exact layout.
  • Dynamic analysis is a good fallback. Dumping $rsi at the memcmp call would also have produced the 20 bytes directly.

Techniques

  • Matched Filtering
  • Reverse Engineering with radare2
  • Decoy Scripts and Misleading Documentation
  • Signal Decoding
  • GDB on PIE Binaries

References