- Notifications
You must be signed in to change notification settings - Fork104
An execution engine for Wireshark-like filters
License
cloudflare/wirefilter
Folders and files
| Name | Name | Last commit message | Last commit date | |
|---|---|---|---|---|
Repository files navigation
This is an execution engine forWireshark®-like filters.
It contains public APIs for parsing filter syntax, compiling them intoan executable IR and, finally, executing filters against provided values.
use wirefilter::{ExecutionContext,Scheme};fnmain() ->Result<(),Box<dyn std::error::Error>>{// 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.letmut 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)?);// falseOk(())}
There are fuzz tests in the fuzz directory.
Install afl:
cargo install afl --forceBuildbytes fuzz test:
cd fuzz/bytescargo afl buildRun fuzz test (from insidefuzz/bytes directory):
cargo afl fuzz -i in -o out ../../target/debug/fuzz-bytesIf you see an error like:
Looks like the target binary is not instrumented!Try deleting the compiled binary and re-building withcargo afl build.
Licensed under the MIT license. See theLICENSE file for details.
About
An execution engine for Wireshark-like filters
Topics
Resources
License
Code of conduct
Contributing
Security policy
Uh oh!
There was an error while loading.Please reload this page.
Stars
Watchers
Forks
Packages0
Uh oh!
There was an error while loading.Please reload this page.
Contributors6
Uh oh!
There was an error while loading.Please reload this page.