西湖论剑 web 5 easyjson

3 篇文章 0 订阅

今天西湖论剑比赛,但是今天要去学校所以一上午就在火车上度过,下午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

最后的最后,和羽师傅笑谈,可能羽师傅感觉太简单啦~
在这里插入图片描述

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 8
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 8
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值