Writeup · 31 Nights of Root

Sealed Decree

stegmediumsolvedFlag: r00t{REDACTED}

Overview

A single PDF, sealed_decree.pdf, is the whole challenge. It looks like a harmless one-page “Decree of the Western Holdings” generated by ReportLab. Nothing on the rendered page is a clue.

The secret lives after the end of the PDF: an unreferenced object (9999 0 obj) appended past %%EOF. Its stream is a 4-byte length prefix followed by ciphertext. The cipher is a byte-wise additive Vigenere with the 5-byte key QUILL, a word taken from the document metadata.

Prerequisites / Setup

  • file, xxd, strings, grep, exiftool, pdfinfo
  • pdfid / qpdf / binwalk (optional)
  • python3
  • sealed_decree.pdf in the working directory
  • No online services needed

Recon

Step 1 — Identify the file

Goal: Confirm the file is a PDF and note its size.

file sealed_decree.pdf
# sealed_decree.pdf: PDF document, version 1.3, 1 pages

A plain, tiny PDF (2401 bytes). Small files leave nowhere to hide data except the structure itself, so read the raw bytes.

Step 2 — Read the metadata

Goal: Extract the Info dictionary; odd fields are often the key.

exiftool sealed_decree.pdf
# or
pdfinfo sealed_decree.pdf

The Info dictionary (object 7) is the useful part:

Field Value
Author Office of the Chancellor
Title Sealed Decree - Filing Copy
Subject Decree of the Western Holdings
Keywords Filing ref: QUILL-7734-W
Producer ReportLab PDF Library
CreationDate / ModDate 2026-10-05 18:52:03

Step 3 — Check the visible page (decoy)

Goal: Decode the page content stream to confirm it is just flavour text.

The page content stream is /Filter [/ASCII85Decode /FlateDecode]. You do not need a viewer to read it; decode it:

python3 - << 'EOF'
import re, zlib, base64
pdf = open("sealed_decree.pdf", "rb").read()
s = pdf[pdf.index(b"9 0 obj"):]
body = s[s.index(b"stream\n")+7 : s.index(b"~>")]
print(zlib.decompress(base64.a85decode(body)).decode())
EOF

Decoded text operators:

(DECREE OF THE WESTERN HOLDINGS)
(By order of the Chancellor's office, the following is entered)
(into the permanent record of the Western Holdings assay and)
(trade commission, effective upon the date of sealing below.)
(All prior filings pertaining to disputed shipments are hereby)
(superseded. ...)
(This copy serves as the filing record and bears no further)
(annotation beyond the reference mark affixed by the clerk's)
(office at time of entry.)
(Filing copy -- commission archive -- not for public distribution)

Pure flavour text, with one nudge: “the reference mark affixed by the clerk’s office” points back at the filing reference in the metadata. No flag or ciphertext in the page.

Step 4 — Look at the structure and the tail

Goal: Find anything after the last %%EOF and any object the xref table never mentions.

xxd sealed_decree.pdf | tail -n 25

A well-formed PDF ends with startxref <offset> then %%EOF. Here, after %%EOF, there is more:

000008d0: 4f46 0a0a 3939 3939 2030 206f 626a 0a3c  OF..9999 0 obj.<
000008e0: 3c20 2f54 7970 6520 2f4d 6574 6164 6174  < /Type /Metadat
000008f0: 6120 2f53 7562 7479 7065 202f 436f 6d6d  a /Subtype /Comm
00000900: 6973 7369 6f6e 5365 616c 202f 4c65 6e67  issionSeal /Leng
00000910: 7468 2034 3620 3e3e 0a73 7472 6561 6d0a  th 46 >>.stream.

Quick confirmations that the object is hidden:

# Where does the real file end?
grep -abo '%%EOF' sealed_decree.pdf
# Is there an object the xref table never mentions?
grep -abo '[0-9]* 0 obj' sealed_decree.pdf
# xref declares /Size 10 (objects 0-9), but 9999 exists
strings -n 6 sealed_decree.pdf | grep -n -E 'obj|Size|CommissionSeal'
Offset (hex) Content Notes
0x000 %PDF-1.3 header normal
0x736 xref (offset 1846 in startxref) lists objects 0-9 only
0x8cd-0x8d1 %%EOF the PDF officially ends here
0x8d2-0x8d3 two \n padding
0x8d4 9999 0 obj orphaned object, 141 bytes to end of file
0x920 stream data (46 bytes) 00 00 00 2a + 42 bytes

Why it is invisible to readers:

  • It sits after %%EOF, and readers locate objects via startxref, which points at the earlier xref.
  • Object number 9999 is not in the xref table (/Size 10).
  • /Type /Metadata /Subtype /CommissionSeal is a made-up subtype nothing will ever interpret.

Exploitation

Step 5 — Carve the blob

Goal: Extract the orphaned object’s stream bytes.

The dictionary says /Length 46, so read exactly 46 bytes after stream\n. Do not rely on finding endstream, because ciphertext can legitimately contain 0x0a.

OFF=$(grep -abo '9999 0 obj' sealed_decree.pdf | head -1 | cut -d: -f1)
echo "orphan at decimal offset $OFF"   # 2260 (0x8d4)
tail -c +$((OFF+1)) sealed_decree.pdf | strings -n 4 | head

Raw carve with dd, once you know the data starts at 0x920 (2336) and runs 46 bytes:

dd if=sealed_decree.pdf bs=1 skip=2336 count=46 of=blob.bin 2>/dev/null
xxd blob.bin
00000000: 0000 002a c385 79c0 c781 c7b9 b480 bf88  ...*..y.........
00000010: adab 7cb3 bf7c afc0 c4b4 b17d b084 b47a  ..|..|.....}...z
00000020: baab c1c1 7d7d bab0 c87a b3b4 c5d2       ....}}...z....

Step 6 — Parse the header

Goal: Read the 4-byte big-endian length prefix.

The first four bytes are a big-endian integer:

00 00 00 2a  ->  0x2a  ->  42

46 total minus 4 = 42 bytes of ciphertext, exactly the length of a flag like r00t{...} with a medium-sized leetspeak body. That is a strong hint the blob is a length-preserving cipher of one flag.

Step 7 — Identify the cipher

Goal: Determine the cipher family from the byte values.

c3 85 79 c0 c7 81 c7 b9 b4 80 bf 88 ad ab 7c b3 ...
  • Plain ASCII is below 0x80. If this were XOR with an ASCII key, every output byte would also be below 0x80. Most of these are above it, so it is not XOR.
  • Values cluster in two bands, 0x79-0x7d and 0xb0-0xd2. That is what plaintext + key (mod 256) looks like when both are printable ASCII (0x30-0x7d plus 0x49-0x55 gives 0x79-0xd2).

So: byte-wise additive Vigenere, C[i] = (P[i] + K[i mod n]) mod 256.

Step 8 — Recover the key without using the metadata (known plaintext)

Goal: Derive the key from the known flag prefix r00t{.

The event’s flags start with r00t{. Subtract that crib from the first five ciphertext bytes:

ct   = bytes.fromhex("c38579c0c7")
crib = b"r00t{"
print(bytes((c - p) % 256 for c, p in zip(ct, crib)))
b'QUILL'
i C crib C - crib char
0 0xc3 r 0x72 0x51 Q
1 0x85 0 0x30 0x55 U
2 0x79 0 0x30 0x49 I
3 0xc0 t 0x74 0x4c L
4 0xc7 { 0x7b 0x4c L

The recovered key is the first word of Filing ref: QUILL-7734-W from the metadata. Two independent routes agree, so the key length is 5 and the key is QUILL. The -7734-W part is a red herring.

Step 9 — Decrypt

Goal: One-shot solver that goes from the PDF to plaintext.

#!/usr/bin/env python3
"""solve.py - sealed_decree.pdf -> flag. Usage: python3 solve.py sealed_decree.pdf"""
import re, struct, sys

pdf  = open(sys.argv[1], "rb").read()
tail = pdf[pdf.rfind(b"%%EOF") + 5:]          # everything after the last %%EOF

m = re.search(rb"(\d+) 0 obj\s*<<(.*?)>>\s*stream\r?\n", tail, re.S)
assert m, "no orphaned object after %%EOF"
length = int(re.search(rb"/Length\s+(\d+)", m.group(2)).group(1))
blob   = tail[m.end(): m.end() + length]       # 4-byte length + ciphertext

n  = struct.unpack(">I", blob[:4])[0]
ct = blob[4:4 + n]
assert len(ct) == n, "length header does not match"

# Route A: key from metadata  ->  b"QUILL"
# Route B: key from known plaintext (flag prefix)
crib = b"r00t{"
key  = bytes((c - p) % 256 for c, p in zip(ct, crib))
print("key from crib :", key)

pt = bytes((c - key[i % len(key)]) % 256 for i, c in enumerate(ct))
print("plaintext     :", pt.decode())
python3 solve.py sealed_decree.pdf
key from crib : b'QUILL'
plaintext     : r00t{REDACTED}

The plaintext is 42 characters long, matching the length header. Opening `r00t{REDACTED} are in place, and the leetspeak body reads as a sentence about orphaned objects hiding in plain sight.

Flag

r00t{REDACTED}

Lessons / Takeaways

  • Workflow for PDF steg

    1. file, then exiftool / pdfinfo for metadata. Odd Keywords or Subject fields are often the key.
    2. Decode the visible streams (ASCII85 / Flate) to rule out decoy content.
    3. xxd | tail. Look for anything after the last %%EOF.
    4. Compare object numbers found by grep -abo '[0-9]* 0 obj' against the xref /Size. Orphans are suspicious.
    5. Carve by declared length, not by searching for endstream.
  • Appended-after-EOF data is invisible to every PDF reader because the xref table is the only index. A fake subtype like /CommissionSeal is ignored for the same reason.

  • A 4-byte big-endian length prefix is a common CTF framing. It confirms the blob is one self-contained message and tells you how long the plaintext should be.

  • Byte values above 0x7f in what should be text rule out XOR with a printable key and point to addition (or a Caesar/Vigenere over bytes).

  • Known-plaintext cribs (r00t{, flag{, safctf{) recover short repeating keys instantly: subtract the crib from the first len(crib) bytes and look for ASCII.

  • Red herring: -7734-W in the filing reference. Only the first word was used.

  • Detection in the real world: pdfid, qpdf --check, and comparing file size against the xref/startxref extent flag incremental or trailing data. Strip it with qpdf --linearize in.pdf out.pdf (or by truncating after %%EOF) when sanitising PDFs.

Techniques

  • PDF Steganography
  • Appended Data After EOF
  • Known-Plaintext Attack
  • Vigenere Cipher
  • Metadata Analysis

References