$ cat writeup.md…
$ cat writeup.md…
metactf
Task: a web endpoint continuously streams printable junk mixed with indexed hex chunks that hide an image. Solution: extract the numbered hex records, rebuild the PNG, decode two QR layers, repair UTF-8-expanded bytes with latin1 re-encoding, then base64-decode the final payload.
Source challenge:
Stomach BugURL:
https://stomachbug.umbccd.net
English summary: the endpoint returns an endless attachment named spew.txt. Inside the stream, useful data appears as numbered hex records mixed with distracting printable ASCII lines.
Recon observations:
spew.txt and keeps streaming.|000|... through |161|.....decode("utf-8").encode("latin1") before opening the nested image.Extraction pipeline:
.decode("utf-8").encode("latin1").#!/usr/bin/env python3 import base64 import io import re import requests from PIL import Image from pyzbar.pyzbar import decode URL = "https://stomachbug.umbccd.net" LINE_RE = re.compile(r"^\|(\d{3})\|([0-9a-fA-F]+)$") def decode_qr(image_bytes: bytes) -> bytes: img = Image.open(io.BytesIO(image_bytes)) result = decode(img) if not result: raise RuntimeError("QR code not found") return result[0].data def fetch_sample(max_lines: int = 2000) -> str: lines = [] with requests.get(URL, stream=True, timeout=15) as r: r.raise_for_status() for i, line in enumerate(r.iter_lines(decode_unicode=True), 1): if line is not None: lines.append(line) if i >= max_lines: break return "\n".join(lines) def main() -> None: sample = fetch_sample() chunks = {} for line in sample.splitlines(): m = LINE_RE.match(line.strip()) if m: idx = int(m.group(1)) chunks[idx] = m.group(2) if not chunks: raise RuntimeError("No numbered hex chunks found") first_png = bytes.fromhex("".join(chunks[i] for i in sorted(chunks))) qr1 = decode_qr(first_png) nested_png = qr1.decode("utf-8").encode("latin1") qr2 = decode_qr(nested_png) flag = base64.b64decode(qr2).decode() print(flag) if __name__ == "__main__": main()
$ cat /etc/motd
Liked this one?
Pro unlocks every complete writeup and expanded API access. $9/mo.
$ grep --similar