Ret2dlresolve
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Basic Information
As explained in the page about GOT/PLT and Relro, binaries without Full Relro will resolve symbols (like addresses to external libraries) the first time they are used. This resolution occurs calling the function _dl_runtime_resolve.
The _dl_runtime_resolve function takes from the stack references to some structures it needs in order to resolve the specified symbol.
Therefore, it's possible to fake all these structures to make the dynamic linked resolving the requested symbol (like system function) and call it with a configured parameter (e.g. system('/bin/sh')).
Usually, all these structures are faked by making an initial ROP chain that calls read over a writable memory, then the structures and the string '/bin/sh' are passed so they are stored by read in a known location, and then the ROP chain continues by calling _dl_runtime_resolve , having it resolve the address of system in the fake structures and calling this address with the address to $'/bin/sh'.
This technique is useful specially if there aren't syscall gadgets (to use techniques such as ret2syscall or SROP) and there are't ways to leak libc addresses.
Chek this video for a nice explanation about this technique in the second half of the video:
Or check these pages for a step-by-step explanation:
Attack Summary
Write fake estructures in some place
Set the first argument of system (
$rdi = &'/bin/sh')Set on the stack the addresses to the structures to call
_dl_runtime_resolveCall
_dl_runtime_resolvesystemwill be resolved and called with'/bin/sh'as argument
From the pwntools documentation, this is how a ret2dlresolve attack look like:
Example
Pure Pwntools
You can find an example of this technique here containing a very good explanation of the final ROP chain, but here is the final exploit used:
Raw
Other Examples & References
https://guyinatuxedo.github.io/18-ret2_csu_dl/0ctf18_babystack/index.html
32bit, no relro, no canary, nx, no pie, basic small buffer overflow and return. To exploit it the bof is used to call
readagain with a.bsssection and a bigger size, to store in there thedlresolvefake tables to loadsystem, return to main and re-abuse the initial bof to call dlresolve and thensystem('/bin/sh').
Learn & practice AWS Hacking:
HackTricks Training AWS Red Team Expert (ARTE)
Learn & practice GCP Hacking:
HackTricks Training GCP Red Team Expert (GRTE)
Last updated