Daniel Bae
Menu

Defensive edition

Cursed Mirror and the limits of a non-executable stack

Daniel BaeOriginally published

SecurityDEADFACE CTFPWNROP

The Cursed Mirror binary had a non-executable stack. It also accepted more input than a local buffer could hold. Both observations matter when evaluating what a production build protects.

What the binary headers tell us

The challenge shipped a Linux executable with NX enabled. That protection stops the processor from treating the stack as executable memory. Its scope is quite specific. It does nothing to limit how many bytes a program copies into a buffer.

Two other properties were visible in the build. The function lacked a stack canary, and the executable was built without position independence. Those omissions matter for different reasons. A canary can detect certain overwrites before a function returns. A position-independent executable lets the loader vary its base address when address randomization is enabled.

Where the input contract failed

The function owned a fixed-size buffer. The input operation had no length limit at all, a kind of interface the C standard removed in C11. The program therefore lost control of which part of its own stack the input could change. Correcting that size mismatch addresses the defect even on a platform with different executable protections. NX restricts where new code can run; it does not make corrupted control data safe.

What to check in a release

For a service with the same design, test empty input, the largest valid request and the first request above that limit. The oversized case should take a defined error path. A sanitizer build can catch the original memory error in that test. A separate check on the actual release binary establishes which hardening options survived compilation and linking, and a compiler warning policy can reject unbounded input functions before they reach a build.

One more question belongs in that review. Does the network-facing process need the ability to start an operating-system command at all? Removing an unnecessary capability reduces what a future memory error could expose.