Detux is a sandbox developed to do traffic analysis of the Linux malwares and capture the IOCs by doing so. QEMU hypervisor is used to emulate Linux (Debian) for various CPU architectures.
This release of Detux contains the script for executing a Linux binary/script in a specified CPU arch. Don't worry if you don't know what platform, it's in the script, the Magic package helps picking up the CPU arch in an automated way. x86 is the default CPU version, this can be tuned to a different one in the config file.
This release gives the analysis report in a DICT format, which can be easily customized to be inserted in to NOSQL dbs.
An example script has been provided which demonstrates the usage of the sandbox library.
What's in the report?
- Static Analysis
-- Basic strings extracted from binary
-- ELF information generated by readelf commands
-- the report.py can be modified to add more 3rd party commands to analyse the binary and add the result to DICT.
- Dynamic Analysis
-- The captured pcaps are parsed with DPKT to extract the IOC's and readable info from the packets.
Requirements
System packages
python 2.7
qemu
pcaputils
sudo
libcap2-bin
bridge-utils
Python libraries (Preferable to use virtual environment)
pexpect
paramiko
python-magic
Kindly make sure that the above requirements are met before using Detux. A few dependencies may vary from OS to OS.
Architecture
Host ( The host itself can be a VM or a baremetal machine)
QEMU
dumpcap
DETUX Scripts
Network Arch
- NIC1 : This interface is for accessing the Host
- NIC2 : Interface bridged with the the QEMU Sandbox VMs. One can redirect the traffic from the interface to WHONIX or REMNUX or a custom Gateway to filter/allow internet access for the Sandboxed VMs.
VM Setup:
Downloading Linux VM Images
Special thanks to aurel who has uploaded pre built QEMU Debian VM images for all possible CPU architectures.
The VM images are located at : https://people.debian.org/~aurel32/qemu/, the same link contains the command examples for invoking the vm images.
You can use the following script to automatically download the VM images to the "qemu" folder of Detux.
Detux uses SSH to communicate with the VMs and so, this is currently required for the VMs to have networking capability. Considering that the listed binaries are in the same path, you may add the following lines to to /etc/sudoers (only if you are a non-root user):
Change the paths to the binaries if they differ for you.
Network setup
Add the following config to /etc/qemu-ifup, backup the original if you already have one:
#! /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
Considering that eth0 is the interface you want your VMs to be bridged with, you may remove the configs for eth0 and use the following configs in /etc/network/interfaces:
auto br0
iface br0 inet dhcp
bridge_ports eth0
bridge_maxwait 0
You can also specify a static address you used for eth0.
Setting up your VMs
Traverse to the folder in which your VM images are located for each QEMU Images e.g. for ARM is :
<your detux folder>/qemu/arm/1/
For each image, follow the VM boot instructions given at "https://people.debian.org/~aurel32/", to start the VM. However, if you are a non-root user, you will have to use sudo.
Comands for Booting the VMs (Replace with the MAC you desire):
The following command may enable the same for you:
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
Keep in mind that you might have to logout and login again or reboot the host to apply the permissions.
If you are unable to capture packets or you get errors related to dumpcap, you need to check if permissions for your users are set correctly and the dumpcap path is right.
Detux Config
The detux.cfg files in the main directory needs to be configured. Each VM section has to be configured with correct Network Params and SSH credentials. You can choose root/non-root user depending on your need.
Running Detux
The Detux library located in "core" directory can be used to suit your need of analysis.
The repo contains "detux.py" which analyses the given binary and saves pcap in pcap folder and writes JSON output to a specified filepath.
Usage
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)
请发表评论