[Triple Happiness!] Learning House of Storm & SROP & ORW from one challenge
Actually I don’t want to write this article in English, but I have written half of it in English before…
rctf2019_babyheap binary
1 | [*] '/home/giantbranch/Desktop/rctf_2019_babyheap/rctf_2019_babyheap' |
Reverse Analysis
init()
mallopt(1, 0)
fastbin is banned.
alarm(0x3Cu)
alarm is annoying while debugging, sed -i s/alarm/isnan/g ./ProgrammName
replace it with isnan().
prctl()
sandbox enabled, forcing us to orw.
1 | line CODE JT JF K |
add()
Program used calloc() instead of malloc(), making it impossible to hijack malloc_hook.
limit of chunk size is 0x100. We can have 16 chunks at most.
struct is simpe ptr|size
edit()
ptrs.ptr + read_n(ptrs.ptr, ptrs.size) = 0
Off by null existed.
we can hijack pre_inuse bit to trigger unlink.
LEAK
unlink –> chunk overlap –> unsortedbin leak
1 | $ ./main_arena /lib/x86_64-linux-gnu/libc-2.23.so |
1 | #LEAK |
House of Storm
This chall remind me of another chall: 0ctf_2018_heapstorm2. Both of them ban the fastbin and use calloc
. We can use house of storm
to hijack free_hook
.
1 | #---------------------------------HOUSE OF STORM------------------------# |
Now, we can control __free_hook
by chunk 6.
SROP
However, execve is banned. We can use SROP to ORW.
The key to SROP is setcontext
, this function can control registers(even the rip), we can hijack __free_hook
to setcontext
. Once we set the chunk well, we can control the programme by free the chunk.
Here, we use mprotect
to set the chunk executable.
1 | #-----------------------------SROP------------------------------# |
ORW
Given that we have set the chunk executable, we can inject our shellcode to orw
1 | #------------------------ORW-------------------------------# |
懒得写异常处理了,多试几次也能拿到flag。