logo资料库

上传漏洞总结(私人珍藏).pdf

第1页 / 共17页
第2页 / 共17页
第3页 / 共17页
第4页 / 共17页
第5页 / 共17页
第6页 / 共17页
第7页 / 共17页
第8页 / 共17页
资料共17页,剩余部分请下载后查看
Bypass Upload Validation Framework V0.9 CasperKid[S.Y.C] 2011.7.29 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 目录 0x01 客户端端验证绕过(javascript 扩展名检测) 0x02 服务器端验证绕过(http request 包检测) - Content-type (Mime type) 检测 0x03 服务器端验证绕过(扩展名检测) - 黑名单检测 - 白名单检测 - .htaccess 文件攻击 0x04 服务器端验证绕过(文件完整性检测) - 文件头检测 - 图像大小及相关信息检测 - 文件加载检测 0x05 各种情况下的检测绕过分析 0x06 关于图像代码注入后的解析简答 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 前言 在现在越来越安全的体系下,SQL Injection 这类漏洞已经很难在安全性很高地站点出现,比 如一些不错的.NET 或 JAVA 的框架基本上都是参数化传递用户输入,直接封死注入攻击。 而在非 php 的 web 安全中最有威力的攻击主要有两种,第一种是 SQL Injection,第二种便 是上传绕过漏洞。(php 的还有远程文件包含或代码注入漏洞) 一般只要能注册普通用户,时常都能找到上传头像或附件之类的地方,这些地方就是好的突 破点,只要有办法绕过上传验证,并找到一句话木马的 web 路径基本上就能搞下这个站点。 这篇 paper 并不完善,但在分类框架上还是比较全面,因为个人经验有限,所以所能覆盖的 情况并不全面,也有很多地方还没机会实践并贴图出来,希望大家有类似经验的提出来,以 便我能完善这篇 paper,也让大家的交流产生更大的价值。 Blog: hi.baidu.com/hackercasper
0x01 客户端端验证绕过(javascript 扩展名检测) 打开 HTTP 反向代理工具 burp 先随便点击上传一个 2012.asa 然后还没点 Upload burp 里也还没出现任何内容 便弹出了一个警告框 一看就知道是个客户端端验证 javascript 只需要把它禁掉或者通过 burp 进行代理修改
这里我用 burp 进行代理修改 先将文件扩展名改成 jpg 然后 Upload 现在的文件名是 2012.jpg 在 burp 里将 jpg 改成 asp
然后继续上传 最后可以看到 asp 成功上传
0x02 服务器端验证绕过(http request 包检测) - Content-type (Mime-type) 检测 假如服务器端上的 upload.php 代码如下 然后我们可以将 request 包的 Content-Type 修改 POST /upload.php HTTP/1.1 TE: deflate,gzip;q=0.3 Connection: TE, close Host: localhost User-Agent: libwww-perl/5.803 Content-Type: multipart/form-data; boundary=xYzZY Content-Length: 155 --xYzZY Content-Disposition: form-data; name="userfile"; filename="shell.php" Content-Type: image/gif (原为 Content-Type: text/plain) --xYzZY-- HTTP/1.1 200 OK Date: Thu, 31 May 2007 14:02:11 GMT Server: Apache X-Powered-By: PHP/4.4.4-pl6-gentoo Content-Length: 59 Connection: close Content-Type: text/html
File is valid, and was successfully uploaded.
像这种服务端检测 HTTP 包的 Content-Type 都可以用这种类似的方法来绕过检测
0x03 服务器端验证绕过(扩展名检测) - 黑名单检测 黑名单的安全性其实还没白名单的安全性高,至少攻击它的方式比白名单多多了 一般有个专门的 blacklist 文件,里面会包含常见的危险脚本文件 例如 fckeditor 2.4.3 或之前版本的黑名单 1. 找黑名单扩展名的漏网之鱼 - 比如上面就漏掉了 asa 和 cer 之类 2. 可能存在大小写绕过漏洞 - 比如 aSp 和 pHp 之类 3. 特别文件名构造 - 比如发送的 http 包里把文件名改成 help.asp. 或 help.asp_(下划线为空 格),这种命名方式在 windows 系统里是不被允许的,所以需要在 burp 之类里进行修改,然 后绕过验证后,会被 windows 系统自动去掉后面的点和空格。 4. IIS 或 nginx 文件名解析漏洞 - 比如 help.asp;.jpg 或 http://www.xx.com/help.jpg/2.php 这里注意网上所谓的 nginx 文件名解析漏洞实际上是 php-fpm 文件名解析漏洞 详见 http://www.cnbeta.com/articles/111752.htm 5. 0x00 截断绕过 - 这个是基于一个组合逻辑漏洞造成的 给个简单的伪代码 name = getname(http request) //假如这时候获取到的文件名是 help.asp .jpg(asp 后面为 0x00) type = gettype(name) //而在 gettype()函数里处理方式是从后往前扫描扩展名,所以判断为 jpg if (type == jpg) SaveFileToPath(UploadPath.name, name) //但在这里却是以 0x00 作为文件名截断 //最后以 help.asp 存入路径里 6. 双扩展名解析绕过攻击(1) - 基于 web 服务器的解析逻辑 比如在 Apache manual 中有这样一段描述 “Files can have more than one extension, and the order of the extensions is normally irrelevant. For example, if the file welcome.html.fr maps onto content type text/html and language French then the file welcome.fr.html will map onto exactly the same information. If more than one extension is given which maps onto the same type of meta-information, then the one to the right will be used, except for languages and content encodings. For example, if .gif maps to the MIME-type image/gif and .html maps to the MIME-type text/html, then the file welcome.gif.html will be associated with the MIME-type text/html.” 如果上传一个文件名为 help.asp.123 首先扩展名 123 并没有在扩展名 blacklist 里,然后扩展名 123 也没在 Apache 可解析扩展名 list 里,这个时候它会向前搜寻下一个可解析扩展名,或搜寻到.php,最后会以 php 执行
7. 双扩展名解析绕过攻击(2) - 基于 web 服务器的解析方式 如果在 Apache 的 conf 里有这样一行配置 AddHandler php5-script .php 这时只要文件名里包含.php 即使文件名是 test2.php.jpg 也会以 php 来执行 8. 危险解析绕过攻击 - 基于 web 服务器的解析方式 如果在 Apache 的 conf 里有这样一行配置 AddType application/x-httpd-php .jpg 即使扩展名是 jpg,一样能以 php 方式执行
分享到:
收藏