14
Thinkphp6.0 任意文件写入漏洞
source link: https://www.smi1e.top/thinkphp6-0-%e4%bb%bb%e6%84%8f%e6%96%87%e4%bb%b6%e5%86%99%e5%85%a5%e6%bc%8f%e6%b4%9e/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
寒假天天在家干活的我,好多天没学习了,趁着有空水一篇看起来不是很复杂的洞。
漏洞介绍
2020年1月10日,ThinkPHP团队发布一个补丁更新,修复了一处由不安全的 SessionId
导致的任意文件操作漏洞。该漏洞允许攻击者在目标环境启用 session
的条件下创建任意文件以及删除任意文件。
具体受影响版本为 ThinkPHP6.0.0-6.0.1
。
回溯写入 Session
时的 $filename
vendor/topthink/framework/src/think/session/driver/File.php
$sessID
对应文件名拼接变量 $name
,看一下 $sessID
参数怎么来的
vendor/topthink/framework/src/think/session/Store.php
$name
为 $this->id
值,与 setID($id=null)
对应,而当 $id
参数的长度等于32位时,直接返回 $id
,不进行md5操作。
根据源码可知 $id
从cookie中的 PHPSESSID
变量中获取。vendor/topthink/framework/src/think/middleware/SessionInit.php
因此我们构造 PHPSESSID=aaaaaaaaaaaaaaaaaaaaaaaaaaab.php
即可成功写入文件,不过想要控制文件内容的话还需要控制储存的 session
变量键名或者键值,在实际情况下应该是比较容易的。
而原文中提到的可以删除任意文件,首先需要 $this->data
为空,也就是session设置的变量键值等于空,或者其他为空的操作,貌似在实际场景中并不常见
另外文件名并不完全可控,有一个 sess_
前缀,只有在windows下才可以用一个不存在的目录绕过限制删除任意文件。
Referer
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK