今天西湖论剑比赛,但是今天要去学校所以一上午就在火车上度过,下午4点才去看了看题,也只看了一道题。就和队伍小伙伴讨论(yu22x师傅和atao师傅)出来的,但是自己环境错了(应该是封了我ip),在最后换了手机wifi的才提交了flag。真的太刺激啦
唯一遗憾就是今天开学坐火车没有太多时间做题,大部分是m3w师傅和呆呆师傅做的。
一. 源代码
<?php
include 'security.php';
if(!isset($_GET['source'])){
show_source(__FILE__);
die();
}
$sandbox = 'sandbox/'.sha1($_SERVER['HTTP_X_FORWARDED_FOR']).'/';//设置沙盒根据自己ip获得目录
var_dump($sandbox);
if(!file_exists($sandbox)){//如果不存在就创建
mkdir($sandbox);
file_put_contents($sandbox."index.php","<?php echo 'Welcome To Dbapp OSS.';?>");
}
$action = $_GET['action'];
$content = file_get_contents("php://input");//获得post数据流
if($action == "write" && SecurityCheck('filename',$_GET['filename']) &&SecurityCheck('content',$content)){//验证函数
$content = json_decode($content);//json格式解密
$filename = $_GET['filename'];
$filecontent = $content->content;//获得content变量的值
$filename = $sandbox.$filename;
file_put_contents($filename,$filecontent."\n Powered By Dbapp OSS.");//写入文件,利用点
}elseif($action == "reset"){//删除操作
$files = scandir($sandbox);
foreach($files as $file) {
if(!is_dir($file)){
if($file !== "index.php"){
unlink($sandbox.$file);
}
}
}
}
else{
die('Security Check Failed.');
}
二. 思路
代码比较简单,意思就是我们访问的时候会生成一个沙盒目录,然后我们通过json格式写入文件进行利用
在自己之前测试的过程,是自己将json格式进行url编码,但是羽师傅告诉我说这样不会进行解析,之后在本地测试了一下确实不能进行解析。
#test.php
<?php
error_reporting(0);
highlight_file(__FILE__);
$content = file_get_contents('php://input');
// $content = '{"content":"1"}';
$content = json_decode($content);
$filecontent = $content->content;
print_r($filecontent);
?>
之后和羽师傅讨论,因为题目叫easyjson,所以SecurityCheck()函数里面应该是对json格式的验证,自己fuzz了一下发现对content
这个变量进行了过滤。并且filename这个参数可以后缀名是.php
而且不能的数字
所以考点就是绕过json格式
三. json格式绕过
浅谈json参数解析对waf绕过的影响
经过测试,发现unicode编码可以绕过
unicode转换工具
在本地测试成功
四. getshell
接下来思路就清晰啦,我们直接写入一个php进行getshell。
这里我们为了保险起见
写入一句
<?='ls /`;?>
然后访问沙盒目录下的a.php
执行成功,然后就读flag。这里使用*来替代flag,因为flag被过滤啦
五. 总结
最后羽师傅copy下了security.php
,我们就可以分析一下过滤了那些
<?php
function SecurityCheck($type,$content){
switch ($type){
case 'filename'://文件名匹配字母,没有验证后缀名
if(preg_match("/[^a-z\.]/", $content) !== 0) {
return false;
}
return true;
break;
case 'content'://过滤了on html flag file php upload type
if(stristr($content,'on') || stristr($content,'html') || stristr($content,'type') || stristr($content,'flag') || stristr($content,'upload') || stristr($content,'file') || stristr($content,'php') || stristr($content,'.')) {
return false;
}
return true;
break;
}
}// Powered By Dbapp OSS
最后的最后,和羽师傅笑谈,可能羽师傅感觉太简单啦~