Stack memory refresher
The stack stores call state and temporary data. On x86-64 Linux it usually grows toward lower addresses as space is reserved.
What the registers mean
Section titled “What the registers mean”| Register | Typical x86-64 Linux role |
|---|---|
RSP |
Stack pointer; points to the current top of stack. |
RBP |
Often a frame pointer; optimized code may use it as a general register. |
RIP |
Instruction pointer: the next instruction to execute. |
RDI, RSI, RDX, RCX, R8, R9 |
First integer or pointer arguments under the System V AMD64 ABI. |
RAX |
Common integer return-value register. |
That argument-register order is for the common System V ABI on Linux and other Unix-like systems. Windows x64 uses a different convention.
Why an overflow can change control flow
Section titled “Why an overflow can change control flow”If a function copies more bytes into a local buffer than it holds, later stack data may be overwritten. In a challenge, determine whether the bytes can reach saved control data and whether the protections change what is useful.
- Find the input buffer and the operation that writes to it.
- Send a cyclic pattern and measure the distance to the saved return value.
- Inspect the stack at the return point and confirm which bytes are controlled.
- Build a payload using the measured offset and target-appropriate packed addresses.
Refresh the stack view
Section titled “Refresh the stack view”Each stop shows the current state. After an instruction pushes, pops, reserves, or releases data, inspect the new address instead of relying on an old dump.
x/24gx $rsp # 24 eight-byte values from the current stack pointerx/64bx $rsp # 64 individual bytesx/8i $rip # instructions at the current instruction pointerinfo registers # fresh register values after a stop or stepWith GDB, x/nfu ADDRESS takes a repeat count, format, and unit size. Common units are b (byte), h (2 bytes), w (4 bytes), and g (8 bytes).
Details that affect payloads
Section titled “Details that affect payloads”- Alignment: under the System V AMD64 ABI, the stack is 16-byte aligned immediately before a call; at function entry, RSP is 8 modulo 16 because the call pushed a return address.
- Endianness: x86-64 stores multi-byte integers little-endian. Pack addresses with
p64()orflat(); do not type them as text. - ASLR and PIE: stack, library, and PIE addresses can change between runs. A value from one run is not proof that it is stable.
- Canaries: a stack protector may stop the function before it returns. A crash in
__stack_chk_failis not the same as controlling RIP. - Input boundaries: newline, NUL bytes, or a length limit can change which payload bytes arrive.
Primary reference
Section titled “Primary reference”The System V AMD64 ABI documents the calling convention, stack frame, and alignment rules.