-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fd5e56b
commit 995f600
Showing
3 changed files
with
65 additions
and
4 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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" | ||
|
@@ -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" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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), | ||
} | ||
} | ||
} |