← All researchGREGO GUARD / CASE STUDY 02 / COMPLETED

Record Inspector: diagnosing a boundary violation.

A controlled file-parser exercise demonstrating structured-input mutation, crash analysis, Ghidra root-cause identification, binary-level remediation, and regression testing.

CWE-787 · Out-of-bounds writeWindows x64Ghidra / x64dbg / PowerShell

Executive summary

The parser successfully imported 16-, 32-, and 64-byte payloads, but a 128-byte payload triggered Windows exception 0xC0000005. Debugging revealed a write at index 64 into an inaccessible page. Static analysis showed an unchecked copy loop using a file-derived length.

Crash evidence

Faulting instructionmov byte ptr [rax+rcx],dl
Index at faultRCX = 0x40 (64)
Attempted address...0x1000
Original exception0xC0000005
Destination writable capacity64 bytes

The function committed two memory pages, made the second page inaccessible, and placed the destination 64 bytes before the page boundary. Its copy loop used the supplied payload length without checking that capacity.

Binary hotfix

A code-cave validation stub checks the unsigned payload length against 0x40. Acceptable lengths continue to the original function; oversized lengths terminate with exit code 7.

Caller patch (file offset)0x0848–0x0849
Validation stub (file offsets)0x0D00–0x0D17
Total changed bytes26
Patched SHA-25680A97B2F11658D66FFD9063B40867C719840A00CB929F0A051B764BD60AC372E

Regression results

Payload bytesObserved outcomeExit code
16Imported0
32Imported0
64Imported0
65Rejected7
128Rejected7

Scope and limits

This was a purpose-built educational binary. The patch protects the tested caller, not the unchecked function itself. A source-level repair would enforce the capacity within the processing routine and include broader tests.

Flag exercise

The hidden 20-byte flag was recovered by XOR-decoding a data array with the constant 0x5A, demonstrating basic string obfuscation analysis. Its flag was GRE{b0und4ry_ch3ck5}.

Research and validation were limited to the owned Windows VM and purpose-built executable.