traffic_capture module provides a Python wrapper around tcpdump for capturing network traffic to PCAP files. It handles process management, output path resolution, and filename generation with evasion profile labels.
Functions
start_capture()
Start a tcpdump process to capture network packets on a specified interface.interface(str): Network interface to capture on (e.g.,eth0,wlan0)output_file(str): Output PCAP filename (automatically placed inpcaps/directory)bpf_filter(str, optional): BPF filter expression. Default:'tcp port 443'
subprocess.Popen: The running tcpdump process
RuntimeError: If tcpdump is not found on PATH
stop_capture()
Terminate a running tcpdump process and wait for it to exit cleanly.proc(subprocess.Popen): The tcpdump process returned bystart_capture()
- None
- Sends SIGTERM to the process
- Waits up to 5 seconds for graceful exit
- Sends SIGKILL if timeout expires
- Logs warnings if process already exited or had to be force-killed
label_capture()
Generate a timestamped PCAP filename with evasion profile parameters embedded.base_name(str): Base name prefix for the capture fileprofile(EvasionProfile): Evasion profile containing jitter and padding parameters
str: Formatted filename with pattern:{base_name}_jitter{pct}_pad{max}_{timestamp}.pcap
Constants
DEFAULT_BPF_FILTER
Default BPF filter for HTTPS traffic:CAPTURE_DIR
Default directory for storing PCAP files:UTC_PLUS_7
Timezone object for UTC+7 (Southeast Asia):Helper Functions
timestamp_utc7()
Generate current timestamp in UTC+7 formatted for filenames.str: Timestamp in formatYYYYMMDD_HHMMSS
ensure_capture_dir()
Create the capture directory if it does not exist.resolve_output_path()
Ensure capture directory exists and return full path inside it.filename(str): Output filename
str: Full path withinCAPTURE_DIR
Command-Line Usage
The module can be run standalone:Requirements
- tcpdump must be installed and available on PATH
- Root/sudo privileges required on Linux for packet capture
- Depends on:
common.logger,transport.traffic_profile
Notes
- All captures are automatically stored in the
pcaps/directory - The module uses structured logging via
common.logger - Process stderr is captured for error reporting
- Handles SIGINT/SIGTERM for clean shutdown