[GYCTF2020]EasyThinking


thinkphp框架,先報錯,查看版本

thinkphp6.0版本,經查閱,存在任意文件寫入
先注冊一個賬戶,登錄時將cookie修改成aaaaaaaaaaaaaaaaaaaaaaaaaaaa.php,一共32位

在搜索處可寫入webshell

訪問runtime/session/sess_aaaaaaaaaaaaaaaaaaaaaaaaaaaa.php

可以看到disable_functions過濾了很多函數

應該是要繞過disable_functions
先用蟻劍連接,這里我換了一下cookie,用來寫一句話木馬
可以看到本地有readflag,應該是通過readflag讀取flag

下載一波繞過的exp,https://github.com/mm0r1/exploits
使用php7-gc-bypass的exploit,修改一下

將exploit上傳到/var/tmp目錄下
最后包含一下即可讀取flag
<?php include('/var/tmp/exploit.php');?>

做完題后的分析
先來確定寫入文件的操作web\vendor\topthink\framework\src\think\session\Store.php

有一個write函數,跟進
來到\vendor\topthink\framework\src\think\session\driver\File.php

有一個writeFile函數,跟進

看到file_put_contents()函數,可以確定,webshell在此處寫入
往回看,查找filename的來源
Score.php->save()->write($sessionId, $data)->File.php->writeFile($filename, $data)->file_put_contents($path, $content, LOCK_EX)
可知filename來自$sessionId

有getId()就應該有setId()

可以看到,id只要滿足32位即可,也就是說,aaaaaaaaaaaaaaaaaaaaaaaaaaaa.php這種形式也行
找到調用setId()的地方
\vendor\topthink\framework\src\think\middleware\SessionInit.php

看到getName()


即sessionId的值來自cookie中的PHPSESSID,也就是說,webshell的filename來自PHPSESSID,且要滿足長度為32位

file_put_contents($path, $content, LOCK_EX),查找content的值來源

Score.php->save()

看一下data

data是一個數組
從前台找一下輸入
\app\home\controller\Member.php

data應該是跟這個key有關
這應該就是webshell的寫入位置了

水平有限,只能分析到這里了
參考
ThinkPHP6 任意文件操作漏洞分析
https://c0okb.github.io/2020/02/26/GYCTF2020/#GYCTF2020-EasyThinking


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM