This exploit leverages a buffer overflow vulnerability in a custom SSH implementation that fails to properly allocate and manage memory. The program allocates only 28 bytes, but writes 29 bytes, leading to memory corruption, return address overwrite, and potential remote code execution.
This proof-of-concept (PoC) demonstrates exploitability by:
β
Overflowing the buffer beyond the allocated size.
β
Overwriting the return address with a controlled value.
β
Injecting shellcode for arbitrary command execution.
β
Bypassing protections (NX
, Stack Canaries
, ASLR
).
- Function:
malloc()
allocates only 28 bytes but writes 29 bytes, corrupting adjacent memory. - Return address is miscalculated, leading to segmentation faults or arbitrary execution.
- No error checking for
open()
andwrite()
, causing silent failures. system()
call executes commands unsafely, allowing command injection.- Memory leak due to missing
free(buffer)
calls.
Run the vulnerable program in GDB:
gdb -q ./vulnerable_program
(gdb) run $(python3 -c 'print("A"*40)') # Overwrite EIP