4 minutes
Understanding POP-POP-RET in SEH Exploits

Part of the Exploit Development Module β Certified Cybersecurity Engineer (CCSE) β By Cyberwarfare Labs
π Table of Contents
- Introduction
- What is a Stack Overflow?
- Understanding Structured Exception Handling (SEH)
- Where Does POP-POP-RET Come In?
- Breaking Down POP-POP-RET
- Step-by-Step Example of Using POP-POP-RET in an SEH Exploit
- Finding a Suitable POP-POP-RET Instruction
- Example Exploit Code
- What Happens When We Run the Exploit?
- Conclusion
- Next Steps
π° Introduction
This blog post is part of the Exploit Development module in my journey through the Certified Cybersecurity Engineer (CCSE) certification by Cyberwarfare Labs.
In this article, we explore a common and effective technique in Windows exploitationβPOP-POP-RET, which is often used in SEH-based exploits. Weβll cover not only what it is and how it works but also walk through a practical example and payload structure.
π§ What is a Stack Overflow?
A stack overflow is a flaw that occurs when a program writes more data to a stack-based buffer than it can hold. This causes adjacent memory to be overwritten, which can include other local variables and more importantly, the return address.
If the conditions are right, an attacker can overwrite the EIP (Instruction Pointer) and redirect execution to malicious code. If not, the program will likely crashβleading to a Denial of Service (DoS).
In Structured Exception Handler (SEH) based overflows, we target the SEH chain on the stack, aiming to hijack control flow when an exception occurs.
π Understanding Structured Exception Handling (SEH)
Structured Exception Handling (SEH) is a mechanism in Windows that allows applications to gracefully handle exceptions such as illegal memory access, division by zero, etc.
- Every thread maintains an SEH chain (linked list of exception handlers).
- This chain is stored on the stack, making it exploitable.
- When an exception occurs, Windows walks this chain to locate a suitable handler.
π Where Does POP-POP-RET Come In?
In SEH exploits, our goal is to overwrite the SEH handler with an address that helps us redirect execution to our shellcode.
Thatβs where POP-POP-RET comes in. It helps us bypass basic protections and cleanly transfer execution from the overwritten SEH record to our shellcode, without triggering further exceptions.
π Breaking Down POP-POP-RET
This sequence of instructions helps clean up the stack before jumping to your shellcode:
POPβ Removes and discards the top of the stack.POPβ Removes another stack value.RETβ Pops the next address off the stack and jumps to it (our shellcode).
β Example Flow:
- SEH handler is overwritten with the address of a
POP-POP-RETsequence. - When an exception triggers, Windows jumps to this address.
POPandPOPdiscard stack garbage.RETsends execution to your crafted payload.
π Step-by-Step Example of Using POP-POP-RET in an SEH Exploit
Scenario: Vulnerable Windows Application
Buffer Overflow Identified
- Input function allows more bytes than the buffer can safely handle.
Analyze Stack Layout
- Locate Next SEH and SEH Handler on the stack.
Payload Construction
- Overwrite
Next SEHwith a short jump (\xEB\x06) to shellcode. - Overwrite
SEH Handlerwith address of a POP-POP-RET instruction.
- Overwrite
Trigger Exception
- Application crashes.
- Windows traverses the SEH chain.
- Our
POP-POP-RETsequence is executed. RETtakes execution to our shellcode.
π Finding a Suitable POP-POP-RET Instruction
We are using Mona.py in Immunity Debugger to find usable instructions that are not protected by SafeSEH or ASLR.
!mona seh
Example output:
0x1001AABB : pop pop ret | [vulnlib.dll]
Using this address in our payload to overwrite the SEH handler.
π Example Exploit Code
payload = b"A" * 2000 # Fill buffer to reach SEH
payload += b"\xEB\x06\x90\x90" # Next SEH: Short Jump over SEH
payload += b"\xBB\xAA\x01\x10" # SEH Handler: POP-POP-RET address
payload += b"\x90" * 20 # NOP sled
payload += b"\xcc" * 300 # Shellcode: INT 3 for debugging
Breakdown:
"A" * 2000β Fills the buffer and reaches SEH\xEB\x06β Jumps 6 bytes forward (to shellcode).\x90\x90β NOPs for alignment.\xBB\xAA\x01\x10β Little-endian address of POP-POP-RET. Overwrites SEH"\x90" * 20β Safe space for Shellcode"\xcc" * 300β Breakpoint to analyze control transfer in debugger (Shellcode).
π What Happens When We Run the Exploit?
- Application crashes β triggers exception.
- Windows reads SEH chain β finds overwritten handler.
- Executes
POP-POP-RETβ stack cleaned. RETjumps toNext SEH(short jump).- Execution lands in shellcode β code execution achieved.
π Conclusion
- POP-POP-RET is a classic yet powerful method in SEH exploitation.
- Helps bypass protections by cleaning the stack and redirecting flow.
- Requires a deep understanding of the stack and exception handling.
While modern protections like SafeSEH, DEP, and ASLR make this harder today, it’s a critical foundational technique for understanding Windows exploit development.
I’m planning to enroll in their Exploit Development course which goes indeep about exploit development Certified Exploit Development Professional (CEDP) and will definitely write a review about it.
Here’s another good article that showcase this vulnerability in Easy Chat Server 3.1 here