背景
CAPEはCuckooから派生したOSSのSandboxです。
CAPEの好きなところは、Unpackした検体をダンプし、ダウンロードできることです。
また、オプションでIATの再構築を試みてくれるのも有り難い〜
2020年1月にCAPEv2がリリースされましたが、CAPEv2の親切な構築Blogが見当たらなかったので、memoを残して置きます。
以下にオンラインのコミュニティ版がありますので、構築しない人はそちらをどうぞ。
https://capesandbox.com/submit
Host
ユーザ名capeを作成し、以降はcapeユーザで作業をする
Hostの情報は以下
cape@sandbox:~$ cat /etc/lsb-release | head -n 4 && uname -r DISTRIB_ID=Ubuntu DISTRIB_RELEASE=20.04 DISTRIB_CODENAME=focal DISTRIB_DESCRIPTION="Ubuntu 20.04.1 LTS" 5.4.0-42-generic
KVM
KVMをinstallしていく。紆余曲折あり、推奨もKVMなので、KVMを使ってみた。
なお、KVMは素人同然。いや素人そのもの
cape@sandbox:~$ sudo apt install cpu-checker cape@sandbox:~$ kvm-ok # kvmがinstallできるか確認する。以下の出力であればok INFO: /dev/kvm exists KVM acceleration can be used cape@sandbox:~$ sudo apt install qemu-kvm libvirt-daemon-system libvirt-clients bridge-utils virtinst virt-manager cape@sandbox:~$ sudo systemctl is-active libvirtd active cape@sandbox:~$ sudo usermod -aG libvirt cape cape@sandbox:~$ sudo usermod -aG kvm cape cape@sandbox:~$ virt-manager # kvmの起動

VMのimageは検証でお馴染み、MSが提供しているEdge開発者向けのimageを利用する。90日まで使用可能。imageはHyper-Vをダウンロードしてみた。
https://developer.microsoft.com/ja-jp/microsoft-edge/tools/vms/
qcow2に変換する。
cape@sandbox:~/Downloads$ 7z x MSEdge.Win10.HyperV.zip cape@sandbox:~/Downloads$ cd 'Virtual Hard Disks' cape@sandbox:~/Downloads/Virtual Hard Disks$ mv 'MSEdge - Win10.vhdx' MSEdge-Win10.vhdx cape@sandbox:~/Downloads/Virtual Hard Disks$ qemu-img convert -O qcow2 MSEdge-Win10.vhdx cuckoo1.qcow2 cape@sandbox:~/Downloads/Virtual Hard Disks$ chmod 664 cuckoo1.qcow2
残念だが、win10では、capeでNetrworkの解析が出来なかった。。
仕方がないので、win7を利用する。幸いにも、手元に利用していないwin7のimageが残っていた。
ovaだったのでqcow2に変換する。
cape@sandbox:~/Documents$ tar -xvf Win7.ova Win7.ovf Win7-disk1.vmdk cape@sandbox:~/Documents$ qemu-img convert -f vmdk -O qcow2 Win7-disk1.vmdk Win7.qcow2 cape@sandbox:~/Documents$ file Win7.qcow2 Win7.qcow2: QEMU QCOW2 Image (v3), 136365211648 bytes
以降はGUIの操作。
virt-managerのtop画面より[File] – [New Virtual Machine]を選択
“Import existing disk image”より以下のように勧めていく


Windows7 Setup
起動したら、IPアドレスを固定します。192.168.122.101を使用しました。
次に、ノイズを除去するbatをダウンロードして実行します。
wget https://raw.githubusercontent.com/doomedraven/Tools/master/Windows/disable_win7noise.bat -o C:\Users\{UserName}\Desktop\disable_win7noise.bat .\disable_win7noise.bat
次に.NET 4.7.2以上をインストール。
Pythonは 3.6 のx86をインストール!x64は駄目みたい。
再起動し、Pillowをinstallします。
py -m pip install --upgrade pip py -m pip install --upgrade Pillow
agent.pyをダウンロードし、startup配下に保存
wget https://raw.githubusercontent.com/kevoreilly/CAPEv2/master/agent/agent.py -o "C:\Users\{UserName}\AppData\Roaming\Microsoft\Windows\Start Menu\Programs\Startup\agent.pyw"
その他に、malwareが快適に動くTunningを実施します。Tunningは長くなるし、割愛しますが、Sandboxを活かす為に絶対必要です。
win10の話ですが、お気に入りのコマンドを紹介しておきます。
以下のコマンドでCの直下をDefenderの対象外に出来ます。
powershell Add-MpPreference -ExclusionPath C:\
Defenderが意図せず動いた時の保険や、ちょっとした検証時に話が早くなるので気にいってます。管理者で実行して下さい。
再起動し、pythonが立ち上がっているか、タスクマネージャーから確認して下さい。
pythonが立ち上がっていることを確認したら、スナップショットを作成します。
cape@sandbox:~$ virsh snapshot-create cuckoo1 Domain snapshot 1598359132 created cape@sandbox:~$ virsh snapshot-list cuckoo1 Name Creation Time State --------------------------------------------------- 1598359132 2020-08-25 21:38:52 +0900 running
GUIからももちろん可能。
CAPEv2
公式ドキュメントでも推奨されているinstallスクリプトを利用する。良い子はスクリプト内に記載されているDBのパスワードを変更してから実行すること。
cape@sandbox:~$ sudo wget https://raw.githubusercontent.com/doomedraven/Tools/master/Sandbox/cape2.sh cape@sandbox:~$ vim cape2.sh . . NETWORK_IFACE=virbr0 # for tor IFACE_IP="192.168.122.101" # DB password PASSWD="{CHANGE-YOUR-PASSWORD}" DIST_MASTER_IP="127.0.0.1" USER="cape" nginx_version=1.18.0 . .
DIST_MASTER_IPは少し自信がないが・・とりあえず実行
cape@sandbox:~$ sudo chmod a+x cape2.sh cape@sandbox:~$ sudo ./cape2.sh base cape | tee cape2_result.txt
/opt/CAPEv2/ にinstallされる。
conf
cuckoo.conf
[resultserver] ip = 0.0.0.0 # kvm側で指定するため、0.0.0.0にしておく
databaseはinstall scriptを利用するとpostgleが設定されている。ブランクにするとsqlite3になるとのこと。
auxiliary.conf
. . [zipped_download] enabled = yes zip_pwd = infected
kvm.conf
[kvm] #machines = cuckoo1 machines = win7_x64 interface = virbr0 #[cuckoo1] [win7_x64] label = cuckoo1 platform = windows ip = 192.168.122.101 snapshot = 1598359132 resultserver_ip = 192.168.122.1 # window10のGateway resultserver_port = 2042 . .
memory.conf
guest_profile = Win7SP1x64_23418
guest_profileは以下を参考にした
https://github.com/volatilityfoundation/volatility/wiki/2.6-Win-Profiles#profile-lists
processing.conf
[virustotal] enabled = yes timeout = 60 # Add your VirusTotal API key here. The default API key, kindly provided # by the VirusTotal team, should enable you with a sufficient throughput # and while being shared with all our users, it shouldn't affect your use. key = {your API key}
routing.conf
[routing] route = internet internet = enp4s0 # HOSTのNWに合わせること。 [tor] enabled = yes dnsport = 5353 proxyport = 9040 interface = virbr0
web.conf
[malscore] enabled = yes [url_analysis] enabled = yes [tlp] enabled = yes
その他
webサーバやサービス周り
cape@sandbox:/opt/CAPEv2/web$ sudo python3 manage.py migrate sudo service mongodb start sudo systemctl enable mongodb cape@sandbox:/opt/CAPEv2/conf$ sudo vim /lib/systemd/system/cape-web.service [Service] WorkingDirectory=/opt/CAPEv2/web ExecStart=/usr/bin/python3 manage.py runserver {your_ip}:8888
起動方法
ここまでくれば、再起動してrestart
install script にserviceとして登録されているため、勝手に起動されているハズ
今回の場合、 http://{your_ip}:8888 にアクセスすればOK

手動で立ち上げる時は、以下のコマンド
cape@sandbox:/opt/CAPEv2$ python3 cuckoo.py cape@sandbox:/opt/CAPEv2/web$ python3 manage.py runserver {your_ip}:8888
api serverを立ち上げる場合は以下を実行する
cape@sandbox:/opt/CAPEv2$ python3 ./utils/api.py --host 10.1.0.5 argument for 's' must be a bytes object Depricated in favour of /api/ that is integrated in webgui Bottle v0.12.18 server starting up (using WSGIRefServer())... Listening on http://10.1.0.5:8090/# portを指定しなければ8090となる Hit Ctrl-C to quit. 10.1.0.2 - - [14/Sep/2020 21:35:41] "POST /tasks/create/file HTTP/1.1" 200 38
2042ポート使ってるぜ〜と怒られる場合
cape@sandbox:/opt/CAPEv2$ python3 cuckoo.py __ .----..--.--..----.| |--..-----..-----. | __|| | || __|| < | _ || _ | |____||_____||____||__|__||_____||_____| Cuckoo Sandbox 2.1-CAPE www.cuckoosandbox.org Copyright (c) 2010-2015 CAPE: Config and Payload Extraction github.com/kevoreilly/CAPEv2 pywin32 is not installed (only is required if you want to use MS Excel) name 'Signature' is not defined name 'Signature' is not defined name 'Signature' is not defined 2020-09-01 07:34:35,784 [root] WARNING: Missing Yara directory: /opt/CAPEv2/data/yara/macro? 2020-09-01 07:34:35,819 [root] CRITICAL: CuckooCriticalError: Cannot bind ResultServer on port 2042 because it was in use, bailing.
2042がlistenしているかの確認memo
sudo lsof -i :2042 COMMAND PID USER FD TYPE DEVICE SIZE/OFF NODE NAME python3 5710 cape 11u IPv4 81663 0t0 TCP *:2042 (LISTEN)
これでおしまい。