﻿<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/"><channel><title>C++博客-兔子的技术博客-随笔分类-服务器安全</title><link>http://www.cppblog.com/flyinghare/category/20540.html</link><description>兔子</description><language>zh-cn</language><lastBuildDate>Tue, 28 May 2013 16:35:09 GMT</lastBuildDate><pubDate>Tue, 28 May 2013 16:35:09 GMT</pubDate><ttl>60</ttl><item><title>截断上传详解 从入门到精通（一）</title><link>http://www.cppblog.com/flyinghare/archive/2013/05/29/200664.html</link><dc:creator>会飞的兔子</dc:creator><author>会飞的兔子</author><pubDate>Tue, 28 May 2013 16:17:00 GMT</pubDate><guid>http://www.cppblog.com/flyinghare/archive/2013/05/29/200664.html</guid><wfw:comment>http://www.cppblog.com/flyinghare/comments/200664.html</wfw:comment><comments>http://www.cppblog.com/flyinghare/archive/2013/05/29/200664.html#Feedback</comments><slash:comments>0</slash:comments><wfw:commentRss>http://www.cppblog.com/flyinghare/comments/commentRss/200664.html</wfw:commentRss><trackback:ping>http://www.cppblog.com/flyinghare/services/trackbacks/200664.html</trackback:ping><description><![CDATA[<span style="font-family: Arial; line-height: 28px; background-color: #f5fcff; color: #ff0000;"><strong>声明：原创文章，转载请指名来自华夏联盟（</strong><a href="http://www.hx95.com/" target="_blank" id="url_1" style="text-decoration: none; color: #0070af;"><strong>www.hx95.com</strong></a><strong>），违者必究！</strong></span>&nbsp;<br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">文章作者：仙剑之鸣&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">截断上传大家一定不陌生，可能你也看过很多动画教程，人家都能顺利的上传成功，而但自己操作时却总是失败，为什么会这样？&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">其实我一开始接触&#8220;截断&#8221;这个概念时感到很神奇，也觉得很茫然。神奇的是它竟能突破上传限制，茫然的是什么情况下才可以用？哪些上传能截断，哪些又不能。。。带着这些问题，我试着去找上传，试着用NC去截断，可从来就没有成功过。。。慢慢的就对这个概念模糊了！&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">后来，我在拿一个站时，遇到了困难，可用的地方就只有上传，于是被逼着再去研究截断。。。经过那次的成功才发现，截断原来是那么的简单。。。摸清原理之后，它就不那么神奇了。&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">也许你曾经用阿D，明小子。。的上传上传过SHE11,其实这些工具也是用&#8220;截断&#8221;来上传的，而如果每次都盲目的用它来上传，甚至连为什么都不知道，那说实话，就算你用它来拿再多的站也没任何进步！。。。懂得为什么才是最重要的，灵活变通，活学活用才能不断的成长！&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><strong style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;"><span style="color: #ff0000;">下面和大家分享一下我给截断的一些学习经验：还是那句话，高手请飞过！&nbsp;</span></strong><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">截断的核心，就是chr(0)这个字符&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">先说一下这个字符，这个字符不为空(Null)，也不是空字符("")，更不是空格！&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">当程序在输出含有chr(0)变量时，chr(0)后面的数据会被停止，换句话说，就是误把它当成结束符，后面的数据直接忽略，这就导致漏洞产生&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">简单举个例子，看下面的代码&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">&lt;%&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">path="upfiles/picture/"&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">file="20121212.jpg"&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">upfilename=path &amp; file '最后的上传地址&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">%&gt;&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">就这段代码中的path为上传的路径，file为生成的文件名，upfilename为上传后的地址，程序表面是没什么问题，但如果path可以由用户自定义（path这个参数往往是从表单或参数传过来的，能够自定义），所以就产生了上传路径截断漏洞&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">比如我在表单中把路径改成了&#8220;upfiles/1.aspChr(0)&#8221;&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">这样上传路径就成了 path="upfiles/1.aspChr(0)" chr(0)代表那个截断字符&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">这时变量被输出时，就成了upfiles/1.asp&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">而不是upfiles/upfiles/1.aspChr(0)20121212.jpg&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">很明显，upfile/1.asp就成了she11&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">你可以马上做个实验&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">把上面的代码修改一下：&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">&lt;%&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">path="upfiles/1.asp" &amp; Chr(0) 'asp中chr(0)表示截断字符&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">file="20121212.jpg"&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">upfilename=path &amp; file '最后的上传地址&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">response.write upfilename&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">%&gt;&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">眼见为实，你会发现最后输出的upfilename确实是upfile/1.asp，变量输出是这样，上传时生成文件当然也会这样，这就是大家常听到的路径截断上传！&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">上面这个例子非常简单，如果你想学截断，不妨亲手试一下，明白了它的原理，看到了输出的结果，你就会恍然大悟，原来截断是这么的简单！&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">本文只讲了路径截断，当然截断的种类也有好几种，原理其实都一样。。。都是利用了这个chr(0)字符。&nbsp;</span><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><br style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;" /><span style="color: #333333; font-family: Arial; line-height: 28px; background-color: #f5fcff;">至于实操，其它截断。。以后会和大家慢慢分享！</span><br />转自：<a href="http://bbs.hx95.com/read-htm-tid-19597-fpage-5-skinco-wind.html">http://bbs.hx95.com/read-htm-tid-19597-fpage-5-skinco-wind.html<br /><br /><br /></a>其它相关资料：<br /><br /><dl style="border-width: 0px; padding: 15px 0px 0px; margin: 0px; list-style: none; float: left; width: 670px; height: 35px; text-align: center; font-size: 21px; font-weight: bold; font-family: 宋体; line-height: normal; background-color: #ffffff;"><dd style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;">截断字符上传</dd></dl><dl style="border-width: 0px; padding: 10px 20px; margin: 0px; list-style: none; float: left; width: 630px; font-size: 12px; color: #999999; font-family: 宋体; line-height: normal; background-color: #ffffff;"><dd line_blue"="" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; background-image: url(http://www.2cto.com/statics/images/xxbule.jpg); height: 30px; overflow: hidden; float: left; width: 500px; background-position: 0% 22px; background-repeat: repeat no-repeat;">2007-10-02 10:31:06 &nbsp;&nbsp;&nbsp;&nbsp;<a href="http://www.2cto.com/Article/200710/19044.html#comment_iframe" style="color: #1f3a87; text-decoration: none; font-weight: bold; padding: 5px 0px 5px 20px; background-image: url(http://www.2cto.com/statics/images/icon/user_comment.png); background-position: 0% 50%; background-repeat: no-repeat no-repeat;">我来说两句&nbsp;</a>&nbsp;&nbsp; &nbsp;&nbsp;</dd><dd line_blue"="" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none; background-image: url(http://www.2cto.com/statics/images/xxbule.jpg); height: 30px; overflow: hidden; float: left; width: 130px; text-align: right; background-position: 0% 22px; background-repeat: repeat no-repeat;"><span id="favorite"><a style="color: #1f3a87;">收藏</a>&nbsp;</span>&nbsp;&nbsp;&nbsp;<a target="_blank" href="http://www.2cto.com/index.php?m=member&amp;c=content&amp;a=publish&amp;modid=1&amp;siteid=1" style="color: #1f3a87; text-decoration: none;"><img border="0" src="http://www.2cto.com/statics/images/dl.jpg" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;"  alt="" />我要投稿</a></dd></dl><dl id="fontzoom" style="border-width: 0px; padding: 0px 20px 20px; margin: 0px; list-style: none; float: left; width: 630px; color: #333333; line-height: 28px; font-family: 宋体; background-color: #ffffff;"><dd id="Article" style="border-width: 0px; padding: 0px; margin: 0px; list-style: none;"><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">来自樱木花盗 blog</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">截断字符上传的确是一个很聪明的方法！ 能想出这一招的人一定是个怪才！&nbsp;<br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 其实这一招也很简单！　　就是在上传一半的时候　理论上停止了！</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">　　比如找到了一个upfile.asp 但是在上传的时候　遇到扩展名不对的问题时！</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">　你就用这一招｀　比如上传一个1.asp.jpg　　　不知道你想明白没！</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">　　　呵呵！ 估计你已经想到了 原理！&nbsp;&nbsp;&nbsp;&nbsp; 就是在上传1.asp.jpg的时候&nbsp;&nbsp;&nbsp;&nbsp; 可以截断上传</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">过程&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 结果上传的东西的扩展名就成了&nbsp;&nbsp;&nbsp;&nbsp; 1.asp&nbsp;&nbsp;&nbsp;&nbsp; webshell就形成了</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">你也可以上传1.asp 他的提示肯定是不成功！</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">然后把上传的数据包修改以下&nbsp;&nbsp; nc 提交&nbsp;&nbsp; 注意如果是上传 1.asp&nbsp;&nbsp; 要在后面加一个空格</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">那么win2000 在这个<a href="http://www.2cto.com/" target="_blank" style="color: #333333; text-decoration: none;">漏洞</a>的处理方面没有显现他的卓越功效！</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;">只会认成 1.<a href="http://www.2cto.com/kf/web/asp/" target="_blank" style="color: #333333; text-decoration: none;">asp</a>&nbsp;然后保存 在wwwroot的目录里！形成了你的webshell</p><p style="border-width: 0px; padding: 0px; margin: 0px 0px 8px; list-style: none; text-indent: 2em;"><br />&nbsp;&nbsp;&nbsp;&nbsp;&nbsp; 这种漏洞源自所有写程序的人都以函数比较文件的扩展名！&nbsp;&nbsp;&nbsp;&nbsp; 导致了这样的错误 &nbsp;<br /><a href="http://www.2cto.com/Article/200710/19044.html">http://www.2cto.com/Article/200710/19044.html</a></p></dd></dl><img src ="http://www.cppblog.com/flyinghare/aggbug/200664.html" width = "1" height = "1" /><br><br><div align=right><a style="text-decoration:none;" href="http://www.cppblog.com/flyinghare/" target="_blank">会飞的兔子</a> 2013-05-29 00:17 <a href="http://www.cppblog.com/flyinghare/archive/2013/05/29/200664.html#Feedback" target="_blank" style="text-decoration:none;">发表评论</a></div>]]></description></item></channel></rss>