Disclaimer: The experimental environment is Windows 2000
Source: Moeomu’s blog
Disassembly of linked tables
Theory
- Heap block allocation: “unloading” heap blocks from an empty table
- Block release: chaining blocks into an empty table
- Heap merge: “unload” several heap blocks from the empty table, modify the block header information (size), and then “chain” the new updated blocks into the empty table
Heap overflow: construct the block header of the next heap overflow block, rewrite the forward and backward pointers in the block header, and then wait for an opportunity to write arbitrary data to any address in memory in sequence when the allocate-release merge operation occurs.
- This opportunity to write arbitrary data to any location is called
DWORD SHOOT/ARBITARY DWORD RESET
.
target | load | result after rewriting |
---|---|---|
function return address in the stack frame | shellcode start address | function return, execute shellcode |
S.E.H handle in stack frame | shellcode start address | shellcode to be executed when exception occurs |
important function call address | shellcode start address | shellcode executed when function is called |
Practice
Code
|
|
found
- At the time of h1 application to h5 space, if at this time h5 has been overflowed to cover Blink and Flink, then it will write [Flink] to [Blink]
Code implantation
Principle
- Target the PEB synchronization function pointer RtlEnterCriticalSection of the ExitProcess call, and execute the shellcode after the exception is raised by the heap overflow within the program
Code Example 1 (Observe Exception)
|
|
mind
- Just short of ShellCode content
Code example 2 (incomplete)
|
|
Summary
- This time, some important parameters of the shellcode are written, but the main content is not yet written
Code example 3 (problematic)
|
|
Summary
- This is the complete ShellCode, which can successfully use the heap overflow of Win2000
- But the problem is that the MessageBox cannot be popped up successfully.
- The reason is that the PEB pointer is spoofed together with the ShellCode, so you need to fix the PEB pointer.
Code example 4 (complete)
|
|
Summary
- This is the complete ShellCode, you can successfully use Win2000’s heap overflow to pop up MessageBox