windows-wfp
Safe Rust wrapper for the Windows Filtering Platform (WFP) kernel-level firewall API.
Overview
WFP is the kernel-level firewall framework in Windows, used by Windows Firewall and third-party security software. This crate provides a high-level, memory-safe Rust interface to create and manage firewall filters without dealing with raw FFI.
Features
- WFP Engine - RAII-based session management with automatic cleanup
- Provider & Sublayer - Register custom firewall providers with configurable priority
- Filter Rules - Builder-pattern API for creating firewall filters
- Path Conversion - Automatic DOS-to-NT kernel path conversion (critical for WFP)
- Event Monitoring - Real-time network event subscription
- Memory Safety - All Windows handles managed with RAII, minimal unsafe code
Prerequisites
- Windows 10/11 (or Windows Server 2016+)
- Administrator privileges required at runtime (WFP is a kernel API)
- Rust 1.75+
Quick Start
use ;
// Open WFP engine (requires Administrator)
let engine = new?;
// Register provider and sublayer
initialize_wfp?;
// Block an application
let rule = new
.with_weight
.with_app_path;
let filter_id = add_filter?;
// curl.exe is now blocked at kernel level!
// Clean up
delete_filter?;
# Ok::
Filter Conditions
Filters can match on multiple conditions simultaneously:
use *;
let rule = new
.with_weight
.with_app_path
.with_protocol
.with_remote_port
.with_remote_ip;
# Ok::
Available conditions:
- Application path - Match by executable (auto-converted to NT kernel path)
- Protocol - TCP, UDP, ICMP, ICMPv6, and more
- Remote/Local port - Match specific ports
- Remote/Local IP - Match IP addresses with CIDR masks (IPv4 and IPv6)
- Windows service name - Match by service SID
- AppContainer SID - Match UWP/packaged apps
Path Conversion
WFP operates at the kernel level and requires NT kernel paths, not DOS paths:
| Format | Example |
|---|---|
| DOS path (you provide) | C:\Windows\System32\curl.exe |
| NT kernel path (WFP needs) | \device\harddiskvolume4\windows\system32\curl.exe |
This crate handles the conversion automatically using FwpmGetAppIdFromFileName0. Without it, filters would be added successfully but would never match any traffic.
Event Monitoring
Subscribe to real-time network events:
use ;
let engine = new?;
let subscription = new?;
loop
# Ok::
Examples
Run the included examples (requires Administrator):
# Block notepad.exe for 10 seconds
# Block curl.exe and monitor events in real-time
# List all active WFP filters in the system
License
Licensed under GPL-2.0. See LICENSE for details.