Detux是一个沙箱,用于对Linux恶意软件进行流量分析,并从中捕获IOC。它使用QEMU虚拟机管理程序来模拟不同CPU架构的Linux(Debian)。
目前支持以下CPU:
立即使用在线版本:http://detux.org
此版本的Detux包含用于在指定CPU架构下执行Linux二进制文件/脚本的脚本。如果你不知道平台类型也不必担心,脚本内已集成Magic包,可自动识别CPU架构。x86是默认的CPU版本,可在配置文件中调整为其他架构。
此版本以DICT格式输出分析报告,可轻松定制以插入到NoSQL数据库中。
提供了一个示例脚本,演示了沙箱库的使用方法。
- 静态分析
-- 从二进制文件中提取的基本字符串
-- 由readelf命令生成的ELF信息
-- 可修改report.py以添加更多第三方命令来分析二进制文件并将结果加入DICT
- 动态分析
-- 使用DPKT解析捕获的pcap文件,从中提取IOC及可读信息
系统包
Python库(建议使用虚拟环境)
请确保在运行Detux之前满足以上依赖。某些依赖可能因操作系统而异。
- NIC1:用于访问宿主的接口
- NIC2:与QEMU沙箱虚拟机桥接的接口。可将该接口的流量重定向至WHONIX、REMNUX或自定义网关,以过滤/允许沙箱虚拟机的互联网访问
特别感谢aurel,他已预先构建好所有可能CPU架构的QEMU Debian虚拟机镜像。 镜像位于:https://people.debian.org/~aurel32/qemu/,同一链接包含启动虚拟机镜像的命令示例。
你可以使用以下脚本自动下载虚拟机镜像到Detux的"qemu"文件夹。
#x86
wget https://people.debian.org/~aurel32/qemu/i386/debian_wheezy_i386_standard.qcow2 -P qemu/x86/1/
#x86-64
wget https://people.debian.org/~aurel32/qemu/amd64/debian_wheezy_amd64_standard.qcow2 -P qemu/x86-64/1/
#arm
wget https://people.debian.org/~aurel32/qemu/armel/debian_wheezy_armel_standard.qcow2 -P qemu/arm/1/
wget https://people.debian.org/~aurel32/qemu/armel/initrd.img-3.2.0-4-versatile -P qemu/arm/1/
wget https://people.debian.org/~aurel32/qemu/armel/vmlinuz-3.2.0-4-versatile -P qemu/arm/1/
#mips
wget https://people.debian.org/~aurel32/qemu/mips/vmlinux-3.2.0-4-4kc-malta -P qemu/mips/1/
wget https://people.debian.org/~aurel32/qemu/mips/debian_wheezy_mips_standard.qcow2 -P qemu/mips/1/
#mipsel
wget https://people.debian.org/~aurel32/qemu/mipsel/vmlinux-3.2.0-4-4kc-malta -P qemu/mipsel/1/
wget https://people.debian.org/~aurel32/qemu/mipsel/debian_wheezy_mipsel_standard.qcow2 -P qemu/mipsel/1/
Detux通过SSH与虚拟机通信,因此虚拟机需要具备网络能力。假设所列二进制文件位于同一路径,你可以将以下行添加到/etc/sudoers(仅限非root用户时):
Cmnd_Alias QEMU_CMD = /usr/bin/qemu-*, /sbin/ip, /sbin/ifconfig, /sbin/brctl
<your detux username here> ALL = (ALL) NOPASSWD: QEMU_CMD
如果二进制路径不同,请自行修改。
将以下配置添加到/etc/qemu-ifup(如有原文件请备份):
#! /bin/sh
# Script to bring a network (tap) device for qemu up.
# The idea is to add the tap device to the same bridge
# as we have default routing to.
# in order to be able to find brctl
PATH=$PATH:/sbin:/usr/sbin
ip=$(which ip)
ifconfig=$(which ifconfig)
echo "Starting" $1
if [ -n "$ip" ]; then
ip link set "$1" up
else
brctl=$(which brctl)
if [ ! "$ip" -o ! "$brctl" ]; then
echo "W: $0: not doing any bridge processing: neither ip nor brctl utility not found" >&2
exit 0
fi
ifconfig "$1" 0.0.0.0 up
fi
switch=$(ip route ls | \
awk '/^default / {
for(i=0;i<NF;i++) { if ($i == "dev") { print $(i+1); next; } }
}'
)
if [ -d /sys/class/net/br0/bridge/. ]; then
if [ -n "$ip" ]; then
ip link set "$1" master br0
else
brctl addif br0 "$1"
fi
exit # exit with status of the previous command
fi
echo "W: $0: no bridge for guest interface found" >&2
假设eth0是你要与虚拟机桥接的接口,你可以移除eth0的配置,并在/etc/network/interfaces中使用以下配置:
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_maxwait 0
你也可以指定你之前用于eth0的静态地址。
进入每个QEMU镜像所在的文件夹,例如ARM位于:
<your detux folder>/qemu/arm/1/
对于每个镜像,按照"https://people.debian.org/~aurel32/"给出的虚拟机启动指令启动虚拟机。但如果你是非root用户,需要使用sudo。
启动虚拟机的命令(将替换为你想要的MAC地址):
#x86
sudo qemu-system-i386 -hda qemu/x86/1/debian_wheezy_i386_standard.qcow2 -vnc 127.0.0.1:5901 -net nic,macaddr=<MACADDR> -net tap -monitor stdio
#x86-64
sudo qemu-system-x86_64 -hda qemu/x86-64/1/debian_wheezy_amd64_standard.qcow2 -vnc 127.0.0.1:5901 -net nic,macaddr=<MACADDR> -net tap -monitor stdio
#arm
sudo qemu-system-arm -M versatilepb -kernel qemu/arm/1/vmlinuz-3.2.0-4-versatile -initrd qemu/arm/1/initrd.img-3.2.0-4-versatile -hda qemu/arm/1/debian_wheezy_armel_standard.qcow2 -append "root=/dev/sda1" -vnc 127.0.0.1:5901 -net nic,macaddr=<MACADDR> -net tap -monitor stdio
#mips
sudo qemu-system-mips -M malta -kernel qemu/mips/1/vmlinux-3.2.0-4-4kc-malta -hda qemu/mips/1/debian_wheezy_mips_standard.qcow2 -append "root=/dev/sda1 console=tty0" -vnc 127.0.0.1:5901 -net nic,macaddr=<MACADDR> -net tap -monitor stdio
#mipsel
sudo qemu-system-mipsel -M malta -kernel qemu/mipsel/1/vmlinux-3.2.0-4-4kc-malta -hda qemu/mipsel/1/debian_wheezy_mipsel_standard.qcow2 -append "root=/dev/sda1 console=tty0" -vnc 127.0.0.1:5901 -net nic,macaddr=<MACADDR> -net tap -monitor stdio
Detux需要一个预先配置好IP地址和SSH设置的虚拟机快照。
(qemu)
(qemu) savevm init
(qemu) q
-- 对所有虚拟机重复步骤1
为了使非root用户能够抓包,Dumpcap需要捕获权限。(https://wiki.wireshark.org/CaptureSetup/CapturePrivileges)。
以下命令可能为你提供相应权限:
sudo groupadd -g wireshark
sudo usermod -a -G wireshark <your user name>
sudo chmod 750 /usr/bin/dumpcap
sudo setcap cap_net_raw,cap_net_admin=eip /usr/bin/dumpcap
请注意,你可能需要注销并重新登录或重启宿主机才能应用这些权限。如果你无法抓包或遇到与dumpcap相关的错误,请检查用户权限设置是否正确以及dumpcap路径是否正确。
需要配置主目录中的detux.cfg文件。每个虚拟机部分必须配置正确的网络参数和SSH凭据。你可以根据需要选择root或非root用户。
"core"目录中的Detux库可用于满足你的分析需求。 该仓库包含"detux.py",用于分析给定的二进制文件,将pcap保存到pcap文件夹,并将JSON输出写入指定文件路径。
usage: detux.py [-h] --sample SAMPLE [--cpu {x86,x86-64,arm,mips,mipsel}]
[--int {python,perl,sh,bash}] --report REPORT
optional arguments:
-h, --help show this help message and exit
--sample SAMPLE Sample path (default: None)
--cpu {x86,x86-64,arm,mips,mipsel}
CPU type (default: auto)
--int {python,perl,sh,bash}
Architecture type (default: None)
--report REPORT JSON report output path (default: None)
示例:
python detux.py --sample test_script/example_binary1 --report reports/example_report1.json
感谢Aurélien Jarno (@aurel32) (https://www.aurel32.net/) 提供的预构建虚拟机镜像。