diff --git a/packet_sniffer/report.txt b/packet_sniffer/report.txt index 0ed91a1e..73f7d305 100644 --- a/packet_sniffer/report.txt +++ b/packet_sniffer/report.txt @@ -4,13 +4,13 @@ <><> Packets are sniffed from adapter 'en0' <><> <><> Report updates info -<><> Report start time: 13/08/2022 17:36:21 -<><> Report last update: 13/08/2022 17:37:52 -<><> Report update frequency: every 7 seconds -<><> Number of times report was updated: 13 +<><> Report start time: 13/08/2022 22:08:02 +<><> Report last update: 13/08/2022 22:08:12 +<><> Report update frequency: every 5 seconds +<><> Number of times report was updated: 2 <><> <><> Filters -<><> Considering only addresses featured by more than 500 packets +<><> Considering addresses featured by any number of packets <><> Considering all port numbers (from 0 to 65535) <><> <><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><><> @@ -18,213 +18,3 @@ -Address: 185.126.207.169:8080 - Sent data - Sent Bytes: 297.30 kB - Sent packets: 5179 - Received data - Received Bytes: 12.67 MB - Received packets: 9428 - Timestamps - Initial Timestamp: 13/08/2022 17:36:36 - Final Timestamp: 13/08/2022 17:36:57 - Protocols - Transport layer protocols: TCP - Application layer protocols: unable to identify any level 7 protocol - - -Address: 151.99.54.108:443 - Sent data - Sent Bytes: 8.73 MB - Sent packets: 5965 - Received data - Received Bytes: 101.85 kB - Received packets: 2475 - Timestamps - Initial Timestamp: 13/08/2022 17:36:22 - Final Timestamp: 13/08/2022 17:37:01 - Protocols - Transport layer protocols: TCP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:60486 - Sent data - Sent Bytes: 6.46 MB - Sent packets: 4400 - Received data - Received Bytes: 80.66 kB - Received packets: 1641 - Timestamps - Initial Timestamp: 13/08/2022 17:36:36 - Final Timestamp: 13/08/2022 17:36:57 - Protocols - Transport layer protocols: TCP - Application layer protocols: unable to identify any level 7 protocol - - -Address: 192.168.1.233:60485 - Sent data - Sent Bytes: 3.65 MB - Sent packets: 3084 - Received data - Received Bytes: 114.22 kB - Received packets: 2105 - Timestamps - Initial Timestamp: 13/08/2022 17:36:36 - Final Timestamp: 13/08/2022 17:36:53 - Protocols - Transport layer protocols: TCP - Application layer protocols: unable to identify any level 7 protocol - - -Address: 192.168.1.233:60478 - Sent data - Sent Bytes: 54.55 kB - Sent packets: 1349 - Received data - Received Bytes: 4.60 MB - Received packets: 3135 - Timestamps - Initial Timestamp: 13/08/2022 17:36:22 - Final Timestamp: 13/08/2022 17:36:46 - Protocols - Transport layer protocols: TCP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:49518 - Sent data - Sent Bytes: 371.86 kB - Sent packets: 1908 - Received data - Received Bytes: 1.74 MB - Received packets: 2294 - Timestamps - Initial Timestamp: 13/08/2022 17:36:29 - Final Timestamp: 13/08/2022 17:37:17 - Protocols - Transport layer protocols: UDP - Application layer protocols: HTTPS - - -Address: 172.224.58.14:443 - Sent data - Sent Bytes: 1.74 MB - Sent packets: 2294 - Received data - Received Bytes: 371.86 kB - Received packets: 1908 - Timestamps - Initial Timestamp: 13/08/2022 17:36:29 - Final Timestamp: 13/08/2022 17:37:17 - Protocols - Transport layer protocols: UDP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:60479 - Sent data - Sent Bytes: 46.94 kB - Sent packets: 1117 - Received data - Received Bytes: 4.14 MB - Received packets: 2821 - Timestamps - Initial Timestamp: 13/08/2022 17:36:53 - Final Timestamp: 13/08/2022 17:37:01 - Protocols - Transport layer protocols: TCP - Application layer protocols: HTTPS - - -Address: 74.125.99.60:443 - Sent data - Sent Bytes: 2.37 MB - Sent packets: 2005 - Received data - Received Bytes: 56.84 kB - Received packets: 942 - Timestamps - Initial Timestamp: 13/08/2022 17:36:42 - Final Timestamp: 13/08/2022 17:36:54 - Protocols - Transport layer protocols: UDP, TCP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:58853 - Sent data - Sent Bytes: 56.75 kB - Sent packets: 939 - Received data - Received Bytes: 2.37 MB - Received packets: 2003 - Timestamps - Initial Timestamp: 13/08/2022 17:36:42 - Final Timestamp: 13/08/2022 17:36:54 - Protocols - Transport layer protocols: UDP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:60487 - Sent data - Sent Bytes: 1.26 MB - Sent packets: 877 - Received data - Received Bytes: 36.05 kB - Received packets: 690 - Timestamps - Initial Timestamp: 13/08/2022 17:36:36 - Final Timestamp: 13/08/2022 17:36:54 - Protocols - Transport layer protocols: TCP - Application layer protocols: unable to identify any level 7 protocol - - -Address: 192.168.1.233:60488 - Sent data - Sent Bytes: 1.29 MB - Sent packets: 890 - Received data - Received Bytes: 33.62 kB - Received packets: 593 - Timestamps - Initial Timestamp: 13/08/2022 17:36:36 - Final Timestamp: 13/08/2022 17:36:54 - Protocols - Transport layer protocols: TCP - Application layer protocols: unable to identify any level 7 protocol - - -Address: 188.114.96.7:443 - Sent data - Sent Bytes: 853.09 kB - Sent packets: 901 - Received data - Received Bytes: 121.52 kB - Received packets: 446 - Timestamps - Initial Timestamp: 13/08/2022 17:37:02 - Final Timestamp: 13/08/2022 17:37:17 - Protocols - Transport layer protocols: UDP - Application layer protocols: HTTPS - - -Address: 192.168.1.233:55560 - Sent data - Sent Bytes: 70.95 kB - Sent packets: 242 - Received data - Received Bytes: 494.17 kB - Received packets: 512 - Timestamps - Initial Timestamp: 13/08/2022 17:37:02 - Final Timestamp: 13/08/2022 17:37:15 - Protocols - Transport layer protocols: UDP - Application layer protocols: HTTPS - - diff --git a/packet_sniffer/src/main.rs b/packet_sniffer/src/main.rs index 111276a3..a7007cb3 100644 --- a/packet_sniffer/src/main.rs +++ b/packet_sniffer/src/main.rs @@ -56,30 +56,41 @@ fn main() { let min_packets = args.minimum_packets; let interval = args.interval; - if lowest_port > highest_port { - eprint!("ERROR: Specified lowest port is greater than specified highest port.\n"); + if args.device_list == true { + print_device_list(); return; } - if args.device_list == true { - print_device_list(); + if lowest_port > highest_port { + eprint!("\n\tERROR: Specified lowest port is greater than specified highest port.\n\n"); + return; + } + + if interval == 0 { + eprint!("\n\tERROR: Specified time interval is null.\n\n"); return; } let found_device = retrieve_device(adapter); if found_device.name.len() == 0 { - eprint!("ERROR: Specified network adapter does not exist. Use option '-d' to list all the available devices.\n"); + eprint!("\n\tERROR: Specified network adapter does not exist. Use option '-d' to list all the available devices.\n\n"); return; } - let cap = Capture::from_device(found_device.clone()).unwrap() + let cap = Capture::from_device(found_device.clone()) + .expect("Capture initialization error\n") .promisc(true) - .open().unwrap(); + .buffer_size(10_000_000) + .open() + .expect("Capture initialization error\n"); let mutex_map1 = Arc::new(Mutex::new(HashMap::new())); let mutex_map2 = mutex_map1.clone(); + println!("\n\tParsing packets..."); + println!("\tUpdating the file '{}' every {} seconds\n", output_file, interval); + thread::spawn(move || { sleep_and_write_report_loop(lowest_port, highest_port, interval, min_packets, found_device.name, output_file, mutex_map2); }); @@ -137,6 +148,7 @@ fn sleep_and_write_report_loop(lowest_port: u16, highest_port: u16, interval: u6 write!(output,"{}\n\n\n", cornice_string).expect("Error writing output file\n"); let map = mutex_map.lock().expect("Error acquiring mutex\n"); + let mut sorted_vec: Vec<(&AddressPort, &ReportInfo)> = map.iter().collect(); sorted_vec.sort_by(|&(_, a), &(_, b)| (b.received_packets + b.transmitted_packets).cmp(&(a.received_packets + a.transmitted_packets))); @@ -146,7 +158,7 @@ fn sleep_and_write_report_loop(lowest_port: u16, highest_port: u16, interval: u6 write!(output, "Address: {}:{}\n{}\n\n", key.address1, key.port1, val).expect("Error writing output file\n"); } } - println!("Report updated ({})",times_report_updated); + println!("\tReport updated ({})",times_report_updated); } } @@ -160,7 +172,7 @@ fn parse_packets_loop(mut cap: Capture, lowest_port: u16, highest_port: let now = utc.format("%d/%m/%Y %H:%M:%S").to_string(); match PacketHeaders::from_ethernet_slice(&packet) { - Err(value) => println!("Err {:?}", value), + Err(_) => {continue;}, Ok(value) => { let address1; @@ -200,13 +212,13 @@ fn parse_packets_loop(mut cap: Capture, lowest_port: u16, highest_port: .replace(" ", ""); exchanged_bytes = ipv6header.payload_length as u32; } - None => {continue;} + _ => {continue;} } match value.transport { - Some(TransportHeader::Udp(udpheader)) => { - port1 = udpheader.source_port; - port2 = udpheader.destination_port; + Some(TransportHeader::Udp(udp_header)) => { + port1 = udp_header.source_port; + port2 = udp_header.destination_port; transport_protocol = TransProtocol::UDP; application_protocol_1 = from_port_to_application_protocol(port1); if application_protocol_1.is_some() { @@ -217,9 +229,9 @@ fn parse_packets_loop(mut cap: Capture, lowest_port: u16, highest_port: application_protocols.insert(application_protocol_2.unwrap()); } } - Some(TransportHeader::Tcp(tcpheader)) => { - port1 = tcpheader.source_port; - port2 = tcpheader.destination_port; + Some(TransportHeader::Tcp(tcp_header)) => { + port1 = tcp_header.source_port; + port2 = tcp_header.destination_port; transport_protocol = TransProtocol::TCP; application_protocol_1 = from_port_to_application_protocol(port1); if application_protocol_1.is_some() { @@ -289,7 +301,6 @@ fn parse_packets_loop(mut cap: Capture, lowest_port: u16, highest_port: } } Err(_) => { - println!("Err occurred while parsing .next() packet\n"); continue; } } @@ -299,13 +310,18 @@ fn parse_packets_loop(mut cap: Capture, lowest_port: u16, highest_port: fn print_device_list() { + println!(); for dev in Device::list().expect("Error retrieving device list\n") { - print!("Device: {}\n\tAddresses: ", dev.name); - for addr in dev.addresses { - print!("{:?}\n\t\t ", addr.addr); + print!("\tDevice: {}\n\t\tAddresses: ", dev.name); + if dev.addresses.len() == 0 { + println!(); } - println!("\n"); + for addr in dev.addresses { + print!("{:?}\n\t\t\t ", addr.addr); + } + println!(); } + println!(); } diff --git a/packet_sniffer/src/report_info.rs b/packet_sniffer/src/report_info.rs index 1b52477b..d44a30e2 100644 --- a/packet_sniffer/src/report_info.rs +++ b/packet_sniffer/src/report_info.rs @@ -74,4 +74,5 @@ impl fmt::Display for ReportInfo { pub enum TransProtocol { TCP, UDP } #[derive(Debug, Clone, Copy, PartialEq, Eq, Hash)] -pub enum AppProtocol { FTP, SSH, Telnet, SMTP, DNS, DHCP, TFTP, HTTP, POP, NTP, NetBIOS, IMAP, SNMP, BGP, LDAP, HTTPS, LDAPS, FTPS } \ No newline at end of file +pub enum AppProtocol { FTP, SSH, Telnet, SMTP, DNS, DHCP, TFTP, HTTP, POP, + NTP, NetBIOS, IMAP, SNMP, BGP, LDAP, HTTPS, LDAPS, FTPS } \ No newline at end of file diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4 b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4 index 1098934e..451d6573 100755 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4 and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4 differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.1.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.1.rcgu.o index 8ef8f63a..f224de10 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.1.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.1.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.10.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.10.rcgu.o index 733d9ac4..2d58310b 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.10.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.10.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.12.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.12.rcgu.o index 418b4001..fd357d73 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.12.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.12.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.5.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.5.rcgu.o index 2105ea73..0b42fb0a 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.5.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.5.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.6.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.6.rcgu.o index 935b61ad..991d0815 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.6.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.6.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.8.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.8.rcgu.o index 36e27ec7..9d970271 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.8.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.8.rcgu.o differ diff --git a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.9.rcgu.o b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.9.rcgu.o index 4596fde0..1dbfebad 100644 Binary files a/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.9.rcgu.o and b/packet_sniffer/target/debug/deps/packet_sniffer-c6e9037dc10b49f4.packet_sniffer.8a9399c8-cgu.9.rcgu.o differ diff --git a/packet_sniffer/target/debug/packet_sniffer b/packet_sniffer/target/debug/packet_sniffer index 1098934e..451d6573 100755 Binary files a/packet_sniffer/target/debug/packet_sniffer and b/packet_sniffer/target/debug/packet_sniffer differ