1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//! Issue #30: passive visibility into UDP infrastructure protocols —
//! NTP, SNMP, TFTP, RADIUS.
//!
//! Arms the four `Protocol` markers and prints each parsed message. These are
//! the unglamorous-but-security-relevant services an NSM wants to see: rogue
//! time sources (NTP), cleartext community strings (SNMP v1/v2c), unauthenticated
//! file transfers (TFTP), and the auth fabric (RADIUS).
//!
//! Run:
//!
//! ```sh
//! cargo run --example monitor_infra_protocols --features "infra-protocols,tokio,emit" -- eth0
//! ```
use std::time::Duration;
use netring::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let iface = std::env::args().nth(1).unwrap_or_else(|| "lo".into());
eprintln!("monitor_infra_protocols: NTP/SNMP/TFTP/RADIUS on {iface} (Ctrl-C to stop)");
Monitor::builder()
.interface(&iface)
.name("infra")
.protocol::<Ntp>()
.on::<Ntp>(|m: &flowscope::ntp::NtpMessage| {
println!("ntp {m:?}");
Ok(())
})
.protocol::<Snmp>()
.on::<Snmp>(|m: &flowscope::snmp::SnmpMessage| {
println!("snmp {m:?}");
Ok(())
})
.protocol::<Tftp>()
.on::<Tftp>(|m: &flowscope::tftp::TftpMessage| {
println!("tftp {m:?}");
Ok(())
})
.protocol::<Radius>()
.on::<Radius>(|m: &flowscope::radius::RadiusMessage| {
println!("radius {m:?}");
Ok(())
})
.sink(StdoutSink::default())
.build()?
.run_for(Duration::from_secs(300))
.await?;
Ok(())
}