Where we roppin boys? (350pt)
Description
Forknife is still a thing right?
nc ctf.umbccd.io 4100
Author: trashcanna
Attachment
Analysis
buffer overflow
bof in function tryme
:
1 | undefined4 tryme(void){ |
25 bytes copied to
local_10[8]
only 8 bytes can be overwritten to
esp
there was no enough room for args of any function, so we need to enlarge the buffer by stack pivot and then rop attack was available
Solution
ret2text (fgets)
return to fgets
so that we can read bytes to buf
again:
1 | 0x80496d1 <tryme+ 7>: call 0x8049100 <__x86.get_pc_thunk.bx> |
fgets(ebp-0xc,0x19,stdin);
stack pivot
bof cause
ebp
was overwritten, so we should make sure that newebp
is an area of readable & writable memory (e.g..bss
section)
set ebp
to bss+0x200
and overwrite return address with 0x80496d1
(call fgets
):
1 | ebp = elf.bss()+0x200 |
after that, new address of buf
was in .bss
while calling fgets
again:
now we can puts ropchain
into new buf
to start rop attack
rop attack
set ebp
to buf-4
and execute gadget leave;ret
to entry ropchain
:
1 | # rop1 |
this ropchain
can leak address of puts
in libc:
1 | puts = uu32(rc(4)) |
we can calc the base address of libc and then address of other function in libc:
1 | libcbase = puts-libc.sym['puts'] |
we back to main
after the first rop attack, so stack pivot again and execute the second ropchain
1 | # stack pivot |
set
ebp
tobss+0x800
becausesystem()
need more area of stack
More
you can download full exp from my github