Skip to content

Commit ecbcce5

Browse files
authored
Document how to use the filters (#222)
* adding coverage for tcp and http filters * update TLS readme * update readmes * update references to other crates in readmes
1 parent 5828283 commit ecbcce5

File tree

11 files changed

+1268
-144
lines changed

11 files changed

+1268
-144
lines changed

huginn-net-http/README.md

Lines changed: 63 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ This crate provides HTTP-based passive fingerprinting capabilities. It analyzes
2626
- **High performance** - 562.1K pps for full analysis, 200M pps detection
2727
- **HTTP/1.x & HTTP/2** - Support for both major protocol versions
2828
- **Type-safe architecture** - Prevents entire classes of bugs at compile time
29+
- **Typed observable data access** - Access to typed HTTP headers, header ordering, language preferences, and other observable signals for custom fingerprinting and analysis
30+
- **Extensible fingerprinting** - Build custom fingerprints using typed observable data (`ObservableHttpRequest`, `ObservableHttpResponse`) without being limited to predefined p0f signatures
2931

3032
## Features
3133

@@ -48,34 +50,80 @@ Add this to your `Cargo.toml`:
4850
```toml
4951
[dependencies]
5052
huginn-net-http = "1.6.1"
53+
huginn-net-db = "1.6.1"
5154
```
5255

5356
### Basic Usage
5457

5558
```rust
56-
use huginn_net_http::{HuginnNetHttp, HttpAnalysisResult};
5759
use huginn_net_db::Database;
58-
use std::sync::mpsc;
59-
60-
fn main() {
61-
let db = Database::load_default().unwrap();
62-
let mut analyzer = HuginnNetHttp::new(Some(&db), 1000).unwrap();
60+
use huginn_net_http::{FilterConfig, HuginnNetHttp, HuginnNetHttpError, IpFilter, PortFilter, HttpAnalysisResult};
61+
use std::sync::{Arc, mpsc};
62+
63+
fn main() -> Result<(), HuginnNetHttpError> {
64+
// Load database for browser/server fingerprinting
65+
let db = match Database::load_default() {
66+
Ok(db) => Arc::new(db),
67+
Err(e) => {
68+
eprintln!("Failed to load database: {e}");
69+
return Err(HuginnNetHttpError::Parse(format!("Database error: {e}")));
70+
}
71+
};
72+
73+
// Create analyzer
74+
let mut analyzer = match HuginnNetHttp::new(Some(db), 1000) {
75+
Ok(analyzer) => analyzer,
76+
Err(e) => {
77+
eprintln!("Failed to create analyzer: {e}");
78+
return Err(e);
79+
}
80+
};
81+
82+
// Optional: Configure filters (can be combined)
83+
if let Ok(ip_filter) = IpFilter::new().allow("192.168.1.0/24") {
84+
let filter = FilterConfig::new()
85+
.with_port_filter(PortFilter::new().destination(80))
86+
.with_ip_filter(ip_filter);
87+
analyzer = analyzer.with_filter(filter);
88+
}
89+
6390
let (sender, receiver) = mpsc::channel::<HttpAnalysisResult>();
6491

6592
// Live capture (use parallel mode for high throughput)
66-
std::thread::spawn(move || analyzer.analyze_network("eth0", sender, None));
93+
std::thread::spawn(move || {
94+
if let Err(e) = analyzer.analyze_network("eth0", sender, None) {
95+
eprintln!("Analysis error: {e}");
96+
}
97+
});
6798

6899
// Or PCAP analysis (always use sequential mode)
69-
// std::thread::spawn(move || analyzer.analyze_pcap("capture.pcap", sender, None));
100+
// std::thread::spawn(move || {
101+
// if let Err(e) = analyzer.analyze_pcap("capture.pcap", sender, None) {
102+
// eprintln!("Analysis error: {e}");
103+
// }
104+
// });
70105

71106
for result in receiver {
72107
if let Some(http_request) = result.http_request { println!("{http_request}"); }
73108
if let Some(http_response) = result.http_response { println!("{http_response}"); }
74109
}
110+
111+
Ok(())
75112
}
76113
```
77114

78-
For a complete working example with signal handling and error management, see [`examples/capture-http.rs`](../examples/capture-http.rs).
115+
For a complete working example with signal handling, error management, and CLI options, see [`examples/capture-http.rs`](../examples/capture-http.rs).
116+
117+
### Filtering
118+
119+
The library supports packet filtering to reduce processing overhead and focus on specific traffic. Filters can be combined using AND logic (all conditions must match):
120+
121+
**Filter Types:**
122+
- **Port Filter**: Filter by TCP source/destination ports (supports single ports, lists, and ranges)
123+
- **IP Filter**: Filter by specific IPv4/IPv6 addresses (supports source-only, destination-only, or both)
124+
- **Subnet Filter**: Filter by CIDR subnets (supports IPv4 and IPv6)
125+
126+
All filters support both Allow (allowlist) and Deny (denylist) modes. See the [filter documentation](https://docs.rs/huginn-net-http/latest/huginn_net_http/filter/index.html) for complete details.
79127

80128
### Example Output
81129

@@ -92,6 +140,12 @@ For a complete working example with signal handling and error management, see [`
92140
Sig: server=[nginx/1.14.0 (Ubuntu)],date=[Tue, 17 Dec 2024 13:54:16 GMT],x-cache-status=[from content-cache-1ss/0],connection=[close]:Server,Date,X-Cache-Status,Connection:
93141
```
94142

143+
## Huginn Net Ecosystem
144+
145+
This crate is part of the Huginn Net ecosystem. For multi-protocol analysis, see **[huginn-net](../huginn-net/README.md)**. For protocol-specific analysis:
146+
- **[huginn-net-tcp](../huginn-net-tcp/README.md)** - OS fingerprinting, MTU detection, uptime estimation
147+
- **[huginn-net-tls](../huginn-net-tls/README.md)** - JA4 fingerprinting, TLS version detection
148+
95149
## Documentation
96150

97151
For complete documentation, examples, and integration guides, see the main [huginn-net README](https://github.com/biandratti/huginn-net#readme).

0 commit comments

Comments
 (0)