How ntu168108/realtime-packet-sniff-v2 works
1. Overall shape
- This repo is a Linux packet-sniffing and IDS platform built around one capture engine with multiple front ends and processing modes.
- The core product is the sniff CLI; around it are a TUI/interactive UI, a background daemon, a live NDJSON stream mode, and an extended web GUI.
2. Capture and packet-processing core
- The core/ package is the runtime heart of the system.
- It contains the packet acquisition and buffering path (capture, buffer, rotator, pcap_writer, native_writer), packet decoding and filtering (decoder, display_filter), and shared constants.
- This layer is the boundary between raw network traffic and all higher-level consumers.
3. CLI and daemon boundary
- sniff.py and the cli/ package provide the user-facing entrypoints.
- The CLI supports interactive and daemonized operation, with helper code for printing live output, menus, and shell-facing behavior.
- The daemon path is the bridge from capture into long-running background processing and service installation.
4. Terminal UI
- The ui/ package provides the local interactive screen layer: list/detail views, menu handling, and color formatting.
- It sits on top of the capture/decoder outputs and is concerned with presentation rather than packet processing.
5. Plugin/module architecture
- modules/ contains a generic runner and a base module abstraction, suggesting pluggable analysis stages.
- The included modules/dummy is a minimal example, but the structure implies the system can dispatch captured data into additional analyzers without changing the core capture path.
6. File rotation and pcap stream output
- The core writes packet data into rotating pcap segments, which are the handoff artifact for downstream pipelines.
- This is important architecturally because it decouples capture from later IDS processing, allowing live capture to continue while consumers process segments asynchronously.
7. IDS / feature-extraction pipeline
- integration/ and Extraction-and-classification/ together implement the higher-tier IDS workflow.
- The flow is: pcap segments are consumed, features are extracted with Argus and Zeek, normalized/mapped/merged, then classified.
- Extraction-and-classification/MODULE_TRICHXUAT is the extraction stage, while MODULE_PHANLOAI is the classification stage.
8. Classification subsystem
- MODULE_PHANLOAI performs UNSW-NB15-style attack-family classification.
- It includes baseline filtering, family filtering, a DoS-specific classifier, and JSON signature sets for attack families such as reconnaissance, exploits, fuzzers, shellcode, generic, and analysis.
- This layer is rule/model-driven and is separate from packet capture or feature extraction.
9. Streaming infrastructure for the IDS path
- The integration/ package models the production data plane: pcap segmentation, Kafka segment transport, an ec_consumer, and ClickHouse sink logic.
- This shows the architecture is event-driven: capture produces segments, Kafka distributes them, consumers transform/store results, and ClickHouse persists analytics data.
- sql/clickhouse_init.sql provides the storage schema bootstrapping for that analytics backend.
10. Web GUI subsystem
- sniff-web/ is a separate frontend stack with its own Python server plus a React/TypeScript/Vite app.
- It talks to backend services for capture control, Kafka, ClickHouse, and websocket/live updates, and is backed by its own integration and end-to-end tests.
- This is a distinct presentation boundary from the TUI, aimed at browser-based operations and observability.
11. Operational deployment
- deploy/, scripts/, and sniff-web/deploy/ contain systemd units, Kafka/Grafana deployment assets, and install/uninstall helpers.
- The repo is designed to run both as a local capture tool and as a multi-service stack with Kafka, ClickHouse, Grafana, Argus, and Zeek in the IDS deployment.
12. Configuration, docs, and verification
- Configuration is split across examples like config.yaml.example, .env.example, and package-specific config modules.
- docs/ and the MkDocs setup document the architecture, installation, and operations, while tests/ and the various integration suites validate capture, segmentation, storage, and web behavior across subsystem boundaries.
Main entry points: app.py CLI app · capture.py Capture core · decoder.py Decode/filter · kafka_segmenter.py Kafka transport
Components 24
Capture runtime
Core packet acquisition, decoding, and local presentation
- sniff CLI · Primary command-line entrypoint for the tool
sniff.py - CLI app · User-facing CLI orchestration and modes
cli/app.py - Daemon mode · Background service and install-time execution path
cli/daemon.py - TUI layer · Interactive menu, list, detail, and color presentation
ui/menu.py - Capture core · Acquires packets and drives the capture lifecycle
core/capture.py - Buffering · Holds captured packets before downstream handling
core/buffer.py - Decode/filter · Packet decoding and display filtering
core/decoder.py - Rotation · Rotates capture output into manageable segments
core/rotator.py - PCAP writer · Writes packet capture segments for downstream consumers
core/pcap_writer.py - Native writer · Alternative low-level packet output path
core/native_writer.py - Display rules · Shared filtering constants and predicates
core/display_filter.py
IDS pipeline
Segment transport, feature extraction, classification, and analytics storage
- Pcap segmenter · Breaks rotated PCAP into transportable segments
integration/pcap_segment.py - Kafka transport · Publishes and routes capture segments through Kafka
integration/kafka_segmenter.py - EC consumer · Consumes segments and performs downstream processing
integration/ec_consumer.py - ClickHouse sink · Stores processed analytics into ClickHouse
integration/clickhouse_sink.py - Feature extract · Argus/Zeek extraction and feature merging
Extraction-and-classification/MODULE_TRICHXUAT/extractor.py - Attack classify · Rule and model driven UNSW-NB15 family classification
Extraction-and-classification/MODULE_PHANLOAI/baseline_filter.py
Web GUI
Browser frontend and its server boundary
- Web server · Python server boundary for the browser GUI
sniff-web/web_server.py - React app · TypeScript/Vite frontend for monitoring and control
sniff-web/web/src/App.tsx
Operations
Deployment, service units, and database bootstrap
- Schema init · Bootstraps ClickHouse storage schema
sql/clickhouse_init.sql - Deploy assets · Systemd, Kafka, Grafana, and install scripts
deploy/systemd/sniff-producer.service
Plugins
Pluggable analysis module framework
- Module runner · Dispatches captured data into pluggable analyzers
modules/runner.py - Module API · Base abstraction for analysis modules
modules/base.py - Dummy module · Minimal example analysis module
modules/dummy/analyze.py
Connections 28
- sniff CLI → CLI app: launches · CLI entrypoint starts application flow
- CLI app → Capture core: starts capture · CLI drives the runtime capture engine
- CLI app → Daemon mode: daemon mode · CLI can hand off to background service behavior
- CLI app → TUI layer: interactive UI · CLI routes interactive sessions into the TUI
- Capture core → Buffering: buffers · Captured packets are staged in memory
- Buffering → Decode/filter: decodes · Buffered traffic is decoded and filtered
- Decode/filter → Display rules: applies rules · Display and packet filtering constrain what is surfaced
- Capture core → Rotation: rotates · Capture output is segmented for downstream use
- Rotation → PCAP writer: writes pcap · Rotated segments are persisted as PCAP artifacts
- Capture core → Native writer: writes native · Alternative low-level writer path
- Decode/filter → TUI layer: feeds views · Decoded packets power the interactive terminal display
- Decode/filter → Module runner: dispatches · Decoded data can be sent to analysis modules
- Module runner → Module API: implements · Runner depends on the shared module contract
- Module runner → Dummy module: example module · Repository includes a minimal plugin implementation
- PCAP writer → Pcap segmenter: handoff · PCAP files become segment inputs for the IDS pipeline
- Pcap segmenter → Kafka transport: publishes · Segmented captures are distributed over Kafka
- Kafka transport → EC consumer: consumed by · Consumers read segmented traffic from the message layer
- EC consumer → ClickHouse sink: stores · Processed events are written into ClickHouse
- ClickHouse sink → Schema init: bootstraps · Sink relies on the schema initialization script
- Pcap segmenter → Feature extract: feeds features · Segment artifacts drive feature extraction
- Feature extract → Attack classify: classifies · Extracted features are passed to attack-family classification
- PCAP writer → Feature extract: offline input · PCAP output can be consumed by the extraction pipeline
- Web server → React app: serves · Python backend serves the browser frontend
- React app → Kafka transport: live ops · Web UI surfaces Kafka-backed pipeline state
- React app → ClickHouse sink: analytics UI · Frontend reads analytics results from ClickHouse-backed services
- Deploy assets → Daemon mode: installs · Operational assets wire the daemonized runtime into the host
- Deploy assets → Web server: deploys · Deployment assets support the web frontend stack
- Deploy assets → Kafka transport: provisions · Deployment includes Kafka and related service config