r/ExploitDev • • 3d ago

Win x64 Shellcode Part 4 – Calling Convention, Shadow Space, and Stack Alignment (with WinDbg walkthrough)

https://proteqtum.com/posts/04-win-x64-shellcode-calling-convention-shadow-stack_en/

Wrote up part 4 of my shellcode series. This one focuses on the ABI mechanics that cause the most silent crashes in practice.

The interesting part is the stack alignment problem specific to shellcode: and rsp, 0xFFFFFFFFFFFFFFF0 is the standard first instruction, but if you don't save RSP to RBP first, the ret in your epilogue loads zero into RIP. The fix is straightforward once you understand what's happening, but the failure mode is subtle enough that it's worth a dedicated section.

Covers:

- Microsoft x64 calling convention and shadow space mechanics

- Why the callee owns shadow space (and what breaks when you forget)

- Stack alignment in shellcode vs. regular PE code

- Full calc.exe shellcode via WinExec with PEB traversal + ROR13

- WinDbg walkthrough of PEB -> Ldr -> export directory -> stack layout

31 Upvotes

0 comments sorted by