Drifter Level 1
Drifter Level 1 — a file-parsing heap corruption bug in C++ code, where overwriting an object's virtual-function pointer redirects execution.
Table of Contents
Source: This content is aggregated from overthewire (MIT). Visit the original repository for the latest version.
Level 1 is a file parsing / heap corruption bug, with C++ classes.
There is no need to mess around with heap exploitation, and C++ lends itself to relatively straight forward exploitation.
SMASHING C++ VPTRS - Although keep in mind that compiler changes can influence how things are laid out.
When looking over the below code, keep in mind what needs to be done to enable debugging, and what SetBuffer does.
One last hint: In order to correctly overflow the objects / pointers, the allocation size will have to be similar to the class size ;) Even blindly messing around will lead to code execution sooner or later
Study guide
Where it fits: Drifter level 1 of 0–15, in the memory corruption stage of the game. The page does not say which account you start as, so check with id after connecting.
What this level teaches
C++ object layout and vtable pointer (vptr) overwrites.
Key ideas
- Heap object layout. C++ objects with virtual functions start with a pointer to a table of function addresses. Overwrite that pointer and the next virtual call goes where you choose.
- No need for deep heap exploitation. The page says that C++ lends itself to relatively straightforward exploitation here.
- Allocation size. To overflow into the right object, the allocation size has to be similar to the class size.
- Debugging. The page tells you to keep in mind what is needed to enable debugging and what
SetBufferdoes; read the source for both. - Reading. “Smashing C++ VPTRs” is linked; note that compiler changes can influence the layout.
How to approach it
- Read the provided code and sketch which objects sit next to each other in memory.
- Craft a file that overflows one into the other.
- Test in
gdband choose a target for the redirected call.
Why it matters
Virtual-call hijacking is behind many browser and application exploits.