Challenge Description

Category: Reverse Engineering / Firmware Forensics

Difficulty: 🔴 Hard

The cartridge carries more than the running HMI needs. A contractor left a readable maintenance log in the firmware and an archive export beside it. The log explains how the archive was keyed. Recover the archive and submit its flag.

The attachment is the same waterworks.gb cartridge used by the other Clearwater training-rig challenges. The service-mode challenge sends us into the input state machine. The full-shift challenge sends us into the process model. This one asks a different question:

What else did the contractor leave in the image?

That wording changed how I approached the file. I stopped treating the ROM as nothing but LR35902 instructions and started treating all 32 KiB as a forensic container.

That distinction is the entire challenge.


TL;DR

  • The supplied file is a 32 KiB, ROM-only Game Boy cartridge
  • Its SHA-256 is 41f2bcb3c80267cc7de348ce06c7dfb4ebfbd375a163d1e70d707e9c59e4bef4
  • Cartridge type 0x00 means there is no Memory Bank Controller
  • Therefore CPU ROM address 0x7200 and file offset 0x7200 identify the same byte
  • A NUL-separated contractor log begins at 0x7000
  • The log says the archive begins at 0x7200 and uses the uppercase plant name shown on the HMI title screen as a repeating key
  • WATERWORKS, HYDROSYS, and WTP-04 are tempting but wrong names
  • The title renderer actually displays CLEARWATER, stored at 0x07D4
  • The 32-byte archive is repeating-key XOR
  • Decryption produces:
flag{maint_log_xor_clearwater01}

Establishing the Evidence

I started by recording the file size and hash before pulling strings or disassembling anything:

$ stat -c '%n  %s bytes' waterworks.gb
waterworks.gb  32768 bytes

$ sha256sum waterworks.gb
41f2bcb3c80267cc7de348ce06c7dfb4ebfbd375a163d1e70d707e9c59e4bef4  waterworks.gb

On PowerShell, the equivalent hash check is:

Get-Item .\waterworks.gb | Select-Object Name, Length
Get-FileHash -Algorithm SHA256 .\waterworks.gb

The Game Boy header occupies 0x0100–0x014F. I used a tiny parser rather than trusting a file-identification guess:

from pathlib import Path

rom = Path("waterworks.gb").read_bytes()

title = rom[0x0134:0x0144].split(b"\x00", 1)[0]

print(f"size           = 0x{len(rom):04x}")
print(f"title          = {title.decode()}")
print(f"cartridge type = 0x{rom[0x0147]:02x}")
print(f"ROM size code  = 0x{rom[0x0148]:02x}")
print(f"RAM size code  = 0x{rom[0x0149]:02x}")
size           = 0x8000
title          = WATERWORKS
cartridge type = 0x00
ROM size code  = 0x00
RAM size code  = 0x00

Those three zeroes matter more than the title:

Header field Value Meaning
Cartridge type 0x00 ROM only; no MBC
ROM size 0x00 32 KiB
External RAM 0x00 None

Why Direct ROM Mapping Matters

The Game Boy exposes cartridge ROM in the CPU range 0x0000–0x7FFF.

On a larger cartridge with an MBC, the lower window is normally fixed while 0x4000–0x7FFF can show different physical banks. In that situation, a note saying 0x7200 is not automatically a unique file offset. I would need the bank number or the code path that selected it.

This image is exactly 0x8000 bytes and declares cartridge type 0x00. There is only one physical 32 KiB ROM and nothing to switch. The mapping is therefore direct:

CPU 0x0000  <->  file offset 0x0000
CPU 0x7000  <->  file offset 0x7000
CPU 0x7200  <->  file offset 0x7200
CPU 0x7FFF  <->  file offset 0x7FFF

This sounds like a small convenience, but it removes an entire class of firmware-analysis mistakes. When the maintenance log later says 0X7200, I can seek to byte 0x7200 without reconstructing bank state.


Triage as a Container, Not Just an Executable

My first pass was deliberately unsophisticated:

strings -a -t x -n 8 waterworks.gb | tail -n 15

The end of the output is immediately suspicious:

7000 HYDROSYS WTP-04 MAINTENANCE LOG V2
7023 2026-02-11 P-101 BEARING REPLACED
7045 2026-03-02 FCV-2 STROKE CALIBRATION
7069 2026-04-19 HMI FIRMWARE 1.3 FLASHED
708d 2026-05-08 OLD SERVICE KEY RETIRED
70b0 2026-06-30 ARCHIVE EXPORT AT 0X7200
70d4 NOTE: ARCHIVE BLOB IS KEYED WITH THE
70f9 PLANT NAME AS SHOWN ON THE HMI TITLE
711e SCREEN. REPEATING KEY. UPPER CASE.
7200 % $&): =+&
7213 1/)$3%6517br1

The main program, text, and graphics all live much earlier in the image. A human-readable maintenance record appearing at 0x7000, followed by odd bytes at the exact offset it names, is much stronger than a random strings coincidence.

For an exact carve, I used:

dd if=waterworks.gb bs=1 skip=$((0x7000)) count=$((0x140)) status=none \
  | tr '\000' '\n'

The log is stored as NUL-terminated records rather than newline-delimited text:

HYDROSYS WTP-04 MAINTENANCE LOG V2
2026-02-11 P-101 BEARING REPLACED
2026-03-02 FCV-2 STROKE CALIBRATION
2026-04-19 HMI FIRMWARE 1.3 FLASHED
2026-05-08 OLD SERVICE KEY RETIRED
2026-06-30 ARCHIVE EXPORT AT 0X7200
NOTE: ARCHIVE BLOB IS KEYED WITH THE
PLANT NAME AS SHOWN ON THE HMI TITLE
SCREEN. REPEATING KEY. UPPER CASE.

The same region can be inspected without Unix tools:

Format-Hex -Path .\waterworks.gb -Offset 0x7000 -Count 0x140
Plaintext contractor maintenance log carved from offset 0x7000

The final three records are effectively a recovery specification:

  1. archive location: 0x7200;
  2. construction: repeating key;
  3. key material: uppercase plant name from the HMI title.

The cipher is easy. Choosing the correct name is where I initially went wrong.


The Name-Selection Dead End

There are four plausible labels in this ROM:

Candidate Where it appears What it really identifies
WATERWORKS Game Boy header at 0x0134 Cartridge/software title
HYDROSYS Copyright/vendor text and maintenance log Contractor/vendor
WTP-04 HMI subtitle and maintenance log Plant asset/site identifier
CLEARWATER HMI title string at 0x07D4 Plant name

I first tried WATERWORKS. It feels authoritative because header parsers label it as the ROM title, and its output is frustratingly close to plausible: every decrypted byte is printable. It is still wrong.

HYDROSYS is printed at the top of the maintenance log, but the log describes Hydrosys as the organization maintaining the rig, not the facility being simulated.

WTP-04 is also visible, but it is an identifier, not a name.

The wording is precise: the plant name as shown on the HMI title screen.

Searching the lower ROM gives the candidates and their locations:

strings -a -t x -n 5 waterworks.gb \
  | grep -E 'WATERWORKS|CLEARWATER|HYDROSYS|WTP-04'
0134 WATERWORKS
07d4 CLEARWATER
07ef PLANT WTP-04
080c (C)2026 HYDROSYS
086f CLEARWATER  WTP-04
7000 HYDROSYS WTP-04 MAINTENANCE LOG V2

Strings alone show that CLEARWATER exists. The title renderer proves that it is the requested label.

At 0x04AA, the ROM places the string at 0x07D4 onto the title-screen tile map:

04AA  ld   hl,$07D4      ; "CLEARWATER\0"
04AD  ld   de,$9825      ; title-screen tile-map destination
04B0  call $0474         ; print NUL-terminated text

04B3  ld   hl,$07DF      ; "WATER TREATMENT\0"
04B6  ld   de,$9842
04B9  call $0474

04BC  ld   hl,$07EF      ; "PLANT WTP-04\0"
04BF  ld   de,$9864
04C2  call $0474

The first line displayed by the HMI is therefore CLEARWATER. WTP-04 is explicitly printed on a later line as a plant number, and HYDROSYS appears as vendor/copyright text elsewhere.

That resolves the ambiguity without relying on what I think a “plant name” should mean.

HMI title renderer selecting CLEARWATER rather than the ROM, vendor, or asset labels

Carving the Archive at 0x7200

The log gives an offset but no length. Looking around the boundary makes the intended extent clear:

xxd -g 1 -s 0x71f0 -l 0x50 waterworks.gb
000071f0: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00007200: 25 20 24 26 29 3a 20 3d 2b 26 1c 20 2a 26 0d 2f  % $&): =+&. *&./
00007210: 2e 26 1a 31 2f 29 24 33 25 36 35 31 37 62 72 31  .&.1/)$3%6517br1
00007220: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................
00007230: 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00  ................

There are 32 nonzero bytes beginning at 0x7200, followed by zero padding:

25 20 24 26 29 3a 20 3d 2b 26 1c 20 2a 26 0d 2f
2e 26 1a 31 2f 29 24 33 25 36 35 31 37 62 72 31

Ciphertext does not generally have to stop at a NUL, so “read until zero” is a heuristic, not a cryptographic rule. Here it is supported by three independent facts:

  • the blob begins exactly where the log says it does;
  • a solid 32-byte run is surrounded by zero padding;
  • those 32 bytes decrypt to one complete brace-delimited flag with no truncation or tail garbage.
The 32-byte archive blob isolated between zero-filled ROM regions

Confirming the Key Before Full Decryption

The log tells us this is a repeating key. The natural interpretation is repeating-key XOR:

plaintext[i] = ciphertext[i] XOR key[i mod key_length]

Before running a whole extractor, I used the expected CTF prefix as known plaintext.

The first ciphertext byte is 0x25. If the plaintext begins with f (0x66), the first key byte must be:

0x25 XOR 0x66 = 0x43 = 'C'

That single byte already agrees with CLEARWATER and disagrees with all three alternatives:

WATERWORKS starts with W (0x57)
HYDROSYS   starts with H (0x48)
WTP-04     starts with W (0x57)
CLEARWATER starts with C (0x43)

Extending the same known-plaintext check over flag{ recovers CLEAR directly:

25 XOR 66 = 43  C
20 XOR 6c = 4c  L
24 XOR 61 = 45  E
26 XOR 67 = 41  A
29 XOR 7b = 52  R

This is a useful confirmation because it does not depend on decrypting the rest of the blob or scoring English. The ciphertext, expected flag grammar, and HMI label all converge on the same key.


Ranking the Candidate Names

I also wrote a small sanity script to compare every plausible label. This is not the primary proof—the renderer and known prefix are stronger—but it makes the false leads visible:

from pathlib import Path

rom = Path("waterworks.gb").read_bytes()
blob = rom[0x7200:0x7220]

candidates = [
    b"WATERWORKS",
    b"HYDROSYS",
    b"WTP-04",
    b"CLEARWATER",
]

def decrypt(key: bytes) -> bytes:
    return bytes(
        byte ^ key[index % len(key)]
        for index, byte in enumerate(blob)
    )

def rank(plain: bytes) -> tuple[int, int]:
    printable = sum(0x20 <= byte < 0x7f for byte in plain)
    grammar = 100 * plain.startswith(b"flag{")
    grammar += 25 * plain.endswith(b"}")
    return printable + grammar, printable

for key in candidates:
    plain = decrypt(key)
    score, printable = rank(plain)
    preview = "".join(
        chr(byte) if 0x20 <= byte < 0x7f else "."
        for byte in plain
    )
    print(
        f"{key.decode():10} score={score:3} "
        f"printable={printable:2}/32  {preview}"
    )
WATERWORKS score= 32 printable=32/32  rapc{moo`uKa~c_xatQbxhpvwazc|1%p
HYDROSYS   score= 30 printable=30/32  my`tfiync.XreuT|f.^c`z}`moqcx1+b
WTP-04     score= 18 printable=18/32  rtt...wi{.,.}r]...Me....rbe..V%e
CLEARWATER score=157 printable=32/32  flag{maint_log_xor_clearwater01}

There is a nice warning hidden in that output: WATERWORKS produces 32 printable bytes too. A printability score alone would not distinguish it from the correct key. The decisive evidence is structure—flag{...}—combined with the title-renderer reference.


Full Reproducible Extractor

The final extractor pulls both the key and the blob from their actual ROM locations. It does not hard-code the recovered flag:

from hashlib import sha256
from pathlib import Path

ROM_PATH = Path("waterworks.gb")
EXPECTED_SHA256 = (
    "41f2bcb3c80267cc7de348ce06c7dfb4"
    "ebfbd375a163d1e70d707e9c59e4bef4"
)

rom = ROM_PATH.read_bytes()

assert len(rom) == 0x8000
assert sha256(rom).hexdigest() == EXPECTED_SHA256
assert rom[0x0147] == 0x00        # ROM ONLY
assert rom[0x0148] == 0x00        # 32 KiB

def c_string(offset: int) -> bytes:
    end = rom.index(0, offset)
    return rom[offset:end]

# The title renderer loads HL=0x07D4 before printing its first line.
key = c_string(0x07D4)

# The contractor log identifies 0x7200. In this image, the first NUL
# after that offset is the end of the 32-byte padded archive field.
blob = c_string(0x7200)

assert key == b"CLEARWATER"
assert len(blob) == 32

plain = bytes(
    byte ^ key[index % len(key)]
    for index, byte in enumerate(blob)
)

print(f"key:  {key.decode()}")
print(f"blob: {blob.hex()}")
print(f"flag: {plain.decode('ascii')}")
key:  CLEARWATER
blob: 25202426293a203d2b261c202a260d2f2e261a312f2924332536353137627231
flag: flag{maint_log_xor_clearwater01}
Repeating-key XOR decoder recovering the maintenance archive flag

This reproduces the solve from the original cartridge bytes and fails loudly if the evidence file, mapping fields, key string, or blob length differs.


Evidence and Limitations

It is worth separating what the ROM proves from what the contractor log merely claims.

The byte-level evidence proves that:

  • the supplied artifact is exactly 32 KiB and has the recorded SHA-256;
  • header type 0x00 gives a direct, unbanked ROM mapping;
  • the NUL-separated log is physically present from 0x7000;
  • the log names 0x7200 and describes an uppercase repeating key;
  • the title renderer at 0x04AA loads 0x07D4, whose string is CLEARWATER;
  • 32 nonzero bytes occur at 0x7200, surrounded by zero padding;
  • repeating-key XOR with the renderer-selected title yields one complete flag.

The ROM alone does not prove that:

  • the dated maintenance events happened in the real world;
  • Hydrosys authored the records rather than the challenge creator;
  • the blob was ever read or decrypted by executing cartridge code;
  • repeating-key XOR supplies integrity or authenticity.

In fact, I found no need for a runtime path to 0x7000 or 0x7200. The challenge works because firmware images can carry inert data that the normal program never references. The records are forensic artifacts, not necessarily live HMI features.

The archive length also deserves honesty. The log gives the start address but not an explicit size. I infer 32 bytes from the isolated nonzero run, the following zero padding, and the complete decoded flag. That is strong evidence for this image, but “stop at NUL” would not be a generally safe parser for arbitrary XOR ciphertext because a legitimate ciphertext byte may itself be zero.

Finally, XOR decryption is malleable. Someone can alter ciphertext and predictably alter plaintext. The recovered flag is semantically convincing, but the format provides no cryptographic authentication.


Flag

flag{maint_log_xor_clearwater01}

Reflection

This challenge is technically simple and analytically good.

The repeating XOR takes a few lines. The difficult part is deciding which evidence deserves authority:

  • the Game Boy header says WATERWORKS;
  • the contractor banner says HYDROSYS;
  • the asset label says WTP-04;
  • the actual HMI title renderer says CLEARWATER.

Only one of those satisfies every word in the log.

I also like that the decisive artifacts do not need to execute. If I had stayed entirely inside the main loop, I would have solved the process simulation and the service sequence while missing the contractor’s filing cabinet at the end of the ROM.

The workflow I want to keep from this one is straightforward:

  1. hash and size the firmware;
  2. parse its mapping metadata;
  3. inspect unreferenced and padded regions, not only code;
  4. treat embedded documentation as a lead, not unquestioned truth;
  5. resolve ambiguous labels through the code that displays them;
  6. confirm the key with known plaintext;
  7. preserve the exact extraction path and its assumptions.

The archive was not protected by difficult cryptography. It was protected by context: knowing which name meant the plant, knowing that 0x7200 was a physical file offset, and remembering that unused bytes can still be evidence.

That is much closer to real firmware forensics than the XOR loop makes it look.