Tutorial Demonstrates Custom Shellcode Execution via a Stack Pivot

· 18:57 · Watch on YouTube ↗

Summary

A tutorial demonstrates a file-based stack buffer overflow in a 512-byte buffer, overwrites the return address to pivot execution to the stack, and runs custom shellcode with DEP, stack cookies, and ASLR disabled.

Key points

  • The demonstration program reads a file into a fixed 512-byte buffer using the file size as the read length, allowing an oversized input to overflow the buffer.
  • The presenter uses IDA to inspect the stack layout and calculates a 524-byte offset to reach the return address; a Python script builds the payload.
  • DEP, stack-cookie protection, and ASLR are disabled to simplify the demonstration.
  • The payload overwrites the return address with a jump ESP instruction at 0x40100C, redirecting execution to the stack; a NOP sled is included.
  • The custom shellcode calls WinExec with the string "calc" and then exits the process.
  • The presenter assembles shellcode with NASM and uses CyberChef to convert the output into bytes for the payload, noting that LLM-generated opcode documentation contained errors that needed correction.
  • The video introduces return-oriented programming (ROP) as a possible next step for working around a non-executable stack, but does not demonstrate a ROP exploit.

Article Details

Topics
  • [00:14] File-based buffer overflow in a fixed-size stack buffer
  • [01:09] Stack pivot setup and the role of ASLR and other mitigations
  • [03:00] Payload construction and calculating the return-address offset
  • [08:35] Debugging the overflow and verifying control of the return address
  • [10:01] Using a jump ESP instruction and NOP sled to pivot execution
  • [14:47] Assembling custom shellcode and converting it for the payload
  • [17:13] ROP as a possible approach to avoiding direct execution on the stack

Products

Tools

Related Articles