文章转载于https://blog.zgsec.cn/index.php/archives/129/

一、Spring Boot概述

Spring Boot 是由Pivotal团队提供的全新框架,其设计目的是用来简化 Spring 应用的创建、运行、调试、部署等。使用 Spring Boot 可以做到专注于 Spring 应用的开发,而无需过多关注 XML 的配置。Spring Boot 使用“习惯优于配置”的理念,简单来说,它提供了一堆依赖打包,并已经按照使用习惯解决了依赖问题。使用 Spring Boot 可以不用或者只需要很少的 Spring 配置就可以让企业项目快速运行起来。

1675135738206-078eda2b-c351-4a65-9f69-1b21c1740169

Spring Boot 是开发者和 Spring 本身框架的中间层,帮助开发者统筹管理应用的配置,提供基于实际开发中常见配置的默认处理(即习惯优于配置),简化应用的开发,简化应用的运维;总的来说,其目的 Spring Boot 就是为了对 Java web 的开发进行“简化”和加“快”速度,简化开发过程中引入或启动相关 Spring 功能的配置。这样带来的好处就是降低开发人员对于框架的关注点,可以把更多的精力放在自己的业务代码上。

二、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 在带来方便的同时,如果没有管理好,会导致一些敏感的信息泄露;可能会导致我们的服务器,被暴露到外网,服务器可能会沦陷。

三、Spring Boot框架的识别

1、通过icon图标进行识别

Fofa语法

icon_hash="116323821"

1675135857553-5a39b72d-1592-4b37-a375-dce1f42b15d4

可以搜索到25万条左右的资产数据,说明Spring Boot框架是应用广泛哈哈~(其中还有很多服务更改了默认的ico图标,所以这个语法找不到)

2、通过网页内容进行识别

哈哈,这个更夸张了,可以搜索到141万条左右的资产数据

1675135914759-cb890a37-3046-473d-82d5-3935e207cedf

以下是 Spring Boot 框架的典型特征:

1675135940764-db1bcd1e-499f-4970-ae59-fa8c2af97b44

所以可以通过Fofa对网页的body内容进行搜索找到那么多的资产

3、Spring Boot框架 敏感信息泄露

如果对 Spring Boot 框架熟悉的师傅,肯定知道对 Spring Boot 的渗透测试过程中,肯定不会少了敏感信息泄露和未授权访问相关的漏洞

不同版本分类讨论

  • Spring Boot < 1.5:默认未授权访问所有端点
  • Spring Boot >= 1.5:默认只允许访问 /health 和 /info 端点,但是此安全性通常被应用程序开发人员禁用了

(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信息

(2)独家字典

于是,我这里独家整理了一份信息泄露字典(欢迎补充哈哈)

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)端点的敏感信息泄露样例

这里先安利一款谷歌浏览器插件哈,名字叫 JSON Viewer ,可以美化JSON的相关页面

1675136177482-fe62e473-bd73-4fa9-b34b-1bca36787b75

a、访问/actuator

如果设置了 management.endpoints.web.exposure.include*,就可以在 /actuator 看到所有存在的端点,截图如下:

1675136309219-254022e0-8376-4e0d-89f0-cef6c790315b

b、访问/actuator/version

会泄露一些相关的版本信息

但这个目前很少有泄露了,一时半会没找到实例

c、访问/env或者/actuator/env

可能会泄露数据库账号密码等敏感信息

1675136404362-3909b49a-e0ce-4a52-b3e2-067a63ce7ccb

针对env这种路径下泄露的密码会用星号进行脱敏,想要获取相应的明文密码,可以尝试通过分析heapdump数据的方式

d、访问/actuator/metrics

获得每个度量的名称,其中主要监控了JVM内容使用、GC情况、类加载信息等

1675136452416-b98e0c53-9701-4577-bb2c-c1844e948680

如果想要得到每个度量的详细信息,需要传递度量的名称到URL中,如下

http://xx.xx.xx.xx/actuator/metrics/http.server.requests

1675136481497-d7252c69-9641-4cb8-b213-74613745832f

e、访问/actuator/threaddump

获取服务器的线程堆栈信息

1675136509575-02f0baa7-b1b9-4bcc-b0bc-8681830e4cec

f、访问/actuator/loggers

获取服务器的日志级别

1675136535590-8acb63fa-60fd-4e35-a506-93cc91c6de86

g、访问/actuator/configprops

查看配置文件中设置的属性内容,以及一些配置属性的默认值

1675136559967-cddad54e-83d0-40b8-9d44-ec29c7ce2792

h、访问/actuator/info

展示了关于应用的一般信息,这些信息从编译文件比如 META-INF/build-info.properties 或者 git 文件比如 git.properties 或者任何环境的 property 中获取

i、访问/actuator/mappings

响应信息描述全部的URI路径,以及它们和控制器的映射关系

1675136637560-fe86ec55-713a-40e6-8ff0-58c692b3f2ae

j、访问/actuator/health

health一般只展示了简单的UP和DOWN状态,比如这样:

1675144005203-33c90cfe-436d-4635-a55c-b24179ff347a

为了获得健康检查中所有指标的详细信息,就需要通过在 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
}
}

k、访问/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

1675143866116-4bab374b-edb8-4850-afa6-77f3efbc5ae1

下载完成之后可以借助一些工具对其中的数据进行内容检索,寻找敏感信息

四、SpringBoot-Scan的使用

日常渗透过程中,经常会碰到Spring Boot搭建的微服务,于是就想做一个针对Spring Boot的开源渗透框架

主要用作扫描SpringBoot的敏感信息泄露端点,并可以直接测试Spring Boot的相关高危漏洞。

1675143941246-d2b554fb-043c-4948-9d89-536778c8e242

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

五、参考链接