對於Spring Boot的滲透姿勢

h1ck0r發表於2024-07-20

0# Spring Boot概述
Spring Boot 是由Pivotal團隊提供的全新框架,其設計目的是用來簡化 Spring 應用的建立、執行、除錯、部署等。使用 Spring Boot 可以做到專注於 Spring 應用的開發,而無需過多關注 XML 的配置。Spring Boot 使用“習慣優於配置”的理念,簡單來說,它提供了一堆依賴打包,並已經按照使用習慣解決了依賴問題。使用 Spring Boot 可以不用或者只需要很少的 Spring 配置就可以讓企業專案快速執行起來。

springboot-title.png

Spring Boot 是開發者和 Spring 本身框架的中間層,幫助開發者統籌管理應用的配置,提供基於實際開發中常見配置的預設處理(即習慣優於配置),簡化應用的開發,簡化應用的運維;總的來說,其目的 Spring Boot 就是為了對 Java web 的開發進行“簡化”和加“快”速度,簡化開發過程中引入或啟動相關 Spring 功能的配置。這樣帶來的好處就是降低開發人員對於框架的關注點,可以把更多的精力放在自己的業務程式碼上。

1# Spring Boot Actuator概述
Actuator 是 Spring Boot 提供的用來對應用系統進行自省和監控的功能模組,藉助於 Actuator 開發者可以很方便地對應用系統某些監控指標進行檢視、統計等。

Actuator 的核心是端點 Endpoint,它用來監視應用程式及互動,spring-boot-actuator 中已經內建了非常多的 Endpoint(health、info、beans、metrics、httptrace、shutdown等等),同時也允許我們自己擴充套件自己的 Endpoints。每個 Endpoint 都可以啟用和禁用。要遠端訪問 Endpoint,還必須透過 JMX 或 HTTP 進行暴露,大部分應用選擇HTTP。

Actuator 在帶來方便的同時,如果沒有管理好,會導致一些敏感的資訊洩露;可能會導致我們的伺服器,被暴露到外網,伺服器可能會淪陷。

2# Spring Boot框架的識別
2.1 透過icon圖示進行識別
Fofa語法如下:

icon_hash="116323821"
Fofa語法搜尋icon.png

可以搜尋到25萬條左右的資產資料,說明Spring Boot框架是應用廣泛哈哈~
(其中還有很多服務更改了預設的ico圖示,所以這個語法找不到)

2.2 透過網頁內容進行識別
Fofa語法如下:

body="Whitelabel Error Page"
Fofa語法搜尋body.png

哈哈,這個更誇張了,可以搜尋到141萬條左右的資產資料
以下是 Spring Boot 框架的典型特徵:

SpringBoot典型特徵.png

所以可以透過Fofa對網頁的body內容進行搜尋找到那麼多的資產

3# Spring Boot框架 敏感資訊洩露
如果對 Spring Boot 框架熟悉的師傅,肯定知道對 Spring Boot 的滲透測試過程中,肯定不會少了敏感資訊洩露和未授權訪問相關的漏洞

不同版本分類討論
Spring Boot < 1.5:預設未授權訪問所有端點、
Spring Boot >= 1.5:預設只允許訪問 /health 和 /info 端點,但是此安全性通常被應用程式開發人員禁用了
3.1 常見端點及其作用:
路徑 是否預設啟用 功能描述
/auditevents 是 顯示當前應用程式的審計事件資訊
/beans 是 顯示一個應用中所有Spring Beans的完整列表
/conditions 是 顯示配置類和自動配置類的狀態及它們被應用或未被應用的原因
/configprops 是 顯示一個所有@ConfigurationProperties的集合列表
/env 是 顯示來自Spring的 ConfigurableEnvironment的屬性
/flyway 是 顯示資料庫遷移路徑(如果存在)
/health 是 顯示應用的健康資訊(當使用一個未認證連線訪問時顯示一個簡單的’status’,使用認證連線訪問則顯示全部資訊詳情)
/info 是 顯示任意的應用資訊
/liquibase 是 展示任何Liquibase資料庫遷移路徑(如果存在)
/metrics 是 展示當前應用的metrics資訊
/mappings 是 顯示一個所有@RequestMapping路徑的集合列表
/scheduledtasks 是 顯示應用程式中的計劃任務
/sessions 否 允許從Spring會話支援的會話儲存中檢索和刪除使用者會話
/shutdown 否 允許應用以優雅的方式關閉(預設情況下不啟用)
/threaddump 是 執行一個執行緒dump
/heapdump 是 返回一個GZip壓縮的hprof堆dump檔案
/jolokia 是 透過HTTP暴露JMX beans(當Jolokia在類路徑上時,WebFlux不可用)
/logfile 是 返回日誌檔案內容(如果設定了logging.file或logging.path屬性的話),支援使用HTTP Range頭接收日誌檔案內容的部分資訊
/prometheus 是 以可以被Prometheus伺服器抓取的格式顯示metrics資訊
獨家字典
於是,我這裡獨家整理了一份資訊洩露字典(歡迎補充哈哈)

actuator
actuator/auditLog
actuator/auditevents
actuator/autoconfig
actuator/beans
actuator/caches
actuator/conditions
actuator/configurationMetadata
actuator/configprops
actuator/dump
actuator/env
actuator/events
actuator/exportRegisteredServices
actuator/features
actuator/flyway
actuator/health
actuator/heapdump
actuator/healthcheck
actuator/heapdump
actuator/httptrace
actuator/hystrix.stream
actuator/info
actuator/integrationgraph
actuator/jolokia
actuator/logfile
actuator/loggers
actuator/loggingConfig
actuator/liquibase
actuator/metrics
actuator/mappings
actuator/scheduledtasks
actuator/swagger-ui.html
actuator/prometheus
actuator/refresh
actuator/registeredServices
actuator/releaseAttributes
actuator/resolveAttributes
actuator/scheduledtasks
actuator/sessions
actuator/springWebflow
actuator/shutdown
actuator/sso
actuator/ssoSessions
actuator/statistics
actuator/status
actuator/threaddump
actuator/trace
auditevents
autoconfig
api.html
api/index.html
api/swagger-ui.html
api/v2/api-docs
api-docs
beans
caches
cloudfoundryapplication
conditions
configprops
distv2/index.html
docs
druid/index.html
druid/login.html
druid/websession.html
dubbo-provider/distv2/index.html
dump
entity/all
env
env/(name)
eureka
flyway
gateway/actuator
gateway/actuator/auditevents
gateway/actuator/beans
gateway/actuator/conditions
gateway/actuator/configprops
gateway/actuator/env
gateway/actuator/health
gateway/actuator/heapdump
gateway/actuator/httptrace
gateway/actuator/hystrix.stream
gateway/actuator/info
gateway/actuator/jolokia
gateway/actuator/logfile
gateway/actuator/loggers
gateway/actuator/mappings
gateway/actuator/metrics
gateway/actuator/scheduledtasks
gateway/actuator/swagger-ui.html
gateway/actuator/threaddump
gateway/actuator/trace
health
heapdump
heapdump.json
httptrace
hystrix
hystrix.stream
info
integrationgraph
jolokia
jolokia/list
liquibase
list
logfile
loggers
liquibase
metrics
mappings
monitor
prometheus
refresh
scheduledtasks
sessions
shutdown
spring-security-oauth-resource/swagger-ui.html
spring-security-rest/api/swagger-ui.html
static/swagger.json
sw/swagger-ui.html
swagger
swagger/codes
swagger/index.html
swagger/static/index.html
swagger/swagger-ui.html
swagger-dubbo/api-docs
swagger-ui
swagger-ui.html
swagger-ui/html
swagger-ui/index.html
system/druid/index.html
threaddump
template/swagger-ui.html
trace
user/swagger-ui.html
version
v1.1/swagger-ui.html
v1.2/swagger-ui.html
v1.3/swagger-ui.html
v1.4/swagger-ui.html
v1.5/swagger-ui.html
v1.6/swagger-ui.html
v1.7/swagger-ui.html
/v1.8/swagger-ui.html
/v1.9/swagger-ui.html
/v2.0/swagger-ui.html
v2.1/swagger-ui.html
v2.2/swagger-ui.html
v2.3/swagger-ui.html
v2/swagger.json
webpage/system/druid/index.html
%20/swagger-ui.html
3.2 端點的敏感資訊洩露樣例
這裡先安利一款谷歌瀏覽器外掛哈,名字叫 JSON Viewer ,可以美化JSON的相關頁面

JSON-Viewer.png

注意,以下測試均是在Fofa上找的例項,漏洞其實離我們並不遙遠
3.2.1 訪問/actuator
如果設定了 management.endpoints.web.exposure.include 為 *,就可以在 /actuator 看到所有存在的端點,截圖如下:

訪問actuator.png

3.2.2 訪問/actuator/version
會洩露一些相關的版本資訊
但這個目前很少有洩露了,一時半會沒找到例項

3.2.3 訪問/env或者/actuator/env
可能會洩露資料庫賬號密碼等敏感資訊

訪問actuator-env.png

針對env這種路徑下洩露的密碼會用星號進行脫敏,想要獲取相應的明文密碼,可以嘗試透過分析heapdump資料的方式

3.2.4 訪問/actuator/metrics
獲得每個度量的名稱,其中主要監控了JVM內容使用、GC情況、類載入資訊等

訪問actuator-metrics.png

如果想要得到每個度量的詳細資訊,需要傳遞度量的名稱到URL中,如下

http://xx.xx.xx.xx/actuator/metrics/http.server.requests
訪問actuator-metrics-http.server.requests.png

3.2.5 訪問/actuator/threaddump
獲取伺服器的執行緒堆疊資訊

訪問actuator-threaddump.png

3.2.6 訪問/actuator/loggers
獲取伺服器的日誌級別

訪問actuator-loggers.png

3.2.7 訪問/actuator/configprops
檢視配置檔案中設定的屬性內容,以及一些配置屬性的預設值

訪問actuator-configprops.png

3.2.8 訪問/actuator/info
展示了關於應用的一般資訊,這些資訊從編譯檔案比如 META-INF/build-info.properties 或者 git 檔案比如 git.properties 或者任何環境的 property 中獲取

3.2.9 訪問/actuator/mappings
響應資訊描述全部的URI路徑,以及它們和控制器的對映關係

訪問actuator-mappings.png

3.2.10 訪問/actuator/health
health一般只展示了簡單的UP和DOWN狀態,比如這樣:

訪問actuator-health.png

為了獲得健康檢查中所有指標的詳細資訊,就需要透過在 application.yaml 中增加如下內容:

management:
endpoint:
health:
show-details: always
一旦開啟上述開關,那麼在 /health 中可以看到詳細內容,比如下面這樣

{
"status": "UP",
"diskSpace": {
"status": "UP",
"total": 209715195904,
"free": 183253909504,
"threshold": 10485760
}
"db": {
"status": "UP",
"database": "MySQL",
"hello": 1
}
}
3.2.11 訪問/heapdump或者/actuator/heapdump
Heap Dump也叫堆轉儲檔案,是一個Java程序在某個時間點上的記憶體快照
Heap Dump是有著多種型別的,不過總體上heap dump在觸發快照的時候都儲存了java物件和類的資訊

通常在寫heap dump檔案前會觸發一次FullGC,所以heap dump檔案中儲存的是FullGC後留下的物件資訊。其中可能會含有敏感資料,如資料庫的密碼明文等

直接訪問路徑會返回一個GZip壓縮的JVM堆dump,其中是jvm heap資訊。下載的heapdump檔案大小通常在 50M—500M 之間,有時候也可能會大於 2G

訪問actuator-threaddump.png

下載完成之後可以藉助一些工具對其中的資料進行內容檢索,尋找敏感資訊

Eclipse Memory Analyzer(MAT)
heapdump_tool
JDumpSpider
都有參考文章,可以自行研究

4# SpringBoot-Scan的使用
日常滲透過程中,經常會碰到Spring Boot搭建的微服務,於是就想做一個針對Spring Boot的開源滲透框架

主要用作掃描SpringBoot的敏感資訊洩露端點,並可以直接測試Spring Boot的相關高危漏洞。

SpringBoot-Scan截圖title.png

於是,就寫了這麼一個工具:SpringBoot-Scan 【簡稱:“SB-Scan”(錯亂】

開源地址:https://github.com/AabyssZG/SpringBoot-Scan

掃描單一URL.png

感覺不錯的話,麻煩師傅點個Star啦~
有問題的話,也可以提交issues或者私聊我都行哈哈~

5# 參考連結
https://blog.csdn.net/u012206617/article/details/109010102
https://blog.csdn.net/m0_64867220/article/details/121728868
https://www.freebuf.com/vuls/289710.html

相關文章