Skip to content

Commit

Permalink
split example
Browse files Browse the repository at this point in the history
  • Loading branch information
biandratti committed Oct 25, 2024
1 parent fd5e56b commit 995f600
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 16 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
[package]
name = "p0f"
version = "0.1.0"
name = "passivetcp-rs"
edition = "2021"
description = "A Rust library for passive traffic fingerprinting [p0f]"
license = "MIT OR Apache-2.0"
authors = ["Your Name <[email protected]>"]
repository = "https://github.com/biandratti/passivetcp-rs"
readme = "README.md"
keywords = ["p0f", "fingerprinting", "network", "security", "TCP"]
categories = ["network-programming"]

[dependencies]
nom = "7.1"
Expand All @@ -11,3 +17,11 @@ regex = "1.11.1"
failure = "0.1.8"
log = "0.4.22"
lazy_static = "1.5.0"

[lib]
name = "passivetcp"
path = "src/lib.rs"

[[example]]
name = "passive_scan"
path = "examples/passive_scan.rs"
47 changes: 47 additions & 0 deletions examples/passive_scan.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
use passivetcp::{Database, P0fOutput, SignatureDetails, SignatureMatcher};
use pnet::datalink::{self, Config, Channel::Ethernet};

fn main() {
let db = Database::default();
let matcher = SignatureMatcher::new(&db);

let interface_name = "eth0";
let interfaces = datalink::interfaces();
let interface = interfaces
.into_iter()
.find(|iface| iface.name == interface_name)
.expect("Could not find the interface");

let config = Config {
promiscuous: true,
..Config::default()
};

// Set up the datalink channel
let (_tx, mut rx) = match datalink::channel(&interface, config) {
Ok(Ethernet(tx, rx)) => (tx, rx),
Ok(_) => panic!("Unhandled channel type"),
Err(e) => panic!("Unable to create channel: {}", e),
};

// Listen for packets and print passive scan output
loop {
match rx.next() {
Ok(packet) => {
if let Ok(signature_details) = SignatureDetails::extract(packet) {
if let Some((label, _)) = matcher.find_matching_signature(&signature_details.signature) {
let output = P0fOutput {
client: signature_details.client,
server: signature_details.server,
is_client: signature_details.is_client,
label: Some(label.clone()),
sig: signature_details.signature,
};
println!("{}", output);
}
}
}
Err(e) => eprintln!("Failed to read packet: {}", e),
}
}
}

0 comments on commit 995f600

Please sign in to comment.