布谷鸟cuckoo

本文分为3部分,分别是 布谷鸟的安装、虚拟机的使用和布谷鸟的配置和使用。

参考资料有:

 

布谷鸟的安装

1、环境准备

apt-get update
apt-get install -y python python-pip python-dev libffi-dev libssl-dev
apt-get install -y python-virtualenv python-setuptools
apt-get install -y libjpeg-dev zlib1g-dev swig
# 如果使用web交互界面,需要安装mongodb,ubuntu 12.04安装mongodb有问题,不能简单安装,需要参考官网文档进行安装 (可以不安装)
apt-get install -y mongodb
# 默认使用sqlite3,推荐使用PostgreSQL,需要配置(可以不安装)
apt-get install -y postgresql libpq-dev

2、安装yara和pydeep

这一步推荐使用virtualenv进行安装,否则后面使用virtualenv安装cuckoo后运行可能会报错,提示没有yara。

(venv)pip install yara-python==3.5.0

pydeep好像不需要,可参考freebuf安装。

3、安装virtualbox

到  http://download.virtualbox.org/virtualbox 下载对应系统的包进行安装

dpkg -i xxx.deb
# 如果安装时报错缺少依赖项,可以执行
apt-get install -f
# 进行安装

CentOS安装virtualbox

# 首先要保证内核版本一致
yum install kernel kernel-headers kernel-devel gcc make
# 然后重启,在安装virtualbox
yum install xxx.rpm

4、安装tcpdump

这里描述得比较简单,详情请参考
 http://docs.cuckoosandbox.org/en/latest/installation/host/requirements/#installing-tcpdump

apt-get install -y tcpdump apparmor-utils libcap2-bin
aa-disable /usr/sbin/tcpdump
setcap cap_net_raw,cap_net_admin=eip /usr/sbin/tcpdump

5、安装Volatility 和 M2Crypto

好像也不需要。

6、创建cuckoo用户

注意,使用cuckoo的用户要和创建virtualbox的用户一致
创建用户并添加到virtualbox的用户组

adduser cuckoo
usermod -a -G vboxusers cuckoo

不过我一直都直接用root的。

7、安装cuckoo

pip install virtualenv
virtualenv venv
. venv/bin/activate
(venv)$ pip install -U pip setuptools
(venv)$ pip install -U cuckoo

CentOS安装可能会报这些错:

1)
swig error : Unrecognized option -builtin
  Use 'swig -help' for available options.
  error: command 'swig' failed with exit status 1
  
  ----------------------------------------
  Failed building wheel for m2crypto

解决方法:http://xujpxm.blog.51cto.com/8614409/1734786
安装新版swig

2)
ImportError: No module named bz2
解决方法:yum install bzip2-devel
http://blog.csdn.net/ruiyiin/article/details/45641833


3)
CuckooDependencyError: Missing unknown database driver, unable to import pysqlite2
解决方法
yum install sqlite-devel
pip install pysqlite
如果还报错的话,解决不了,换mysql或者pgsql吧

8、启动cuckoo

在virtualenv下执行

(venv)$ cuckoo -d

首次启动会在用户目录下创建一下隐藏的cuckoo目录,即 /home/Username/.cuckoo/,目录下的conf文件夹内就有配置文件。也可以使用cwd来指定在哪里创建。

 

虚拟机的使用

安装好cuckoo后,我们就需要安装客户机了。如果我们使用图形化界面,则只需要像平时那样打开virtualbox,创建虚拟机,然后进行配置就可以了。

但如果是使用服务器或者是命令行界面的话,则需要使用 VBoxManage 命令来操作并管理虚拟机了。

cuckoo的客户机官方推荐使用win7 64位,xp也是非常好的。

虚拟机的使用请查看这篇文章  https://my.oschina.net/dragonite/blog/1524770

个人推荐先在自己的系统上使用图形界面把虚拟机安装配置好,在直接把虚拟机的硬盘vdi文件复制到服务器上,然后在创建虚拟机,指定使用的硬盘文件。

 

客户机的安装

安装好客户机的系统后,我们要进行配置

1、为windows安装python 下载地址: https://www.python.org/ftp/python/2.7.13/python-2.7.13.msi

2、安装PIL(Python截屏库) 下载地址: http://effbot.org/media/downloads/PIL-1.1.7.win32-py2.7.exe

3、关闭windows自动更新

4、关闭windows防火墙

5、安装第三方应用程序(MS Office 2003/2007,Adobe Reader 9.3.4,Firefox 3.6等,可以到 http://www.oldapps.com这个网站去下载旧的软件)

6、在Ubuntu下,把/home/Username/.cuckoo/agent目录下的agent.py拷贝到客户机中(比如桌面或者新建一个目录啥的),并将agent.py重命名为agent.pyw,这样运行的时候就不会显示控制台窗口了

7、将agent.pyw的快捷方式放到启动文件夹中去(C:\Documents and Settings\All Users\「开始」菜单\程序\启动 ) (win 7: 开始菜单->所有程序->启动->右键打开,把快捷方式复制过去)

8、运行agent.pyw后,我们使用netstat -an命令会发现本地的8000端口正在处于监听状态中

(如果是win7,还需要关闭UAC)

9、设置网络为host-only模式。

cuckoo客户机需要配置网络方式为 Host-only 模式,并配置网卡ip,网关配置为默认的192.168.56.1 (此 IP 要与上面的 vboxnet0 网卡的 IP 地址相对应)。这样就不用担心客户机会污染到主机所在的网络。

配置好后,我们要验证网络没问题后在创建快照,这样每次cuckoo分析前都会恢复快照进行检测。

首先我们在宿主机上(即ubuntu/CentOS)上设置防火墙:

iptables -t nat -A POSTROUTING -o eth0 -s 192.168.56.0/24 -j MASQUERADE

# Default drop.
iptables -P FORWARD DROP

# Existing connections.
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

# Accept connections from vboxnet to the whole internet.
iptables -A FORWARD -s 192.168.56.0/24 -j ACCEPT

# Internal traffic.
iptables -A FORWARD -s 192.168.56.0/24 -d 192.168.56.0/24 -j ACCEPT

# Log stuff that reaches this point (could be noisy).
iptables -A FORWARD -j LOG 

还要开启主机转发,编辑 /etc/sysctl.conf ,将里面 net.ipv4.ip_forward=1 前的注释取消,然后运行以下命令即可永久开启 IP 转发功能:

sysctl -p /etc/sysctl.conf

配置好后,客户机就应该可以上网的了。

保证客户机可以上网后,我们就可以创建快照,如

VBoxManage snapshot "win7_x86" take "win7_x86_snapshot" --pause

注意,创建快照的用户一定要和cuckoo的用户一致,否则cuckoo可能启动不了和恢复不了虚拟机。

 

Cuckoo的配置和使用

1、首先配置cuckoo,进入到/home/Username/.cuckoo,编辑 conf/virtualbox.conf ,

# Specify a comma-separated list of available machines to be used. For each
# specified ID you have to define a dedicated section containing the details
# on the respective machine. (E.g. cuckoo1,cuckoo2,cuckoo3)
machines = win7_x86

[win7_x86_1]
# Specify the label name of the current machine as specified in your
# VirtualBox configuration.
label = win7_x86

# Specify the operating system platform used by current machine
# [windows/darwin/linux].
platform = windows

# Specify the IP address of the current virtual machine. Make sure that the
# IP address is valid and that the host machine is able to reach it. If not,
# the analysis will fail.
ip = 192.168.56.111

# (Optional) Specify the snapshot name to use. If you do not specify a snapshot
# name, the VirtualBox MachineManager will use the current snapshot.
# Example (Snapshot1 is the snapshot name):
snapshot = win7_x86_snapshot

把machines修改为对应的客户机名称,还有ip和快照名称

2、如果需要使用web交互界面,需要修改reporting.conf,开启mongodb

[mongodb]
enabled = yes

还有生成的报告(按需修改)

[singlefile]
# Enable creation of report.html and/or report.pdf?
enabled = yes 
# Enable creation of report.html?
html = yes 
# Enable creation of report.pdf?
pdf = no

还有一些其他的配置慢慢看吧。

3、安装特征库

(venv)$ cuckoo community
# 如果下载比较慢,多试几次,或者先下载完后进行导入
(venv)$ cuckoo community --file cuckoo_master.tar.gz

4、启动cuckoo

(venv)$ cuckoo -d

如果出现waiting for analysis tasks 即表示成功,可以进行提交任务进行检查了。

5、启动web界面

(venv)$ cuckoo web runserver

指定IP和端口
(venv)$ cuckoo web runserver 0.0.0.0:PORT

这样我们就可以登录页面提交测试文件或url了。

6、让cuckoo运行在后台

编辑 /home/Username/.cuckoo/conf/cuckoo.conf ,把 process_results 改为off

安装supervisor

apt-get install supervisor

运行
supervisord -c /home/Username/.cuckoo/supervisord.conf

基本命令
supervisorctl stop cuckoo:
supervisorctl start cuckoo:
supervisorctl restart cuckoo:

7、cuckoo提交任务

cuckoo提交任务  http://docs.cuckoosandbox.org/en/latest/usage/submit/

cuckoo submit --url http://www.example.com

8、结果分析

每次提交一个分析请求后,会得到该请求的一个ID号。我们可以在 /home/Username/.cuckoo/storage/analyses/ID/reports/report.json 查看分析结果

9、更改默认数据库

cuckoo默认使用sqlite数据库,如果需要使用并发(多台虚拟机同时分析)的话,推荐使用mysql或者postgresql。

这里使用mysql作为设置,首先创建cuckoo用户,密码为cuckoo,数据库为cuckoo

mysql> CREATE DATABASE IF NOT EXISTS cuckoo default charset utf8 COLLATE utf8_general_ci; 
mysql> CREATE USER 'cuckoo'@'localhost' IDENTIFIED BY 'cuckoo';
mysql> GRANT ALL PRIVILEGES ON cuckoo.* TO 'cuckoo'@'localhost';
mysql> FLUSH PRIVILEGES;

接着修改cuckoo配置文件 conf/cuckoo.conf

[database]
connection = mysql://cuckoo:cuckoo@localhost/cuckoo

重启cuckoo即可。

10、特征分析

signature 在工作目录下 ~/.cuckoo/signatures

 

错误处理

常见的错误有 supervisor 出错,cuckoo出错,vboxmanage出错

基本可以用 supervisorctl restart cuckoo: 来解决(如果不行,可以使用supervisord -c 重启)

cuckoo出现的问题可能有分析完后,虚拟机关闭不了,导致虚拟机不能恢复并启动,只能是强制关闭虚拟机并重启cuckoo。还有会timeout导致生成不了报告,或者生成的报告是报错的。

这些都无解,可以到github上的issue查查解决方法。

 

cuckoo进阶

1、CWD工作目录

虽然 cuckoo 默认的 cwd 是 ~/.cuckoo,但决定cwd的顺序是:

  • 通过 --cwd 参数设置 (e.g., --cwd ~/.cuckoo).
  • 通过 CUCKOO 环境变量 (e.g., export CUCKOO=~/.cuckoo).
  • 通过 CUCKOO_CWD 环境变量
  • 当前目录是 CWD (假设这个目录已经创建了CWD)
  • 默认 ~/.cuckoo

多个CWD可以让多个cuckoo实例跑在不同的配置,比如并发运行不同系统的cuckoo等。

 

2、RESET API http://docs.cuckoosandbox.org/en/latest/usage/api/

我们也可以使用REST API来提交或者获取分析等。

开启API Server

cuckoo api

这种方式是最简单的,虽然没什么问题,但如果想需要使用健壮的方式部署服务器的话,可以使用uWSGI+Nginx来进行部署。

apt-get install uwsgi uwsgi-plugin-python nginx

然后执行
cuckoo api --uwsgi
把生成的结果保存到 /etc/uwsgi/apps-available/cuckoo-api.ini 文件里。

在执行
ln -s /etc/uwsgi/apps-available/cuckoo-api.ini /etc/uwsgi/apps-enabled/
service uwsgi start cuckoo-api

然后我们在配置nginx,执行
cuckoo api --nginx
把生成的结果保存到 /etc/nginx/sites-available/cuckoo-api
重启nginx
service nginx restart
(确保nginx重启后有在监听8090端口)

然后我们可以测试一下

提交url
curl -F url="http://www.malicious.site" http://localhost:8090/tasks/create/url

获取请求ID状态
curl http://localhost:8090/tasks/view/1

具体请查看官方文档

 

3、Distributed http://docs.cuckoosandbox.org/en/latest/usage/dist/ 

 

 

一些脚本

 

start_cuckoo.sh  开机启动脚本

#!/bin/bash

vboxmanage hostonlyif ipconfig vboxnet0 --ip 192.168.56.1 --netmask 255.255.255.0

source /home/bluedon/cuckoo/venv/bin/activate
supervisord  -c /home/bluedon/cuckoo/.cuckoo/supervisord.conf

/home/bluedon/cuckoo/set_iptables.sh

set_iptables.sh 设置防火墙脚本

#!/bin/bash

NIC="eth0"

iptables -t nat -A POSTROUTING -o ${NIC} -s 192.168.56.0/24 -j MASQUERADE

# Default drop.
iptables -P FORWARD DROP

# Existing connections.
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT

# Accept connections from vboxnet to the whole internet.
iptables -A FORWARD -s 192.168.56.0/24 -j ACCEPT

# Internal traffic.
iptables -A FORWARD -s 192.168.56.0/24 -d 192.168.56.0/24 -j ACCEPT

# Log stuff that reaches this point (could be noisy).
iptables -A FORWARD -j LOG 

创建虚拟机的脚本 create_win7.sh

#!/bin/bash

cuckoo_venv="/home/bluedon/cuckoo/"

create_vbox()
{
    for i in {1..3}
    do  
    
        vdi_path=$cuckoo_venv"virtualbox/win7_x86_"$i"/"
        VBoxManage createvm --name win7_x86_$i --ostype Windows7 --register --basefolder $cuckoo_venv"virtualbox/"
        VBoxManage modifyvm win7_x86_$i --memory 1024 --vram 18
        VBoxManage storagectl win7_x86_$i --name SATA --add sata --controller IntelAhci --bootable on
        cp $cuckoo_venv"win7_x86.vdi"  $vdi_path
        # change uuid
        VBoxManage internalcommands sethduuid $vdi_path"win7_x86.vdi"
        VBoxManage storageattach  win7_x86_$i  --storagectl SATA --port 0 --device 0 --type hdd --medium  $vdi_path"win7_x86.vdi"
        vboxmanage modifyvm win7_x86_$i --nic1 hostonly --hostonlyadapter1 vboxnet0
    
        echo "done create win7_x86_"$i
        echo ""
    done
}

create_vbox

 

 

 

 

转载于:https://my.oschina.net/dragonite/blog/1524762

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值