A DarkNet (Tor) Traffic Feature Extraction Tool based on RustiFlow.
This tool is engineered for robust and efficient feature extraction, particularly for applications such as network intrusion detection systems, among others. Leveraging Rust language and eBPF, it excels in processing high volumes of network traffic with remarkable speed and throughput. (When your traffic is already captured, don't worry! It also has a build in pcap reader which is also amazingly fast.) With various pre-defined feature sets and the ability to create custom feature sets, DF offers a versatile solution for network security applications.
- High Throughput: Utilizes Rust and the Aya library for eBPF program compilation and execution, ensuring exceptional performance and resource efficiency.
- Versatile Feature Sets: Offers a variety of pre-defined feature sets (flows) and the flexibility to create custom feature sets tailored to specific requirements. An example of the custom flow is shown here.
- Pcap File Support: Facilitates packet analysis from pcap files, compatible with both Linux and Windows generated files.
- Diverse Output Options: Features can be outputted to the console, a CSV file, or other formats with minimal effort.
See the wiki for the different feature sets available.
project/
├─ common/ # Shared data structures
│ ├─ Cargo.toml
│ └─ src/lib.rs # `EbpfEventIp*`
│
├─ darkflow/ # User-space loader crate
│ ├─ Cargo.toml
│ └─ src/main.rs # Loader code
│ └─ ...
│
├─ ebpf-ipv4/ # Kernel eBPF crate (IPv4)
│ ├─ Cargo.toml
│ └─ src/main.rs # `#[no_std]` `#[no_main]` eBPF program
├─ ebpf-ipv6/ # Kernel eBPF crate (IPv6)
│ ├─ Cargo.toml
│ └─ src/main.rs # `#[no_std]` `#[no_main]` eBPF program
│
├─ xtask/ # Project automation crate
│ ├─ Cargo.toml
│ └─ src/main.rs # Custom tasks (Workflow for eBPF compilation)
│ └─ ...
Copy the darkflow binary that you can find in this repo in releases to a location of your choice or to the /usr/local/bin folder.
If it does not have the right permissions, you can run the following command:
chmod +x /path/to/darkflowYou can then run the binary with the following commands displayed on the help menu.
If you want a more graphical interface, you can use the tui interface by just running darkflow without any arguments. This will open a field where you can enter a configuration file you want to edit or you can choose to start new. After that, the following interface will show up:
NOTE: When using the save button, you will be prompted for a filename. You can reuse this file with following command:
darkflow --config-file <filename> realtime <interface> [--only-ingress]darkflow -c <filename> pcap <path to pcap file>
./target/release/darkflow -c ./config.toml pcap ./t.pcap After saving the configuration file, you can safely reset without changing the configuration file.
This is an example of a configuration file that you can use to run the tool with the --config-file option.
[config]
features = "Darkflow" # FlowType can be one of: Basic, CIC, CIDDS, Nfstream, RustiFlow, DarkFlow, Custom
active_timeout = 3600 # Maximum time a flow is allowed to last in seconds
idle_timeout = 120 # Maximum time with no packets for a flow in seconds
early_export = 300 # Optional, print interval for open flows in seconds
threads = 4 # Number of threads to use for processing packets, optional
expiration_check_interval = 60
[output]
output = "Csv" # OutputMethodType can be one of: Print, Csv
export_path = "output.csv" # Path for output if method is Csv
header = true # Whether to export the feature header
drop_contaminant_features = false # Whether to drop contaminant features
performance_mode = trueMake sure that you don't use docker desktop and that you don't have it installed on your machine. If you have this setup, it will not work as intended as the --network host will not link the container to the host network, but to the network of a VM that docker desktop uses.
- Build the Container:
docker build -t darkflow . - Run the Container:
Run it with the --privileged flag if you want to capture traffic in real-time.
docker run --network host -v /path/on/host:/app darkflow [ARGS like you are used to]
- Example:
docker run --network host -v /home/user/pcap:/app darkflow pcap basic-flow 60 /app/pcap.pcap print
docker run --privileged --network host -v /home/matisse/Documents:/app darkflow realtime enp5s0 cic-flow 60 csv /app/output.csv
Use ./setup.sh script directly to setup deps and ./build.sh to build darkflow binary is recommended!
- libpcap-dev:
sudo apt install libpcap-dev
- Rust Installation:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
- Nightly Rust Toolchain:
rustup install stable rustup toolchain install nightly --component rust-src
- For Linux x86_64:
cargo install bpf-linker
- For MacOS/Linux (Other Architectures):
brew install llvm cargo install --no-default-features bpf-linker
- Ubuntu 20.04 LTS Specific:
sudo apt install linux-tools-5.8.0-63-generic export PATH=/usr/lib/linux-tools/5.8.0-63-generic:$PATH
- eBPF Programs:
cargo xtask ebpf-ipv4 cargo xtask ebpf-ipv6 # or cargo xtask ebpf-ipv4 --release cargo xtask ebpf-ipv6 --release - User Space Programs:
cargo build # or cargo build --release
cargo xtask run -- [OPTIONS] <COMMAND>cargo test
cargo test -- --fail-fast
cargo test --no-rundarkflow helpUsage: darkflow [OPTIONS] <COMMAND>
Commands:
realtime Real-time feature extraction
pcap Feature extraction from a pcap file
help Print this message or the help of the given subcommand(s)
Options:
-c, --config-file <CONFIG_FILE>
Configuration file path
-f, --features <FEATURES>
The feature set to use (required if no config file is provided)
Possible values:
- basic: A basic flow that stores the basic features of a flow
- cic: Represents the CIC Flow, giving 83 features
- cidds: Represents the CIDDS Flow, giving 10 features
- nfstream: Represents a nfstream inspired flow, giving 69 features
- rustiflow: Represents the Rusti Flow, giving 120 features
- custom: Represents a flow that you can implement yourself
--active-timeout <ACTIVE_TIMEOUT>
The maximum time a flow is allowed to last in seconds (optional)
[default: 3600]
--idle-timeout <IDLE_TIMEOUT>
The maximum time with no packets for a flow in seconds (optional)
[default: 120]
--early-export <EARLY_EXPORT>
The print interval for open flows in seconds (optional)
--expiration-check-interval <EXPIRATION_CHECK_INTERVAL>
Interval (in seconds) for checking and expiring flows in the flowtable. This represents how often the flowtable should be scanned to remove inactive flows
[default: 60]
--threads <THREADS>
The numbers of threads to use for processing packets (optional) (default: 5, maximum number of logical CPUs)
-o, --output <OUTPUT>
Output method (required if no config file is provided)
Possible values:
- print: The output will be printed to the console
- csv: The output will be written to a CSV file
--export-path <EXPORT_PATH>
File path for output (used if method is Csv)
--header
Whether to export the feature header
--drop-contaminant-features
Whether to drop contaminant features
-h, --help
Print help (see a summary with '-h')
-V, --version
Print version
RUST_LOG=info cargo xtask run --sudo RUST_LOG=info darkflowNote: For specific logging levels, adjust RUST_LOG to error for error messages, and debug for debug messages. If you don't want any additional logs, just remove RUST_LOG=info.