EaseFilter FileProtector Demo in C#

Start Building Your File Security PoC Today

Get the full-featured 30-day trial SDK for free. Includes pre-built templates to test granular access control, transparent encryption, and ransomware defense instantly.

Overview

The EaseFilter FileProtector is a robust framework built on top of a kernel-mode file system filter driver (EaseFlt.sys) designed to provide low-level interception and control over operating system operations before they hit the hardware. By capturing file I/O, process creation, and registry modifications at the kernel level, it prevents malware, ransomware, or unauthorized users from circumventing security mechanisms.

Here is a technical teardown of the FileProtector project architecture, its core features, and how it leverages the EaseFilter SDK to secure data.


Key Features and Capabilities

  • Granular File Access Control: Dynamically allows or blocks file system operations (read, write, delete, rename, change permissions) using wildcard file masks, process inclusion/exclusion lists, and Windows user identities.
  • Transparent On-The-Fly Encryption (TDE): Automates AES-256 encryption on the fly when data is written to disk. Only explicitly authorized applications (e.g., Microsoft Word) see decrypted text in memory; unauthorized applications or bad actors read raw, encrypted ciphertext.
  • Ransomware Defense & Anomaly Detection: Real-time behavior monitoring flags high-frequency renames, massive data encryption anomalies, or unusual access patterns, instantly neutralizing unknown zero-day ransomware.
  • Process and Registry Guarding: Intercepts thread/process spawn cycles to block unauthorized executables and shields critical Windows registry branches from malicious modifications.
  • Hardware and Volume Control: Monitors and regulates physical hardware nodes. It blocks unauthorized USB device mounting, restricts storage volume formatting, and locks down external data vectors.
  • Network Share and IP Audit Tracking: Identifies whether file requests originate locally or remotely via network shares, logging the remote IP address to easily isolate untrusted network nodes.
  • SIEM-Ready Security Auditing: Generates tamper-proof audit trails documenting user credentials, timestamps, process IDs, target paths, and operation outcomes—tailor-made for SIEM or YARA tool compliance mapping.

Main Security Use Cases

  • Data Loss Prevention (DLP): Stop internal data exfiltration by enforcing absolute read/write blocks on USB devices or blacklisting unauthorized communication programs from touching intellectual property folders.
  • Digital Rights Management (DRM): Isolate sensitive folders so only trusted corporate applications can interact with business assets, stripping unapproved software of viewing privileges.
  • Endpoint Detection and Response (EDR): Build comprehensive zero-trust endpoint defenses that monitor system health, audit data trails, and dynamically terminate suspicious background behavior.

The Architecture: Bridging Kernel and User Space

The architecture of the FileProtector project is cleanly isolated into functional layers to securely bridge the gap between low-level Windows kernel events and managed user-space execution:

  • The Kernel-Mode Driver (EaseFlt.sys): Intercepts low-level I/O Request Packets (IRPs) directly inside the OS subsystem.
  • The FilterControl Wrapper: A managed C# class library (FilterControl namespace) that wraps native kernel APIs, handling the heavy lifting of parsing low-level pointers and structured buffers into clean .NET objects and events.
  • The Business Logic Layer: Contained within the FileProtector namespace, this module responds to intercepted kernel callbacks via custom event handlers (such as ControlEventHandler and EncryptEventHandler) to compute real-time security directives.
  • Configuration and UI: The CommonObjects namespace coordinates the application's global configuration templates, Windows data structures, and the administrative dashboard interfaces (like SettingsForm or OptionForm).

file protector


Managing Policies: Filter Rule and Access Control Settings in the Demo

While the programmatic API is incredibly powerful, hardcoding rules isn't practical for enterprise deployments. The FileProtector project demonstrates how to build a dynamic administrative dashboard by mapping UI configurations to the SDK's underlying properties. Within the CommonObjects namespace, the demo utilizes specific Windows Forms to manage these policies:

  • Filter Rule Settings (FilterRuleForm.cs & ControlFilterRuleSettigs.cs): Administrators use these forms to visually define the scope of protection. Instead of writing code, a user can input the target directory (e.g., C:\Finance\*), add inclusion/exclusion masks for file types (like isolating .pdf and .docx files), and specify trusted processes. The form serializes this input and maps it directly to the FileFilter object properties (like ExcludeProcessNameList and IncludeUserNameList).

filter rule settings

  • Access Control Settings (AccessRightsForm.cs): This is where administrators define what happens when a rule matches. The UI presents checkboxes for various operations (e.g., Allow Read, Allow Write, Allow Delete, Allow Rename). Behind the scenes, the form translates these visual checkbox selections into the corresponding hexadecimal bitmask (the AccessFlag property). For example, unchecking "Allow File Delete" dynamically applies ~FilterAPI.ALLOW_FILE_DELETE to the rule's active bitmask.

access control settings

This visual configuration layer allows security teams to dynamically push updates, lock down folders, or change encryption keys on the fly without needing to recompile the core application.


Step-by-Step Implementation and Core Features

1. Initialization and Starting the Filter

Before any protection can occur, the application must configure global filter settings and establish a communication channel with the kernel driver using the StartFilter method. This requires passing in your specific filter type, thread allocations, timeouts, and license key.

// Initialize the core filter control
FilterControl filterControl = new FilterControl();

// Define startup parameters
int filterType = (int)(FilterAPI.FilterType.MONITOR_FILTER | FilterAPI.FilterType.CONTROL_FILTER 
| FilterAPI.FilterType.PROCESS_FILTER | FilterAPI.FilterType.REGISTRY_FILTER); 
int serviceThreads = 5;
int connectionTimeOut = 10; // seconds
string licenseKey = "YOUR_SDK_LICENSE_KEY";
string lastError = string.Empty;

// Start the filter service
if (!filterControl.StartFilter(filterType, serviceThreads, connectionTimeOut, licenseKey, ref lastError))
{
    Console.WriteLine("Start Filter Service failed with error: " + lastError);
    return;
}

Console.WriteLine("Filter Service successfully started.");

2. Granular Identity and Access Control

The ControlEventHandler and FileFilter classes evaluate who can interact with targeted nodes. To dynamically intercept and evaluate requests, you must configure the filter rule's access flags and explicitly register the specific pre-I/O events you want to track using the ControlFileIOEventFilter property.

// 1. Create a filter rule targeting a specific directory using a wildcard mask
FileFilter fileProtectorFilter = new FileFilter(@"C:\HighlySensitiveData\*");

// 2. Exclude specific file types from being restricted by this rule
fileProtectorFilter.ExcludeFileFilterMaskList.Add("*.exe");
fileProtectorFilter.ExcludeFileFilterMaskList.Add("*.dll");

// 3. User-Level Control: Only allow a specific user to access the files
fileProtectorFilter.IncludeUserNameList.Add(@"DOMAIN\AuthorizedAdmin");

// 4. Process-Level Control: Exclude trusted backup software
fileProtectorFilter.ExcludeProcessNameList.Add("backup_service.exe");

// 5. Define the Access Flag: Deny deletion, renaming, and writing for non-matching users
fileProtectorFilter.AccessFlags = FilterAPI.ALLOW_MAX_ACCESS_RIGHT 
                          & ~FilterAPI.ALLOW_FILE_DELETE 
                          & ~FilterAPI.ALLOW_FILE_RENAME 
                          & ~FilterAPI.ALLOW_FILE_WRITE;

// 6. Explicitly set the Event Filter mask to capture Pre-Create and Pre-Delete I/O events
fileProtectorFilter.ControlFileIOEventFilter = (ulong)(ControlFileIOEvents.OnPreFileCreate);

// 7. Register the Pre-I/O callback events to dynamically detect anomalies or block access
fileProtectorFilter.OnPreCreateFile += DynamicBehaviorEvaluation_OnPreCreateFile;

// 8. Apply the rule to the filter control instance
filterControl.AddFilter(fileProtectorFilter);

Implementing the Callback Function: When you set the ControlFileIOEventFilter mask and register the event, the EaseFilter kernel driver pauses the I/O request before it reaches the file system and hands the contextual data up to your user-mode callback function. By modifying the e.ReturnStatus, you directly command the kernel driver to allow or block the operation.

/// <summary>
/// Callback invoked by the filter driver before a file is created, opened, or overwritten.
/// </summary>
private void DynamicBehaviorEvaluation_OnPreCreateFile(object sender, FileCreateEventArgs e)
{
    // Log the attempt for auditing purposes
    Console.WriteLine($"[OnPreCreateFile] User: {e.UserName}, Process: {e.ProcessName}, Target: {e.FileName}");

    // Perform Dynamic Evaluation: Block a specific process dynamically
    if (e.ProcessName.ToLower().Contains("malicious_script.exe"))
    {
        Console.WriteLine($"[BLOCK] Unauthorized process detected: {e.ProcessName}");
        
        // Instruct the kernel driver to deny access
        e.ReturnStatus = NtStatus.StatusAccessDenied; 
        e.FilterReply.ReturnMessage = "Access denied by Dynamic Behavior Evaluation.";
        return;
    }

    // Perform Dynamic Evaluation: Block specific access types (e.g., Write access)
    if ((e.DesiredAccess & (uint)System.IO.FileAccess.Write) > 0)
    {
        Console.WriteLine($"[BLOCK] Write access denied for {e.FileName}");
        e.ReturnStatus = NtStatus.StatusAccessDenied;
        return;
    }

    // If no malicious behavior is detected, do not modify e.ReturnStatus.
    // The driver will allow the I/O request to proceed.
}

3. Transparent On-The-Fly Encryption (TDE)

The EncryptionFilter and EncryptEventHandler classes execute cryptographic mutations as blocks move from memory arrays down to deep storage sectors.

// Create an encryption rule for a target folder
FileFilterRule encryptRule = new FileFilterRule(@"C:\SecureData\*");

// Enable encryption flags and block unauthorized reads of decrypted data
encryptRule.EnableEncryption = true;
encryptRule.EnableReadEncryptedData = false;

// Set up the encryption key (AES-256)
byte[] encryptionKey = new byte[] { 0x01, 0x02, 0x03, /* ... 32 bytes ... */ 0x20 };
encryptRule.EncryptionKey = encryptionKey;

// Authorize specific processes to see the decrypted data with maximum access rights
encryptRule.AddTrustedProcessRight("winword.exe", FilterAPI.ALLOW_MAX_ACCESS_RIGHT,"","");

// Add the encryption rule
filterControl.AddFilterRule(encryptRule);

4. Process and Registry Filtering

Beyond raw file objects, the ProcessFilter and RegistryFilter classes enforce security boundaries at the core OS layer to insulate the host environment from malicious interference.

// Process Filtering Example: Block specific executables
ProcessFilterRule procRule = new ProcessFilterRule(@"C:\UntrustedApp\*");
procRule.ControlFlag = FilterAPI.PROCESS_CREATION_DENIED;
filterControl.AddProcessFilterRule(procRule);

// Registry Filtering Example: Prevent modification of critical keys
RegistryFilterRule regRule = new RegistryFilterRule(@"MACHINE\Software\MyCompany\*");
regRule.ControlFlag = FilterAPI.REG_ALLOW_MAX_ACCESS_RIGHT & ~FilterAPI.REG_ALLOW_SET_VALUE;
filterControl.AddRegistryFilterRule(regRule);

Summary

The FileProtector project showcases a highly structured, scalable architecture for implementing zero-trust endpoint configurations using the EaseFilter SDK. By separating the kernel communication layer from high-level event handling logic, developers can quickly adapt the code to build specialized ransomware guards, automated corporate encryption tunnels, or audit-compliant DLP software.