SpringBoot Actuator未授權(quán)訪問漏洞的排查和解決方法
1. 介紹
Spring Boot Actuator 是一個(gè)用于監(jiān)控和管理 Spring Boot 應(yīng)用程序的功能模塊。它提供了一系列生產(chǎn)就緒的功能,幫助你了解應(yīng)用程序的運(yùn)行狀況,以及在運(yùn)行時(shí)對(duì)應(yīng)用程序進(jìn)行調(diào)整。Actuator 使用了 Spring MVC 來暴露各種 HTTP 或 JMX 端點(diǎn),通過這些端點(diǎn)你可以獲取到應(yīng)用程序的運(yùn)行信息,如健康狀態(tài)、指標(biāo)、線程 dump、環(huán)境變量等。
Spring Boot Actuator 的主要特性包括:
- 健康檢查:可以檢查應(yīng)用程序的運(yùn)行狀況,包括數(shù)據(jù)庫連接、磁盤空間、服務(wù)狀態(tài)等。
- 指標(biāo)收集:收集應(yīng)用程序的性能指標(biāo),如內(nèi)存使用情況、處理器使用情況、HTTP 請(qǐng)求計(jì)數(shù)等。
- HTTP 端點(diǎn):暴露了一系列的 HTTP 端點(diǎn),通過這些端點(diǎn)可以訪問應(yīng)用程序的運(yùn)行信息。
- 日志管理:可以動(dòng)態(tài)地修改應(yīng)用程序的日志級(jí)別。
- 跟蹤和應(yīng)用信息:提供了對(duì)應(yīng)用程序的跟蹤信息和應(yīng)用信息的訪問。
- 線程轉(zhuǎn)儲(chǔ):可以獲取應(yīng)用程序的線程轉(zhuǎn)儲(chǔ)信息,幫助診斷性能問題。
- 環(huán)境信息:可以查看應(yīng)用程序的配置屬性和環(huán)境變量。
- 映射信息:可以查看 Spring MVC 的映射信息。
- 審計(jì)事件:可以訪問應(yīng)用程序的審計(jì)事件信息。
要啟用 Spring Boot Actuator,你需要在項(xiàng)目中包含相應(yīng)的依賴,然后在配置文件中配置相關(guān)的屬性。Spring Boot 2.x 版本中,Actuator 的默認(rèn)端點(diǎn)是通過 HTTP 公開的,但是出于安全考慮,除了/health和/info端點(diǎn)之外,其他端點(diǎn)默認(rèn)是不對(duì)外暴露的。你可以通過配置文件來開啟這些端點(diǎn),并設(shè)置是否需要認(rèn)證訪問。
Spring Boot Actuator 是開發(fā)
2. 問題描述
<!-- SpringBoot Actuator -->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
當(dāng)我們的項(xiàng)目只是引入了 actuator 模塊時(shí),默認(rèn)只公開了幾個(gè)接口,如:
訪問http://localhost:9200/actuator

有些情況下,我們需要將服務(wù)的健康信息上報(bào)給安全監(jiān)控服務(wù),則需要將接口打開
# 暴露監(jiān)控端點(diǎn)
management:
endpoints:
web:
exposure:
include: '*'
此時(shí),再次訪問http://localhost:9200/actuator

也可以訪問具體的屬性http://localhost:9200/actuator/env

我們發(fā)現(xiàn)這個(gè)時(shí)候就會(huì)暴露很多服務(wù)信息,安全性得不到保證。
3. 解決方案
3.1 springboot1.x
3.1.1 禁用所有端口
#關(guān)閉全部接口 endpoints.enabled = false ###只開啟某些接口 #endpoints.beans.enabled = true #endpoints.env.enabled = true #endpoints.trace.enabled = true #endpoints.metrics.enabled = true
3.1.2 安全框架控制
引入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
配置輸入賬號(hào)密碼驗(yàn)證后才允許訪問
management.security.enabled=true security.user.name=admin security.user.password=admin
3.2 springboot2.x
3.2.1 禁用所有端口
management.endpoints.enabled-by-default: false
3.2.2 安全框架控制
引入依賴
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
配置輸入賬號(hào)密碼驗(yàn)證后才允許訪問
spring.security.user.name=actuator spring.security.user.password=actuator
添加配置類
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
/**
* Actuator 監(jiān)控端點(diǎn)權(quán)限
*
*/
@Configuration
public class ActuatorSecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity http) throws Exception {
http.httpBasic().and()
.authorizeRequests()
.antMatchers("/actuator/**")
.authenticated()
.anyRequest()
.permitAll();
http
// 關(guān)閉csrf token認(rèn)證不需要csrf防護(hù)
.csrf().disable()
// 關(guān)閉Session會(huì)話管理器 JWT 不需要
.sessionManagement().disable()
// 關(guān)閉記住我功能 JWT 不需要
.rememberMe().disable();
}
}
4.總結(jié)
以上就是SpringBoot Actuator未授權(quán)訪問漏洞的排查和解決方法的詳細(xì)內(nèi)容,更多關(guān)于SpringBoot Actuator訪問漏洞的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
- SpringBoot應(yīng)用監(jiān)控Actuator使用隱患及解決方案
- SpringBoot+actuator和admin-UI實(shí)現(xiàn)監(jiān)控中心方式
- Spring Boot Actuator未授權(quán)訪問漏洞的問題解決
- SpringBoot中的Actuator詳解
- SpringBoot Actuator未授權(quán)訪問漏洞解決方案
- 關(guān)于SpringBoot Actuator漏洞補(bǔ)救方案
- SpringBoot監(jiān)控模塊Actuator的用法詳解
- SpringBoot Actuator未授權(quán)訪問漏洞修復(fù)詳解
- Spring Boot Actuator入門指南
相關(guān)文章
SpringBoot實(shí)現(xiàn)ORM操作MySQL的幾種方法
本文主要介紹了SpringBoot實(shí)現(xiàn)ORM操作MySQL的幾種方法,文中通過示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-02-02
詳解Java的call by value和call by reference
在本篇文章里小編給大家總結(jié)了關(guān)于Java的call by value和call by reference的相關(guān)用法和知識(shí)點(diǎn)內(nèi)容,需要的朋友們學(xué)習(xí)下。2019-03-03
Spring Cloud微服務(wù)使用webSocket的方法
WebSocket在現(xiàn)代瀏覽器中的應(yīng)用已經(jīng)算是比較普遍了,在某些業(yè)務(wù)場(chǎng)景下,要求必須能夠在服務(wù)器端推送消息至客戶端,本文給大家介紹Spring Cloud微服務(wù)使用webSocket的方法,感興趣的朋友一起看看吧2021-06-06
Spring Boot實(shí)現(xiàn)自動(dòng)發(fā)送郵件
這篇文章主要為大家詳細(xì)介紹了Spring Boot實(shí)現(xiàn)自動(dòng)發(fā)送郵件,文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2020-02-02
Java實(shí)現(xiàn)定時(shí)任務(wù)的示例代碼
這篇文章主要為大家詳細(xì)介紹了Java實(shí)現(xiàn)定時(shí)任務(wù)的相關(guān)知識(shí),文中示例代碼介紹的非常詳細(xì),具有一定的參考價(jià)值,感興趣的小伙伴們可以參考一下2022-11-11

