美文网首页恶意代码检测
Cuckoo SandBox V2.0.4安装指南

Cuckoo SandBox V2.0.4安装指南

作者: Henry3II | 来源:发表于2017-12-06 10:20 被阅读3680次

    Cuckoo SandBox V2.0.4踩坑笔记。目前网上大部分Cuckoo的安装教程为2.0版本的Cuckoo SandBox,该沙箱的上下版本不兼容,除参考本教程外,建议Google(不要百度),或者参考Cuckoo的官方文档。https://cuckoo.sh/docs/

    作者:Henry3II

    0x00 前言

    Cuckoo Sandbox是一个开源的恶意文件自动化分析系统,采用python和c/c++开发,跨越windows、android、linux和darwin四种操作系统平台,支持二进制的PE文件(exe、dll、com)、PDF文档、office文档、URLs、HTML文件、各种脚本(PHP、VB、Python)、jar包、zip文件等等几乎所有的文件格式。能分析恶意文件的静态二进制数据和动态运行后的进程、网络、文件等行为。对于恶意文件的初步分析定性具有很大帮助。(这是我复制的)

    配置情况:

    主机(host):

    Ubuntu 16.04 LTS 
    8Gb Ram
    VirtualBox 
    Cuckoo Sandbox 2.0.4
    

    客户机(guest):

    Windows 7 Professional
    2Gb Ram
    

    注:在安装之前最好为Cuckoo设置一个账户(比如,cuckoo),在安装Cuckoo时不要所有的都是用sudo来安装,这样后面会出现各种权限的错误。

    0x01 主机环境准备

    安装需要的依赖:

    $ sudo apt-get install git mongodb libffi-dev build-essential python-django python python-dev python-pip python-pil python-sqlalchemy python-bson python-dpkt python-jinja2 python-magic python-pymongo python-gridfs python-libvirt python-bottle python-pefile python-chardet tcpdump -y

    安装Tcpdump并确认安装无误:

    $ sudo setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump
    $ getcap /usr/sbin/tcpdump
    /usr/sbin/tcpdump = cap_net_admin,cap_net_raw+eip
    

    安装Pydeep:

    $ wget http://sourceforge.net/projects/ssdeep/files/ssdeep-2.13/ssdeep-2.13.tar.gz/download -O ssdeep-2.13.tar.gz
    $ tar -zxf ssdeep-2.13.tar.gz
    $ cd ssdeep-2.13
    $ ./configure
    $ make
    $ sudo make install
    
    #确认安装无误
    $ ssdeep -V
    Then proceed by installing pydeep:
    
    $ sudo pip install pydeep
    Validate that the package is installed:
    
    $ pip show pydeep
    ---
    Name: pydeep
    Version: 0.2
    Location: /usr/local/lib/python2.7/dist-packages
    Requires:
    

    安装Volatility:

    #先安装依赖
    $ sudo pip install openpyxl
    $ sudo pip install ujson
    $ sudo pip install pycrypto
    $ sudo pip install distorm3
    $ sudo pip install pytz 
    
    #然后安装volatility
    $ git clone https://github.com/volatilityfoundation/volatility.git
    $ cd volatility
    $ python setup.py build
    $ python setup.py install
    
    #确认安装无误
    $ python vol.py -h
    

    安装Cuckoo:

    安装Cuckoo有pip installgit clone两种方法,个人建议使用pip的方式安装,因为不同版本的Cuckoo的结构变化都不小,网上的教程为2.0版本的居多,在大部分教程中使用的cuckoo.pyweb.py等在新版本中均已不再使用。

    $ git clone git://github.com/cuckoosandbox/cuckoo.git
    

    0x02 客户机环境准备

    安装VirtualBox:

    #使用apt的方法安装是最简单的安装方法!
    $ sudo apt-get install virtualbox
    

    在安装VirtualBox的过程中很可能会出现要求你Disable Secure Boot的要求,我建议你最好进去BIOS把安全启动模式关掉,否则之后虚拟机的使用很可能无法创建Host-only网卡。

    创建一个虚拟机,系统建议使用WIn7或者WinXP,首先在VirtualBox的全局设定的网络设置中配置一个Host-only的网卡,这样虚拟机仅可以跟主机通信,然后配置虚拟机的网络为Host-only。在虚拟机内手动设置IP、网关、子网掩码、DNS。

    IP: 192.168.56.101
    Subnet mask:255.255.255.0
    Default gateway: 192.168.56.1
    Prefered DNS server: 114.114.114.114
    Alternate DNS server: 8.8.8.8
    
    

    至此客户机还不能上网,不要急,这个后面说。客户机里面还要python2.7的运行环境,记得将路径添加到环境变量里面。
    然后将之前安装的cuckoo得到的.cuckoo(隐藏文件,在Home文件夹下按ctrl+h),文件夹中的agent/agent.py挪到虚拟机中(记得给你的虚拟机安装增强功能,如果拖不进去就直接去Github上面下载2.0.rc2的版本,里面有)。
    我们需要这个 agent.py 开机启动,并且不能有运行窗口,这就需要另做一些处理:

    agent.py 文件放到系统开机启动目录中,Win7 默认的路径是 C:\Users\[USER]\AppData\Roaming\MicroSoft\Windows\Start Menu\Programs\Startup\
    agent.py 后缀改成 agent.pyw,这样程序启动就不会有 GUI 窗口了。

    接着我们要配置客户机能够开机自动登录,这样可以方便Cuckoo的控制,在开始->附件中使用管理员权限打开CMD窗口,依次执行:

    reg add "hklm\software\Microsoft\Windows NT\CurrentVersion\WinLogon" /v DefaultUserName /d <USERNAME> /t REG_SZ /f
    reg add "hklm\software\Microsoft\Windows NT\CurrentVersion\WinLogon" /v DefaultPassword /d <PASSWORD> /t REG_SZ /f
    reg add "hklm\software\Microsoft\Windows NT\CurrentVersion\WinLogon" /v AutoAdminLogon /d 1 /t REG_SZ /f
    reg add "hklm\system\CurrentControlSet\Control\TerminalServer" /v AllowRemoteRPC /d 0x01 /t REG_DWORD /f
    reg add "HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\Policies\System" /v LocalAccountTokenFilterPolicy /d 0x01 /t REG_DWORD /f
    
    

    记得修改前两条命令里的 <USERNAME><PASSWORD> 为自己的账户和密码。

    同时,客户机要关掉自动更新和防火墙功能。

    0x03 其他的网络设置

    如果都没配错的话,到这里Host和Guest两个机器之间应该是可以ping通的。但是此时Guest是无法访问互联网的,所以要在Host中设置IP转发,利用虚拟网卡做代理转发。

    #开启IP转发
    $ sudo -i
    $ sysctl -w net.ipv4.ip_forward=1
    $ echo 1 > /proc/sys/net/ipv4/ip_forward
    #为使重启之后仍然有效
    $ gedit /etc/sysctl.conf
    #去掉net.ipv4.ip_forward=1 前的注释,然后再执行下面的
    
    sysctl -p /etc/sysctl.conf
    
    

    然后配置Iptables的规则:

    #建议在配置Iptables规则之前要先Iptables -L看下有没有现有的防火墙规则,比如我就莫名其妙多出一堆关于192.168.122.0/24的规则,这样就全部sudo iptables -D ... 1删除掉就好了
    iptables -A FORWARD -o eth0 -i vboxnet0 -s 192.168.56.0/24 -m conntrack --ctstate NEW -j ACCEPT
    iptables -A FORWARD -m conntrack --ctstate ESTABLISHED,RELATED -j ACCEPT
    iptables -A POSTROUTING -t nat -j MASQUERADE
    
    #接着为保证重启之后依然有效
    sudo gedit /etc/network/interfaces
    #在最后添加两行
    pre-up iptables-restore < /etc/iptables.rules 
    post-down iptables-save > /etc/iptables.rules 
    
    

    这样一来,Ubuntu Host 主机每次关机前都会把已有的 iptables 规则备份到 /etc/iptables.rules文件中、每次开机是都会从 /etc/iptables.rules 读取规则并启用。

    配置好之后,Guest 虚拟机就可以通过 vboxnet0 来访问互联网了。

    此时客户机所有的准备工作,包括软件及网络的配置都好了,给虚拟机建立一个快照,用于每次跑完样本之后,Cuckoo会把它还原到这个状态。

    0x04 Cuckoo 配置

    Cuckoo配置文件的更改是非常重要的一步,否则很可能你的所有安装都无法正常启动。在 .cuckoo/conf/中修改配置文件:

    cuckoo.conf

    machinery = virtualbox
    [resultserver]
    ip = 192.168.56.1 #This is the IP address of the host
    port = 2042 #leave default unless you have services running
    

    auxiliary.conf

    [sniffer]
    # Enable or disable the use of an external sniffer (tcpdump) [yes/no].
    enabled = yes
    
    # Specify the path to your local installation of tcpdump. Make sure this
    # path is correct.
    # You can check this using the command: whereis tcpdump
    tcpdump = /usr/sbin/tcpdump
    
    # Specify the network interface name on which tcpdump should monitor the
    # traffic. Make sure the interface is active.
    # The ifconfig command will show you the interface name.
    interface = vboxnet0
    

    virtualbox.conf

    machines = 你的虚拟机名字
    
    [你的虚拟机名字]
    label = 你的虚拟机名字
    platform = windows
    ip = 192.168.56.10 # IP address of the guest
    snapshot = 你创建的快照名字
    

    reporting.conf

    [mongodb]
    enabled = yes
    #也许还有其他要改的,但是这个最重要,其他是yes还是no更多的是看你的需要,或者之后在使用时再来配置文件里面打开
    

    至此,所有的配置都配置完了,此时先运行Web服务
    cuckoo web runserver
    正常运行的话打开http://127.0.0.1:8000,就可以看到cuckoo SandBox的Web页面了。然后打开Cuckoo的服务,cuckoo 若最后一行显示等待分析任务,则说明你安装没问题,如果显示说没有找到CWD位置,则你需要先运行cuckoo -d

    运行一个样本之后,可能会发现无法分析网络流量的问题,比如在命令行里面出现红色的报错:

    Command "/usr/bin/python -u -c "import setuptools, tokenize;__file__='/tmp/pip-build-NKd6fY/pillow/setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record /tmp/pip-Zzo2hp-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-NKd6fY/pillow/
    

    则运行如下:

    $ sudo apt-get install python-virtualenv python-setuptools
    $ sudo apt-get install libjpeg-dev zlib1g-dev swig
    $ sudo apt-get install postgresql libpq-dev
    

    0x05 总结

    Cuckoo SandBox安装过程中有很多坑,最大的坑就是,它上下版本不兼容,国内国外还大部分都是2.0的安装教程!2.0版本的沙箱现在都已经不能用了(╯‵□′)╯︵┻━┻。各位在参考我的办法的时候也要注意你使用的未来的可能Cuckoo版本升级带来的所需的依赖的升级,很有可能本教程中安装的版本已经不再试用。所以不要吝惜重装系统,我已经记不清我重装多少次了。祝君好运,一次成功~

    0x06 参考资料

    1.https://cuckoo.sh/docs/installation/index.html

    2.https://reversing-malware.com/cuckoo-installation-and-setup/

    3.http://securityscrapbook.com/2016/12/17/cuckoo-sandbox-installation-configuration-guide/?i=1

    4.http://www.freebuf.com/sectool/108533.html

    5.https://github.com/cuckoosandbox/cuckoo/issues/1392

    相关文章

      网友评论

        本文标题:Cuckoo SandBox V2.0.4安装指南

        本文链接:https://www.haomeiwen.com/subject/mhrkixtx.html