[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

posted @ 2020-10-01 20:07  山野村夫z1  阅读(1155)  评论(0编辑  收藏  举报