Using CALL $+5 to Build Position-Independent Shellcode
· 10:01 · Watch on YouTube ↗
Summary
A hands-on tutorial demonstrates using CALL, POP, and LEA to find shellcode’s runtime base address, then verifies the result while assembling and debugging the code.
Key points
- The tutorial explains why shellcode needs to locate itself when its memory allocation address is not fixed.
- A CALL instruction pushes its return address onto the stack; POP stores that address in EDX.
- LEA subtracts five from the return address to derive the beginning of the shellcode region.
- The presenter assembles the code with NASM and examines it in IDA.
- The tutorial uses SC launcher and WinDbg to observe the allocation address and confirm the resulting pointer.
- The recovered base address can help shellcode locate data such as strings at offsets relative to its runtime location.
Article Details
- Topics
- [00:00] Why shellcode needs position independence
- [01:00] Using CALL, POP, and LEA to recover the shellcode base address
- [03:00] Assembling the code and examining the instructions in IDA
- [05:14] Debugging execution and verifying the runtime address
- [08:13] Using the base pointer to locate data relative to the shellcode
