Files
vulhub/spring/CVE-2018-1270/README.zh-cn.md
Aaron 63285f61aa
Some checks failed
Vulhub Format Check and Lint / format-check (push) Has been cancelled
Vulhub Format Check and Lint / markdown-check (push) Has been cancelled
Vulhub Docker Image CI / longtime-images-test (push) Has been cancelled
Vulhub Docker Image CI / images-test (push) Has been cancelled
first commit
2025-09-06 16:08:15 +08:00

51 lines
2.3 KiB
Markdown
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

# Spring Messaging 远程命令执行漏洞CVE-2018-1270
spring messaging为spring框架提供消息支持其上层协议是STOMP底层通信基于SockJS
在spring messaging中其允许客户端订阅消息并使用selector过滤消息。selector用SpEL表达式编写并使用`StandardEvaluationContext`解析,造成命令执行漏洞。
参考链接:
- https://pivotal.io/security/cve-2018-1270
- https://xz.aliyun.com/t/2252
- https://cert.360.cn/warning/detail?id=3efa573a1116c8e6eed3b47f78723f12
- https://github.com/CaledoniaProject/CVE-2018-1270
## 漏洞环境
执行如下命令启动一个基于Spring Messaging 5.0.4的Web应用
```
docker compose up -d
```
环境启动后,访问`http://your-ip:8080`即可看到一个Web页面。
## 漏洞复现
网上大部分文章都说spring messaging是基于websocket通信其实不然。spring messaging是基于sockjs可以理解为一个通信协议而sockjs适配多种浏览器现代浏览器中使用websocket通信老式浏览器中使用ajax通信。
连接后端服务器的流程,可以理解为:
1. 用[STOMP协议](http://jmesnil.net/stomp-websocket/doc/)将数据组合成一个文本流
2. 用[sockjs协议](https://github.com/sockjs/sockjs-client)发送文本流sockjs会选择一个合适的通道websocket或xhr(http),与后端通信
所以我们可以使用http来复现漏洞称之为"降维打击"。
我编写了一个简单的POC脚本[exploit.py](exploit.py)需要用python3.6执行因为该漏洞是订阅的时候插入SpEL表达式而对方向这个订阅发送消息时才会触发所以我们需要指定的信息有
1. 基础地址在vulhub中为`http://your-ip:8080/gs-guide-websocket`
2. 待执行的SpEL表达式`T(java.lang.Runtime).getRuntime().exec('touch /tmp/success')`
3. 某一个订阅的地址如vulhub中为`/topic/greetings`
4. 如何触发这个订阅即如何让后端向这个订阅发送消息。在vulhub中我们向`/app/hello`发送一个包含name的json即可触发这个事件。当然在实战中就不同了所以这个poc并不具有通用性。
根据你自己的需求修改POC。如果是vulhub环境你只需修改1中的url即可。
执行:
![](1.png)
进入容器`docker compose exec spring bash`,可见`/tmp/success`已成功创建:
![](2.png)