Skip to content

giorgiozoppi/agentic-nids

Repository files navigation

Agentic Network Intrusion Detection System (NIDS)

AI-Powered Network Security with Explainable Machine Learning

A modern, Python-based Network Intrusion Detection System using Google's Agent2Agent (A2A) Protocol, ONNX ML models, and explainable AI for real-time threat detection and analysis.

🌟 Features

  • πŸ€– Agent2Agent Protocol - Google's A2A protocol with gRPC streaming
  • 🧠 ML-Powered Detection - ONNX models for attack classification
  • πŸ“Š Real-time Dashboard - Vue.js security monitoring UI
  • πŸ” Explainable AI - Feature importance and human-readable explanations
  • βš™οΈ Configurable - YAML-based configuration (3-minute collection intervals)
  • ☸️ Kubernetes Ready - Production-grade Helm charts
  • πŸ”„ Auto-scaling - HPA for classifier and UI components

πŸ—οΈ Architecture

flowchart LR
    subgraph Network
        A[Traffic Capture]
    end
    subgraph Python Agents
        B[nDPI Collector Agent]
        C[Classifier Agent]
    end
    subgraph ML & AI
        D[ONNX Models]
        E[Anomaly Detection]
        F[Risk Assessment]
    end
    subgraph UI
        G[Vue.js Dashboard]
    end

    A -->|Packets| B
    B -->|A2A Protocol/gRPC| C
    C --> D
    C --> E
    C --> F
    C -->|Results| G
Loading

πŸ“‹ Prerequisites

  • Python 3.11+ - For ML/AI agents
  • uv - Python package manager (or pip)
  • Docker - For containerization (optional)
  • Kubernetes - For production deployment (optional)
  • Node.js 18+ - For UI development (optional)

πŸš€ Quick Start

1. Install Dependencies

cd agent
uv pip install -e ".[all]"

# Or with pip
pip install -e ".[all]"

2. Run Quick Test

# Test with synthetic data
python main.py --mode test

3. Analyze PCAP File

# Process a PCAP file
python main.py --mode pcap --pcap /path/to/traffic.pcap --interval 60

4. Live Capture

# Capture live traffic (requires sudo)
sudo python main.py --mode live --interface eth0 --interval 180

πŸ“Š System Components

1. Classifier Agent (A2A Server)

Receives flows and performs ML-based classification:

# Run standalone classifier
python main.py --mode classifier --port 50051

Features:

  • ONNX model inference
  • Attack type detection (DoS, DDoS, port scan, malware, etc.)
  • Anomaly detection
  • Risk scoring (0-1 scale)
  • Explainable AI with feature importance

2. nDPI Collector Agent (A2A Client)

Collects network flows and sends to classifier:

# Run standalone collector
python main.py --mode collector --config config/ndpi_agent.yaml

Features:

  • Packet capture (live/PCAP)
  • Flow aggregation (configurable interval)
  • nDPI protocol detection
  • Batch processing
  • Alert management

3. Security Dashboard (Vue.js UI)

Real-time threat visualization:

cd agent/ui
npm install
npm run dev

Features:

  • Real-time threat alerts
  • Risk level visualization
  • Threat details and explanations
  • Recommended actions
  • Filter by risk level

βš™οΈ Configuration

YAML Configuration

Edit agent/config/ndpi_agent.yaml:

# Collection interval (seconds)
collection_interval: 180  # 3 minutes

# Classifier connection
classifier_agent_url: "grpc://localhost:50051"

# Alert settings
alert_threshold: 0.7  # Risk score 0-1
auto_block: false     # Enable auto-blocking

# Processing
batch_size: 100
max_concurrent_requests: 10

Pre-configured Templates

  • config/ndpi_agent.yaml - Default configuration
  • config/ndpi_agent_live.yaml - Live capture optimized
  • config/ndpi_agent_pcap.yaml - PCAP analysis optimized

🐳 Docker Deployment

Build Docker images:

# Classifier
docker build -t jozoppi/classifier:1.0 -f docker/Dockerfile.classifier .

# Collector
docker build -t jozoppi/ndpi-collector:1.0 -f docker/Dockerfile.collector .

# UI
docker build -t jozoppi/nids-ui:1.0 -f docker/Dockerfile.ui ./agent/ui

☸️ Kubernetes Deployment

Deploy to Kubernetes cluster:

cd infra/helm

# Install Helm chart
helm install agentic-nids ./agentic-nids \
  --namespace nids \
  --create-namespace

# Access UI
kubectl get svc agentic-nids-ui -n nids

Services Exposed:

  • UI: LoadBalancer on port 80 (accessible externally)
  • Classifier: ClusterIP on port 50051 (internal gRPC)
  • Collector: ClusterIP on port 8000 (internal)

See infra/README.md for detailed deployment guide.

πŸ“– Documentation

πŸ§ͺ Testing

Test Modes

# Quick synthetic test
python main.py --mode test

# PCAP analysis
python main.py --mode pcap --pcap data/sample.pcap

# Live capture
sudo python main.py --mode live --interface eth0

🎯 Use Cases

  1. Network Monitoring - Real-time threat detection
  2. PCAP Analysis - Offline traffic analysis
  3. Security Research - ML model evaluation
  4. Incident Response - Threat investigation
  5. Compliance - Security audit trails

πŸ“Š Attack Types Detected

  • DoS/DDoS - Denial of Service attacks
  • Port Scan - Network reconnaissance
  • Brute Force - Authentication attacks
  • Malware - C&C communication
  • Botnet - Coordinated attacks
  • SQL Injection - Database attacks
  • XSS - Cross-site scripting
  • Probe - Network mapping

πŸ”¬ ML Models

The system uses ONNX format for ML models:

  • Primary Model: Flow classifier (XGBoost/Random Forest)
  • Anomaly Detection: Isolation Forest
  • Risk Assessment: Ensemble scoring

Training Custom Models

See agent/README.md for model training guide.

πŸ”§ Development

Project Structure

agentic-nids/
β”œβ”€β”€ agent/                      # Python agents
β”‚   β”œβ”€β”€ classifier_agent_a2a.py # Classifier (A2A server)
β”‚   β”œβ”€β”€ ndpi_collector_agent.py # Collector (A2A client)
β”‚   β”œβ”€β”€ main.py                 # Main entry point
β”‚   β”œβ”€β”€ config/                 # YAML configurations
β”‚   β”œβ”€β”€ ui/                     # Vue.js dashboard
β”‚   └── pyproject.toml          # Python dependencies
β”œβ”€β”€ infra/                      # Kubernetes infrastructure
β”‚   └── helm/                   # Helm charts
β”‚       └── agentic-nids/
β”œβ”€β”€ nDPI/                       # nDPI library (submodule)
└── README.md                   # This file

Contributing

  1. Fork the repository
  2. Create feature branch (git checkout -b feature/amazing-feature)
  3. Commit changes (git commit -m 'Add amazing feature')
  4. Push to branch (git push origin feature/amazing-feature)
  5. Open Pull Request

πŸ” Security

  • Network policies enabled by default
  • Pod security contexts
  • Read-only root filesystem
  • Non-root user execution
  • TLS/HTTPS support

πŸ“š References

Research Papers:

Technologies:

πŸ“ License

MIT License - See LICENSE file for details

πŸ‘₯ Authors

Agentic NIDS Team

πŸ™ Acknowledgments

  • nDPI team for deep packet inspection library
  • Google for A2A Protocol
  • ONNX Runtime team
  • Open source ML/security community

πŸ“ž Support


Built with ❀️ for Network Security

About

Agentic Network Intrusion Detection

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors