2023 年 4 月 3 日 | 没有评论
File Protector Demo是使用EaseFilter File Monitor、File Control、File Encryption和Process Filter Driver SDK开发的,它演示了如何使用EaseFilter Filter Driver SDK来监视或控制Windows文件I/O。 文件保护工具可以实时监视或阻止文件更改和文件访问,获取所有注册的文件 I/O 请求的通知。 它可以捕获或阻止文件打开、文件创建、文件更改、文件读取、文件写入、查询文件信息、设置文件信息、查询安全信息、设置安全信息、文件重命名、文件删除、目录浏览和文件关闭I/ 奥请求。 您可以记录文件 I/O 信息,以了解谁、何时、访问了哪些文件。 这是 File Protector 演示工具的屏幕截图。
过滤规则是一种基于文件名的文件控制策略,过滤驱动程序将根据文件名监视文件 I/O,命令如下,过滤驱动程序将只监视或控制符合过滤条件的文件。要监控文件 I/O,至少需要创建一条文件过滤规则。
为了控制文件访问并保护您的敏感数据,您可以在过滤规则中配置访问控制标志,也可以注册 pre-io 事件,在 pre-io 通知事件中允许或拒绝文件访问。 配置过滤规则的访问标志,可以防止您的文件被未经授权的进程或用户读取、写入、删除、重命名或更改。
您可以在过滤器驱动程序中设置控制策略,过滤器驱动程序将根据过滤器规则设置的策略允许或阻止文件访问。 要为过滤器驱动程序设置控制过滤器规则,您可以设置或取消设置访问标志整数位以允许或阻止过滤器规则中的特定 I/O,如下所示。
您可以注册 Pre-IO 操作来控制回调函数中的文件访问。 通过注册特定的I/O事件,您可以完全控制I/O,您的回调函数将为每个注册的I/O调用,您可以根据I/O信息允许、修改或阻止该I/O。
文件I/O事件的常用信息:
以下示例创建一个过滤规则来保护运行时指定的目录。 设置过滤规则是为了保护文件夹免遭文件被重命名、删除、写入。 该组件在目录中注册了创建和删除 IO 回调事件。 如果文件被打开或删除,就会触发该事件,您可以在该事件中允许或阻止IO。
//A File Protector C# Example
The following example creates a filter rule to watch the directory specified at run time.
The component is set to watch for all file change in the directory. If a file was changed, the file name,
file change type, user name, process name will be printed to the console.
The component also is set to watch the file open and file read IO, the IO was triggered, the file open and file read information will be printed to the console.
using System;
using EaseFilter.FilterControl;
namespace FileProtectorConsole
{
class Program
{
static FilterControl filterControl = new FilterControl();
static void Main(string[] args)
{
string lastError = string.Empty;
string licenseKey = "Email us to request a trial key: info@easefilter.com";
FilterAPI.FilterType filterType = FilterAPI.FilterType.MONITOR_FILTER|FilterAPI.FilterType.CONTROL_FILTER
|FilterAPI.FilterType.PROCESS_FILTER|FilterAPI.FilterType.REGISTRY_FILTER|FilterAPI.FilterType.ENCRYPTION_FILTER;
int serviceThreads = 5;
int connectionTimeOut = 10; //seconds
try
{
//copy the right Dlls to the current folder.
Utils.CopyOSPlatformDependentFiles(ref lastError);
if (!filterControl.StartFilter(filterType, serviceThreads, connectionTimeOut, licenseKey, ref lastError))
{
Console.WriteLine("Start Filter Service failed with error:" + lastError);
return;
}
//the watch path can use wildcard to be the file path filter mask.i.e. '*.txt' only monitor text file.
string watchPath = "c:\\test\\*";
if (args.Length > 0)
{
watchPath = args[0];
}
//create a file protector filter rule, every filter rule must have the unique watch path.
FileFilter fileProtectorFilter = new FileFilter(watchPath);
//configure the access right for the protected folder
//prevent the file from being deleted.
fileProtectorFilter.EnableDeleteFile = false;
//prevent the file from being renamed.
fileProtectorFilter.EnableRenameOrMoveFile = false;
//prevent the file from being written.
fileProtectorFilter.EnableWriteToFile = false;
//authorize process with full access right
fileProtectorFilter.ProcessNameAccessRightList.Add("notepad.exe", FilterAPI.ALLOW_MAX_RIGHT_ACCESS);
//you can enable/disalbe more access right by setting the properties of the fileProtectorFilter.
//Filter the callback file IO events, here get callback before the file was opened/created, and file was deleted.
fileProtectorFilter.ControlFileIOEventFilter = (ulong)(ControlFileIOEvents.OnPreFileCreate | ControlFileIOEvents.OnPreDeleteFile);
fileProtectorFilter.OnPreCreateFile += OnPreCreateFile;
fileProtectorFilter.OnPreDeleteFile += OnPreDeleteFile;
filterControl.AddFilter(fileProtectorFilter);
if (!filterControl.SendConfigSettingsToFilter(ref lastError))
{
Console.WriteLine("SendConfigSettingsToFilter failed." + lastError);
return;
}
Console.WriteLine("Start filter service succeeded.");
// Wait for the user to quit the program.
Console.WriteLine("Press 'q' to quit the sample.");
while (Console.Read() != 'q') ;
filterControl.StopFilter();
}
catch (Exception ex)
{
Console.WriteLine("Start filter service failed with error:" + ex.Message);
}
}
///
/// Fires this event before the file was opened.
///
static void OnPreCreateFile(object sender, FileCreateEventArgs e)
{
Console.WriteLine("OnPreCreateFile:" + e.FileName + ",userName:" + e.UserName + ",processName:" + e.ProcessName);
//you can block the file open here by returning below status.
e.ReturnStatus = NtStatus.Status.AccessDenied;
}
///
/// Fires this event before the file was deleted.
///
static void OnPreDeleteFile(object sender, FileIOEventArgs e)
{
Console.WriteLine("OnPreDeleteFile:" + e.FileName + ",userName:" + e.UserName + ",processName:" + e.ProcessName);
//you can block the file being deleted here by returning below status.
e.ReturnStatus = NtStatus.Status.AccessDenied;
}
}
}
Process Monitor SDK
File Security Filter Driver SDK
Using EaseFilter Filter Driver SDK
EEFD Transparent File Encryption SDK
EaseFilter File Access Control SDK
EaseFilter File Access Monitor SDK
Process Control SDK
Registry Protection SDK
自动文件加密演示
文件保护器分步演示
文件监视器分步演示
文件访问控制列表
认证与授权
零信任文件访问安全
黑名单和白名单
网络文件监控和保护器
阻止文件访问 USB 驱动器
设置可信进程权限
使用标头加密文件
随时随地加密文件
跟踪应用程序中的文件更改
如何设置文件访问权限
文件访问过滤规则