Safe Penetration Testing Labs · intermediate · ~15 min
Scan a frame snapshot for the glibc-style canary pattern.
Walk the frame 8 bytes at a time; flag slots where byte 0 is 0 and at least one of bytes 1..7 is non-zero.
Recognising the canary's shape is step one in understanding why naive overflows fail and why mitigations matter.
Linux toolchains protect functions with stack canaries: a random
machine word inserted between local variables and the return
address, checked before the function returns. On glibc x86_64 the
canary's low byte is always 0x00 — a deliberate null byte so naive
string-write overflows cannot make it through without detection.
We're not writing a stack-smasher. We're writing a detector that recognises the canary's shape: a word whose low byte is zero, in a specific frame slot.
Implement int has_canary_pattern(const uint8_t *frame, size_t n).
Return:
1 if any 8-byte aligned slot has its low byte (the first byte of
the slot) equal to 0x00 AND the upper 7 bytes contain at least one
non-zero byte. That's the glibc canary's signature: low byte zero,
rest random.0 if no such slot exists.-1 if frame == NULL or n isn't a multiple of 8.Aligned 8-byte stride, low-byte-zero + any-nonzero-elsewhere predicate.