SSRF漏洞

SSRF漏洞

SSRF(Server-Site Request Forery)服务端请求伪造

形成原因

服务端提供了从其他服务器获取数据的功能,但没有对内网目标地址做过滤和限制。

容易出现的地方:将url请求作为参数请求资源时发生,分享、下载图片、从别的服务器请求资源等

主要利用方式

1.对外网、服务器所在的内网进行端口扫描,获取一些banner信息

2.测试运行内网或本地的应用程序

3.利用file协议读取本地文件等

curl -v 'file:///etc/passwd'

4.用dict探测端口

curl -v 'dict://127.0.0.1:22'

5.用gopher反弹shell

相关危险函数

curl_exec()
function curl($url){

  				 $ch = curl_init();                //curl_init()返回一个curl句柄

​				curl_setopt($ch, CURLOPT_URL, $url);     
		//需要获取的URL地址,也可以在curl_init()函数中设置。

 				  curl_setopt($ch, CURLOPT_HEADER, 0);   //启用时会将头文件的信息作为数据流输出。

 				 curl_exec($ch);   

​				curl_close($ch);

 }

 $url = $_GET['url'];

 curl($url);
file_get_content()
if(isset($_GET['file']) && $_GET['file'] !=null){

    $filename = $_GET['file'];
    
    $str = file_get_contents($filename);
    
    echo $str;
}
fsockopen()

这个函数会使用socket跟服务器建立tcp连接,传输原始数据。

<?php
$host=$_GET['url'];

$fp = fsockopen("$host", 80, $errno, $errstr, 30);

if (!$fp) {

    echo "$errstr ($errno)<br />\n";
   
} else {
    $out = "GET / HTTP/1.1\r\n";
    $out .= "Host: $host\r\n";
    $out .= "Connection: Close\r\n\r\n";
    fwrite($fp, $out);
    while (!feof($fp)) {
        echo fgets($fp, 128);
    }
    fclose($fp);
}
?>

关于curl

curl 是常用的命令行工具,用来请求 Web 服务器。它的名字就是客户端(client)的 URL 工具的意思。

所支持的协议

image-20200929181015044

正常请求

向服务器发出get请求,返回服务器内容

chenjiaze@kali:~$ curl www.baidu.com
-A 设置代理访问
$ curl -A 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/76.0.3809.100 Safari/537.36' https://google.com
-b 设置cookie访问
$ curl -b 'foo=bar' https://google.com
-c 将服务器设置的cookie写入一个文件
$ curl -c cookies.txt https://www.google.com
-d 发送POST请求
$ curl -d'login=emma&password=123'-X POST https://google.com/login
-e 设置Refer头
curl -e 'https://google.com?q=example' https://www.example.com
-g 构造一个url的查询字符串
$ curl -G -d 'q=kitties' -d 'count=20' https://google.com/search

实际请求的 URL 为https://google.com/search?q=kitties&count=20

-v 输出整个通信过程,用于调试
$ curl -v https://www.example.com

curl用法连接:https://www.ruanyifeng.com/blog/2019/09/curl-reference.html

posted @ 2021-07-10 15:38  cjz12138  阅读(74)  评论(0编辑  收藏  举报