cloudflare/wirefilter

GitHub: cloudflare/wirefilter

Cloudflare 开源的类 Wireshark 过滤器执行引擎,提供过滤语法解析、编译与运行时执行能力,可作为库嵌入各类安全与网络工具。

Stars: 1117 | Forks: 114

# Wirefilter [![构建状态](https://img.shields.io/travis/com/cloudflare/wirefilter/master.svg)](https://travis-ci.com/cloudflare/wirefilter) [![Crates.io](https://img.shields.io/crates/v/wirefilter-engine.svg)](https://crates.io/crates/wirefilter-engine) [![许可证](https://img.shields.io/github/license/cloudflare/wirefilter.svg)](LICENSE) 这是一个用于类 [Wireshark®](https://www.wireshark.org/) 过滤器的执行引擎。 它包含用于解析过滤器语法、将其编译为 可执行 IR,以及最终对提供的值执行过滤器的公共 API。 ## 示例 ``` use wirefilter::{ExecutionContext, Scheme}; fn main() -> Result<(), Box> { // Create a map of possible filter fields. let scheme = Scheme! { http.method: Bytes, http.ua: Bytes, port: Int, } .build(); // Parse a Wireshark-like expression into an AST. let ast = scheme.parse( r#" http.method != "POST" && not http.ua matches "(googlebot|facebook)" && port in {80 443} "#, )?; println!("Parsed filter representation: {:?}", ast); // Compile the AST into an executable filter. let filter = ast.compile(); // Set runtime field values to test the filter against. let mut ctx = ExecutionContext::new(&scheme); ctx.set_field_value(scheme.get_field("http.method").unwrap(), "GET")?; ctx.set_field_value( scheme.get_field("http.ua").unwrap(), "Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:66.0) Gecko/20100101 Firefox/66.0", )?; ctx.set_field_value(scheme.get_field("port").unwrap(), 443)?; // Execute the filter with given runtime values. println!("Filter matches: {:?}", filter.execute(&ctx)?); // true // Amend one of the runtime values and execute the filter again. ctx.set_field_value(scheme.get_field("port").unwrap(), 8080)?; println!("Filter matches: {:?}", filter.execute(&ctx)?); // false Ok(()) } ``` ## 模糊测试 在 fuzz 目录中有模糊测试。 安装 afl: ``` cargo install afl --force ``` 构建 `bytes` 模糊测试: ``` cd fuzz/bytes cargo afl build ``` 运行模糊测试(在 `fuzz/bytes` 目录内): ``` cargo afl fuzz -i in -o out ../../target/debug/fuzz-bytes ``` 如果您看到类似以下的错误: ``` Looks like the target binary is not instrumented! ``` 请尝试删除已编译的二进制文件,并使用 `cargo afl build` 重新构建。 ## 许可证 根据 MIT 许可证授权。有关详细信息,请参阅 [LICENSE](LICENSE) 文件。
标签:Cloudflare, DNS解析, IP 地址批量处理, IR, MITRE ATT&CK, Rust, SEO工具, Wirefilter, Wireshark, 中间表示, 云计算, 包过滤, 协议分析, 句柄查看, 可视化界面, 开源项目, 数据包过滤, 权限提升, 正则表达式匹配, 网络安全, 网络流量审计, 规则引擎, 语法解析, 过滤引擎, 运行时引擎, 通知系统, 隐私保护