From Primitive to Shell
Once you have an arbitrary write, you need a control-flow target:
- Older glibc (< 2.34): overwrite
__free_hookor__malloc_hookwith the address ofsystem(or a one-gadget). The nextfree(p)/mallocthen runs your code, withppointing at"/bin/sh". - GOT overwrite: redirect a library function's GOT entry to
system; works when RELRO is partial or absent. - Saved return address: tcache-poison an allocation onto the stack and overwrite a return address (start a ROP chain).
- Newer glibc (2.34+): malloc/free hooks were removed. Modern targets include
_IO_FILE/ vtable structures and__exit_funcs.
Key Takeaway
The write primitive is generic; the chosen target depends heavily on the glibc version and enabled mitigations.