Skip to content

m4rba4s/Aegis-eBPF

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

123 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Aegis: eBPF Security Matrix

Logo

High-Performance XDP/TC Firewall & Traffic Analyzer written in Rust. Zero-overhead packet filtering, stateful connection tracking, and heuristic intrusion detection.

License Rust eBPF

Screenshot

Preview

Preview

Preview

Overview

Aegis is a next-generation firewall built on eBPF (Extended Berkeley Packet Filter), XDP (eXpress Data Path), and TC (Traffic Control). It operates at the earliest possible point in the networking stack, filtering both ingress and egress traffic before the OS kernel processes it.

Why Aegis?

Feature iptables/nftables Aegis
Packet processing Kernel netfilter XDP (driver level)
Performance ~1M pps 10M+ pps ¹
Egress filtering Yes Yes (TC)
Connection tracking Conntrack module Native eBPF
Real-time TUI No Yes
Memory safety C Rust
Deployment Multiple packages Single binary

¹ Theoretical throughput for XDP in NIC driver mode with minimal rule set. Actual performance depends on NIC driver, kernel version, rule complexity, and hardware. Independent benchmarks pending.

Features

Core

  • XDP Ingress Filtering — Drop packets at NIC driver level
  • TC Egress Filtering — Block outbound connections to malicious destinations
  • Stateful Connection Tracking — Native eBPF conntrack (no kernel module)
  • CIDR Blocklists — LPM Trie for efficient prefix matching
  • IPv4 + IPv6 Support — Dual-stack filtering with extension header security
  • IP Allowlist — Trusted IPs bypass all checks (config-driven)

Detection & Mitigation

  • Port Scan Detection — Bitmap-based unique port tracking with auto-ban
  • SYN Flood Protection — Token bucket rate limiting (XDP layer)
  • TCP Anomaly Detection — Xmas, Null, SYN+FIN scans
  • TLS ClientHello Fingerprinting — Native eBPF TLS payload extraction for JA3 scoring
  • Dynamic Auto-Ban (OODA Loop) — O(1) lock-free userspace threat mitigation
  • ConnTrack Garbage Collection — Clock-synced map cleanup preventing state exhaustion

Interface

  • Interactive TUI (fd-isolated — zero stdout pollution):
    • Connections view with offline GeoIP lookup (MaxMind GeoLite2)
    • Live statistics with sparklines (packets/sec, drops/sec)
    • Security event log
    • ISP/Geo/Country display per connection
  • Module Hotkeys — Toggle PortScan, RateLimit, Threats, ConnTrack, ScanDetect, Verbose on-the-fly
  • Space-to-Ban — One-key IP blocking from connections list
  • Daemon Mode — Background operation with stdout log printer
  • JSON Logging — Machine-readable output for SIEM integration
  • Shell Completions — bash, zsh, fish, PowerShell, elvish

Operations

  • TOML Config File/etc/aegis/config.toml for persistent settings
  • Threat Feeds — Download and load CIDR blocklists from public sources
  • Save/Restore — Persist and reload block rules
  • Status Command — Query running daemon state via pinned BPF maps
  • Single Binary — eBPF bytecode embedded, no external files
  • Multi-Distro Installer — Fedora, Ubuntu, Debian, Arch, Alpine
  • Auto XDP Mode — Automatic fallback from driver to SKB mode
  • Systemd Integration — Hardened service file with CAP_BPF + CAP_NET_ADMIN

Installation

Prerequisites

  • Linux Kernel >= 5.4 (5.8+ recommended for CAP_BPF)
  • Root privileges (for eBPF loading)

Quick Install (Recommended)

One-Line Install (SSH/Remote)

curl -sSfL https://raw.githubusercontent.com/m4rba4s/Aegis-eBPF/main/install.sh | sudo bash

Manual Install

# Clone and install
git clone https://github.com/m4rba4s/Aegis-eBPF.git
cd Aegis-eBPF
sudo ./install.sh

The installer will:

  • Detect your distro and install dependencies
  • Build from source (or use pre-built if available)
  • Install systemd service
  • Create config directories

Run Without Installing

# Build
cargo run -p xtask -- build-all --profile release
cargo build --release -p aegis-cli

# Run (eBPF is embedded in binary)
sudo ./target/release/aegis-cli -i eth0 tui

Docker Build

# Build release binaries in Docker
docker build --output=dist .

# Outputs:
# dist/aegis-cli     - Main binary (eBPF embedded)
# dist/aegis         - Standalone XDP object (optional)
# dist/aegis-tc      - Standalone TC object (optional)

Usage

TUI Mode (Recommended)

sudo aegis-cli -i eth0 tui
sudo aegis-cli -i wg0 tui           # VPN interface
sudo aegis-cli -i eth0 --no-tc tui  # XDP only, no egress filtering

Controls:

Key Action
Tab Switch tabs (Connections / Stats / Logs)
↑/↓ or j/k Navigate list
Space Block/Unblock selected IP
1-5 Toggle modules (PortScan, RateLimit, Threats, ConnTrack, ScanDetect)
6 Toggle verbose logging
0 Toggle ALL modules
q Quit

Daemon Mode

# Start as background service
sudo systemctl start aegis@eth0

# Or run directly
sudo aegis-cli -i eth0 daemon

CLI Mode

sudo aegis-cli -i eth0 load
# Interactive commands:
# block 1.2.3.4
# unblock 1.2.3.4
# list
# save / restore

Rule File

aegis.yaml supports ingress source blocks and TC egress destination blocks:

rules:
  - ip: 198.51.100.10
    port: 443
    proto: tcp

egress_rules:
  - ip: 203.0.113.20
  - ip: 2001:db8::20

egress_cidrs:
  - cidr: 203.0.113.0/24
  - cidr: 2001:db8:bad::/48

Override Embedded eBPF (Advanced)

# Use custom eBPF objects instead of embedded
sudo aegis-cli \
  --ebpf-path /custom/path/aegis.o \
  --tc-path /custom/path/aegis-tc.o \
  -i eth0 tui

Architecture

┌─────────────────────────────────────────────────────────────┐
│                      KERNEL SPACE                            │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────┐           ┌─────────────┐                  │
│  │  aegis-ebpf │           │  aegis-tc   │                  │
│  │   (XDP)     │           │ (TC Egress) │                  │
│  │  INGRESS    │           │  EGRESS     │                  │
│  └──────┬──────┘           └──────┬──────┘                  │
│         │                         │                          │
│         └──────────┬──────────────┘                          │
│                    ▼                                         │
│  ┌─────────────────────────────────────────────────────┐    │
│  │                BPF MAPS / RING BUFFERS               │    │
│  │  BLOCKLIST | CONFIG | STATS | FEEDS | TC CONN_TRACK │    │
│  └─────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────┘
                           │
                           ▼ BPF RingBuf
┌─────────────────────────────────────────────────────────────┐
│                      USER SPACE                              │
├─────────────────────────────────────────────────────────────┤
│  ┌─────────────────────────────────────────────────────┐    │
│  │            aegis-cli (Rust/Tokio)                    │    │
│  │  ┌──────────────────────────────────────────────┐   │    │
│  │  │  EMBEDDED eBPF BYTECODE (XDP + TC objects)   │   │    │
│  │  └──────────────────────────────────────────────┘   │    │
│  │  ┌─────────┐  ┌─────────┐  ┌─────────────────┐     │    │
│  │  │   TUI   │  │  Event  │  │  Map Management │     │    │
│  │  │(ratatui)│  │  Loop   │  │  (aya)          │     │    │
│  │  └─────────┘  └─────────┘  └─────────────────┘     │    │
│  └─────────────────────────────────────────────────────┘    │
└─────────────────────────────────────────────────────────────┘

Project Structure

Aegis-eBPF/
├── aegis-common/       # Shared types (Single Source of Truth)
│   └── src/lib.rs      # PacketLog, Stats, FlowKey, threat/reason constants
├── aegis-ebpf/         # XDP ingress program (no_std, eBPF target)
│   └── src/main.rs     # Packet filtering, rate limiting, scan detection, TLS parsing
├── aegis-tc/           # TC egress program
│   └── src/main.rs     # Outbound connection blocking
├── aegis-cli/          # Userspace controller
│   ├── build.rs        # Embeds eBPF bytecode at compile time
│   ├── src/main.rs     # Application bootstrapper
│   ├── src/event_loop.rs # MPSC Lock-Free Perf Event consumers
│   ├── src/loader.rs   # eBPF/TC program lifecycles
│   ├── src/map_manager.rs # Map pinning, sizing, and threat feeds
│   ├── src/conntrack_gc.rs # Ktime-synced map garbage collection
│   ├── src/tui/        # Terminal UI (ratatui, fd-isolated)
│   ├── src/config.rs   # TOML config parser
│   ├── src/geo.rs      # Offline GeoIP (MaxMind GeoLite2)
│   ├── src/compat.rs   # Kernel capability detection
│   └── src/feeds/      # Threat feed parser/downloader
├── guide/              # Operational & Architectural Engineering Guides
├── deploy/             # Systemd service files
├── Dockerfile          # Reproducible builds
└── install.sh          # Multi-distro installer

Contributing

PRs welcome! Please ensure:

  1. cargo fmt passes
  2. cargo clippy has no warnings
  3. eBPF programs compile with cargo run -p xtask -- build-all

Disclaimer

This tool is intended for defensive security research and system hardening. The author is not responsible for any misuse.

License

MIT


Crafted with Rust & eBPF

About

High-Performance XDP Firewall & Traffic Analyzer written in Rust.

Resources

License

Stars

Watchers

Forks

Packages

 
 
 

Contributors