This is an old revision of the document!
TODO
By going through the echo_service.c
file we see that in the echo_service()
function we use read()
for reading 4096
bytes when we only have 1024
available for a the buf
buffer. We can use this to create a return-oriented programming (ROP) attack.
Let's first consider our steps.
buf
buffer and rewrites the return address of the echo_service()
function triggering the attack (the ROP chain).dup2(sockfd, 1);
dup2(sockfd, 0);
system(“/bin/sh”);
netcat
to send the payload to the server to trigger the attack.We aim for the stack to be the one below:
0x00000000 ... start address of buf ... +--------------------------------+ | dup2() address | <--- return address for echo_service() +--------------------------------+ | pop_pop_ret gadget address | +--------------------------------+ | 4 | +--------------------------------+ | 1 | +--------------------------------+ | dup2() address | +--------------------------------+ | pop_pop_ret gadget address | +--------------------------------+ | 4 | +--------------------------------+ | 0 | +--------------------------------+ | system() address | +--------------------------------+ | junk | +--------------------------------+ | "/bin/sh" address | +--------------------------------+ ... 0xFFFFFFFF