| Crates.io | leviathan-driver |
| lib.rs | leviathan-driver |
| version | 0.1.0 |
| created_at | 2025-11-30 12:25:48.393668+00 |
| updated_at | 2025-11-30 12:25:48.393668+00 |
| description | Windows kernel-mode EDR/XDR driver framework in Rust - callbacks, filters, detection, forensics |
| homepage | |
| repository | https://github.com/anubhavg-icpl/leviathan |
| max_upload_size | |
| id | 1958175 |
| size | 336,266 |
Windows kernel-mode driver framework for building EDR/XDR solutions in Rust using Microsoft's windows-drivers-rs.
Leviathan is a comprehensive KMDF (Kernel-Mode Driver Framework) driver providing all the kernel-mode components needed to build an Endpoint Detection and Response (EDR) or Extended Detection and Response (XDR) solution. It serves as a foundation for security monitoring, threat detection, and forensic analysis on Windows systems.
For detailed architecture documentation, see ARCHITECTURE.md.
| Category | Components | Description |
|---|---|---|
| Telemetry | Callbacks, Filters, ETW | Real-time system activity monitoring |
| Detection | Rules, Behavioral, Heuristics | Multi-layered threat detection engine |
| Protection | ELAM, Integrity, Hooks | System and self-protection mechanisms |
| Forensics | Pool Scanner, Enumeration, IRP | Memory forensics and rootkit detection |
| Communication | Ring Buffer, Shared Memory | High-performance kernel-user IPC |
leviathan/
├── crates/
│ ├── leviathan-driver/ # Kernel-mode driver (cdylib)
│ │ ├── src/
│ │ │ ├── lib.rs # Driver entry point
│ │ │ ├── device.rs # Device management
│ │ │ ├── ioctl.rs # IOCTL handlers
│ │ │ ├── callbacks/ # Kernel callbacks
│ │ │ │ ├── process.rs # PsSetCreateProcessNotifyRoutineEx
│ │ │ │ ├── thread.rs # PsSetCreateThreadNotifyRoutine
│ │ │ │ ├── image.rs # PsSetLoadImageNotifyRoutine
│ │ │ │ ├── registry.rs # CmRegisterCallbackEx
│ │ │ │ └── object.rs # ObRegisterCallbacks
│ │ │ ├── filters/ # Kernel filters
│ │ │ │ ├── minifilter.rs # Filesystem minifilter
│ │ │ │ └── network.rs # WFP network filter
│ │ │ ├── security/ # Security modules
│ │ │ │ ├── elam.rs # Early Launch Anti-Malware
│ │ │ │ ├── apc.rs # APC injection utilities
│ │ │ │ ├── integrity.rs # Anti-tampering, DKOM detection
│ │ │ │ └── hooks.rs # Hook detection (SSDT/IDT/inline)
│ │ │ ├── detection/ # Detection engine
│ │ │ │ ├── mod.rs # Detection engine core
│ │ │ │ ├── rules.rs # Rule-based detection
│ │ │ │ ├── behavior.rs # Behavioral analysis
│ │ │ │ └── heuristics.rs # Heuristic detection
│ │ │ ├── forensics/ # Forensics modules
│ │ │ │ ├── pool_scanner.rs # Pool tag scanning
│ │ │ │ ├── process_enum.rs # Multi-method enumeration
│ │ │ │ ├── irp_analysis.rs # Device stack analysis
│ │ │ │ └── memory_scanner.rs # Signature/pattern scanning
│ │ │ └── utils/ # Utilities
│ │ │ ├── timer.rs # DPC, timers, work items
│ │ │ ├── memory.rs # Pool allocations, MDL
│ │ │ ├── sync.rs # Spinlocks, mutexes, events
│ │ │ ├── etw.rs # Event Tracing for Windows
│ │ │ └── comm.rs # Kernel-user communication
│ │ └── build.rs # WDK build configuration
│ └── leviathan-common/ # Shared types (no_std)
├── ARCHITECTURE.md # Detailed architecture documentation
├── .cargo/config.toml # Cargo build settings
├── Makefile.toml # cargo-make tasks
├── rust-toolchain.toml # Nightly toolchain config
└── Cargo.toml # Workspace manifest
┌─────────────────────────────────────────────────────────────────┐
│ USER MODE (Ring 3) │
│ ┌─────────────────────────────────────────────────────────┐ │
│ │ User-Mode Agent (PPL) │ │
│ │ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ │ │
│ │ │ Event │ │ Rule │ │Behavior │ │ YARA │ │ │
│ │ │Processor│ │ Engine │ │Analyzer │ │ Scanner │ │ │
│ │ └─────────┘ └─────────┘ └─────────┘ └─────────┘ │ │
│ └──────────────────────────┬──────────────────────────────┘ │
│ │ Ring Buffer / Shared Memory │
├─────────────────────────────┼───────────────────────────────────┤
│ KERNEL MODE (Ring 0) │
│ ┌──────────────────────────┴──────────────────────────────┐ │
│ │ Leviathan Driver │ │
│ │ ┌────────────────────────────────────────────────────┐ │ │
│ │ │ Telemetry Collection │ │ │
│ │ │ Process │ Thread │ Image │ Registry │ Object │ │ │
│ │ │ Callback│Callback│Callback│ Callback │ Callback │ │ │
│ │ └────────────────────────────────────────────────────┘ │ │
│ │ ┌────────────────────────────────────────────────────┐ │ │
│ │ │ Kernel Filters │ │ │
│ │ │ Minifilter │ WFP Network │ │ │
│ │ └────────────────────────────────────────────────────┘ │ │
│ │ ┌────────────────────────────────────────────────────┐ │ │
│ │ │ Security & Protection Layer │ │ │
│ │ │ ELAM │ Integrity │ Hook Detection │ APC │ │ │
│ │ └────────────────────────────────────────────────────┘ │ │
│ │ ┌────────────────────────────────────────────────────┐ │ │
│ │ │ Forensics Engine │ │ │
│ │ │ Pool Scanner │ Process Enum │ IRP │ Memory Scan │ │ │
│ │ └────────────────────────────────────────────────────┘ │ │
│ └─────────────────────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────────┘
| Tactic | Techniques | Detection Method |
|---|---|---|
| Execution | T1055 (Process Injection) | Thread callback, ETW-TI |
| Persistence | T1547 (Boot/Logon) | Registry callback |
| Privilege Escalation | T1068 (Exploitation) | Memory scanner |
| Defense Evasion | T1562 (Disable Security) | Integrity monitoring |
| Credential Access | T1003 (OS Credential Dumping) | Object callback |
| Discovery | T1057 (Process Discovery) | Process enumeration |
| Lateral Movement | T1021 (Remote Services) | Network filter |
| Impact | T1486 (Data Encrypted) | Minifilter entropy |
The detection engine includes pre-built rules for:
winget install LLVM.LLVM --version 17.0.6
rust-toolchain.tomlcargo install cargo-make --no-default-features --features tls-native
$env:WDKContentRoot = "C:\Program Files (x86)\Windows Kits\10"
$env:WDKVersion = "10.0.22621.0"
cargo make # Debug build
cargo make release # Release build
cargo make package # Create driver package
bcdedit /set testsigning on # Enable test signing (reboot required)
devcon install leviathan.inf Root\Leviathan
sc start leviathan
Leviathan provides all the kernel-mode primitives needed to build a complete EDR. Here's how to use the components:
// Register callbacks for system monitoring
callbacks::process::register()?; // Process events
callbacks::thread::register()?; // Thread events (injection detection)
callbacks::image::register()?; // DLL/driver loading
callbacks::registry::register()?; // Registry modifications
// Enable minifilter for file I/O monitoring
filters::minifilter::register(driver)?;
// Detects: Ransomware (entropy), sensitive file access, suspicious writes
// Enable WFP for network monitoring
filters::network::register(device)?;
// Detects: C2 communication, data exfiltration, lateral movement
// Initialize detection engine
let mut engine = detection::DetectionEngine::new();
engine.load_default_rules();
engine.set_alert_callback(handle_alert);
// Process events through detection
let alert = engine.process_event(event_type, &context, &data);
// Scan for signatures/patterns
let mut scanner = forensics::memory_scanner::MemoryScanner::new();
scanner.load_builtin_signatures();
let matches = scanner.scan_process(pid)?;
// Detect hidden processes
let mut enumerator = forensics::process_enum::ProcessEnumerator::new();
enumerator.enumerate_all()?;
let hidden = enumerator.find_hidden();
// Set up kernel-user communication
utils::comm::init_global_channel(1024 * 1024)?; // 1MB ring buffer
let channel = utils::comm::get_global_channel()?;
channel.write_event(EventType::ProcessCreate, &event_data)?;
MIT OR Apache-2.0