原文URL: https://jenchoi.top/2025/springboot-actuator-unauthorized-access

Actuator介绍

Spring Boot Actuator 是一个用于监控和管理 Spring Boot 应用的库,提供了多种端点(endpoints)来查看应用的运行状态、健康检查、指标、日志等信息,适用于生产环境监控和故障排查。

主要功能:

  1. 健康检查(Health)/actuator/health 显示应用健康状态,如数据库、缓存等组件的可用性。
  2. 应用指标(Metrics)/actuator/metrics 提供 CPU、内存、GC、请求统计等信息。
  3. 环境信息(Env)/actuator/env 显示应用环境变量和配置属性。
  4. 日志管理(Loggers)/actuator/loggers 允许动态调整日志级别。
  5. 线程 Dump(Thread Dump)/actuator/threaddump 获取当前 JVM 线程信息。
  6. HTTP 请求追踪(HttpTrace)/actuator/httptrace 记录最近的 HTTP 请求信息。
    其他功能请参考官方文档: https://docs.spring.io/spring-boot/docs/2.0.x/actuator-api/html/

Actuator使用

pom.xml中添加Actuator依赖

1
2
3
4
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

Spring 3.x只要引入上述依赖,不需要在配置文件中做任何配置,默认可以访问

  • /actuator
  • /actuator/health

/actuator可以看到,当前可以访问哪些子页面,以下是默认的response

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
{
"_links": {
"self": {
"href": "http://localhost:8088/actuator",
"templated": false
},
"health": {
"href": "http://localhost:8088/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8088/actuator/health/{*path}",
"templated": true
}
}
}

现在再加一条配置重启,把其他的监控也暴露出去

1
management.endpoints.web.exposure.include=*

再访问/actuator,可以看到,现在能访问其他的了

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
{
"_links": {
"self": {
"href": "http://localhost:8088/actuator",
"templated": false
},
"beans": {
"href": "http://localhost:8088/actuator/beans",
"templated": false
},
"caches-cache": {
"href": "http://localhost:8088/actuator/caches/{cache}",
"templated": true
},
"caches": {
"href": "http://localhost:8088/actuator/caches",
"templated": false
},
"health": {
"href": "http://localhost:8088/actuator/health",
"templated": false
},
"health-path": {
"href": "http://localhost:8088/actuator/health/{*path}",
"templated": true
},
"info": {
"href": "http://localhost:8088/actuator/info",
"templated": false
},
"conditions": {
"href": "http://localhost:8088/actuator/conditions",
"templated": false
},
"configprops": {
"href": "http://localhost:8088/actuator/configprops",
"templated": false
},
"configprops-prefix": {
"href": "http://localhost:8088/actuator/configprops/{prefix}",
"templated": true
},
"env": {
"href": "http://localhost:8088/actuator/env",
"templated": false
},
"env-toMatch": {
"href": "http://localhost:8088/actuator/env/{toMatch}",
"templated": true
},
"loggers": {
"href": "http://localhost:8088/actuator/loggers",
"templated": false
},
"loggers-name": {
"href": "http://localhost:8088/actuator/loggers/{name}",
"templated": true
},
"heapdump": {
"href": "http://localhost:8088/actuator/heapdump",
"templated": false
},
"threaddump": {
"href": "http://localhost:8088/actuator/threaddump",
"templated": false
},
"metrics-requiredMetricName": {
"href": "http://localhost:8088/actuator/metrics/{requiredMetricName}",
"templated": true
},
"metrics": {
"href": "http://localhost:8088/actuator/metrics",
"templated": false
},
"sbom": {
"href": "http://localhost:8088/actuator/sbom",
"templated": false
},
"sbom-id": {
"href": "http://localhost:8088/actuator/sbom/{id}",
"templated": true
},
"scheduledtasks": {
"href": "http://localhost:8088/actuator/scheduledtasks",
"templated": false
},
"mappings": {
"href": "http://localhost:8088/actuator/mappings",
"templated": false
}
}
}

只激活部分端点,比如暴露 health 端点和 metrics 端点

1
management.endpoints.web.exposure.include=metrics,health

还有一个有意思的配置

1
management.endpoints.web.base-path=/jenchoi

简单理解这个配置会把/actuator替换成/jenchoi
比如原来访问 http://localhost:8088/actuator/mappings
配置了之后访问 http://localhost:8088/jenchoi/mappings

对于同样暴露在公网,并且开了危险端点的应用来说,在实际的漏洞防护上有那么一点点效果,至少可以防止工具无脑扫到/actuator目录。

漏洞成因

上面了解了Actuator的用法之后,那么此未授权访问漏洞的成因就非常容易理解了——开发人员开启了Actuator组件,没有做任何的鉴权措施。

修复方案

1、不开Actuator监控,移除pom文件中的依赖
虽然Actuator是Spring官方提供的工具,但也是需要开发者在pom中引用的,如果不需要,直接移除该依赖是最稳妥的方式。

2、关闭web访问

1
2
3
4
management.endpoints.access.default=none

# or(该方法为弃用方法)
management.endpoints.enabled-by-default=false

关闭之后,/actuator还是可以访问的,但是从response可以看出其他的是无法访问的

1
2
3
4
5
6
7
8
{
"_links": {
"self": {
"href": "http://localhost:8080/actuator",
"templated": false
}
}
}

审计思路

1、检查pom文件是否引入了spring-boot-starter-actuator依赖

2、检查配置文件中以management.endpoints相关的配置是否合理
注意:如果是yml配置文件,直接在配置文件里面搜endpoints关键词

参考链接

  1. Spring Boot 2 Actuator Web API Documentation
  2. Spring Boot 3 Actuator Web API Documentation
  3. 如何在idea中创建一个SpringBoot项目(超详细教学)idea创建springboot项目-CSDN博客
  4. 如何使用 Spring Boot Actuator 组件实现系统监控?- 掘金