From e76ba126119b05291bee9a13838c8bd9f6051ded Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Thu, 23 Dec 2021 14:08:20 +0100 Subject: [PATCH 01/12] Add Logger Trait and ConsoleLogger as an example for ARP and Ethernet --- src/layer_2/arp.rs | 16 ++--- src/layer_2/mod.rs | 2 +- src/masscanned.rs | 9 ++- src/utils/loggers.rs | 146 +++++++++++++++++++++++++++++++++++++++++++ src/utils/mod.rs | 2 + 5 files changed, 162 insertions(+), 13 deletions(-) create mode 100644 src/utils/loggers.rs diff --git a/src/layer_2/arp.rs b/src/layer_2/arp.rs index 4798c22..ae4fd52 100644 --- a/src/layer_2/arp.rs +++ b/src/layer_2/arp.rs @@ -29,20 +29,18 @@ pub fn repl<'a, 'b>( arp_req: &'a ArpPacket, masscanned: &Masscanned, ) -> Option> { + masscanned.log.arp_recv(arp_req); let mut arp_repl = MutableArpPacket::owned(arp_req.packet().to_vec()).expect("error parsing ARP packet"); /* Build ARP answer depending of the type of request */ match arp_req.get_operation() { ArpOperations::Request => { + masscanned.log.arp_recv_whohas(arp_req); let ip = IpAddr::V4(arp_req.get_target_proto_addr()); /* Ignore ARP requests for IP addresses not handled by masscanned */ if let Some(ip_addr_list) = masscanned.ip_addresses { if !ip_addr_list.contains(&ip) { - info!( - "Ignoring ARP request from {} for IP {}", - arp_req.get_sender_hw_addr(), - ip - ); + masscanned.log.arp_drop(arp_req); return None; } } @@ -53,14 +51,12 @@ pub fn repl<'a, 'b>( arp_repl.set_target_hw_addr(arp_req.get_sender_hw_addr().to_owned()); arp_repl.set_target_proto_addr(arp_req.get_sender_proto_addr().to_owned()); arp_repl.set_sender_proto_addr(arp_req.get_target_proto_addr().to_owned()); - warn!( - "ARP-Reply to {} for IP {}", - arp_req.get_sender_hw_addr(), - arp_repl.get_sender_proto_addr() - ); + masscanned.log.arp_send_isat(&arp_repl); + masscanned.log.arp_send(&arp_repl); } _ => { info!("ARP Operation not handled: {:?}", arp_repl.get_operation()); + masscanned.log.arp_drop(arp_req); return None; } }; diff --git a/src/layer_2/mod.rs b/src/layer_2/mod.rs index 75d4af8..528c224 100644 --- a/src/layer_2/mod.rs +++ b/src/layer_2/mod.rs @@ -104,7 +104,7 @@ pub fn reply<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { - debug!("receiving Ethernet packet: {:?}", eth_req); + masscanned.log.eth_recv(eth_req, &client_info); let mut eth_repl; /* First, check if the destination MAC address is one of those masscanned * is authorized to answer to (avoid answering to packets addressed to diff --git a/src/masscanned.rs b/src/masscanned.rs index ff8f2c8..250dabe 100644 --- a/src/masscanned.rs +++ b/src/masscanned.rs @@ -35,7 +35,7 @@ use pnet::{ util::MacAddr, }; -use crate::utils::IpAddrParser; +use crate::utils::{IpAddrParser, ConsoleLogger, MetaLogger}; mod client; mod layer_2; @@ -55,6 +55,8 @@ pub struct Masscanned<'a> { /* iface is an Option to make tests easier */ pub iface: Option<&'a NetworkInterface>, pub ip_addresses: Option<&'a HashSet>, + /* loggers */ + pub log: MetaLogger, } /* Get the L2 network interface from its name */ @@ -184,14 +186,17 @@ fn main() { } else { None }; - let masscanned = Masscanned { + let mut masscanned = Masscanned { synack_key: [0, 0], mac, iface: Some(&iface), ip_addresses, + log: MetaLogger::new(), }; info!("interface......{}", masscanned.iface.unwrap().name); info!("mac address....{}", masscanned.mac); + masscanned.log.add(Box::new(ConsoleLogger::new())); + masscanned.log.init(); let (mut tx, mut rx) = get_channel(masscanned.iface.unwrap()); loop { /* check if network interface is still up */ diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs new file mode 100644 index 0000000..e7f2ce2 --- /dev/null +++ b/src/utils/loggers.rs @@ -0,0 +1,146 @@ +// This file is part of masscanned. +// Copyright 2021 - The IVRE project +// +// Masscanned is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Masscanned is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Masscanned. If not, see . + +use pnet::packet::{ + arp::{ArpPacket, MutableArpPacket}, + ethernet::{EthernetPacket, MutableEthernetPacket}, +}; + +use crate::client::ClientInfo; + +pub trait Logger { + fn init(&self); + /* list of notifications that a logger might or might not implement */ + /* ARP */ + fn arp_enabled(&self) -> bool { true } + fn arp_recv(&self, _p: &ArpPacket) {} + fn arp_recv_whohas(&self, _p: &ArpPacket) {} + fn arp_drop(&self, _p: &ArpPacket) {} + fn arp_send(&self, _p: &MutableArpPacket) {} + fn arp_send_isat(&self, _p: &MutableArpPacket) {} + /* Ethernet */ + fn eth_enabled(&self) -> bool { true } + fn eth_recv(&self, _p: &EthernetPacket, _c: &ClientInfo) {} + fn eth_drop(&self, _p: &EthernetPacket, _c: &ClientInfo) {} + fn eth_send(&self, _p: &MutableEthernetPacket, _c: &ClientInfo) {} +} + +pub struct ConsoleLogger { + arp: bool, + eth: bool, +} + +impl ConsoleLogger { + pub fn new() -> Self { + ConsoleLogger { + arp: true, + eth: false, + } + } +} + +impl Logger for ConsoleLogger { + fn init(&self) { + println!("arp::init"); + } + fn arp_enabled(&self) -> bool { self.arp } + fn eth_enabled(&self) -> bool { self.arp } + fn arp_recv_whohas(&self, p: &ArpPacket) { + println!("arp::recv\twho-has\t{:}\t{:}\t{:}", p.get_sender_hw_addr(), + p.get_target_hw_addr(), p.get_target_proto_addr()); + } + fn arp_send_isat(&self, p: &MutableArpPacket) { + println!("arp::send\tis-at\t{:}\t{:}\t{:}\t{:}", p.get_sender_hw_addr(), + p.get_sender_proto_addr(), + p.get_target_hw_addr(), p.get_target_proto_addr()); + } +} + +pub struct MetaLogger { + loggers: Vec> +} + +impl MetaLogger { + pub fn new() -> Self { + MetaLogger { + loggers: Vec::new(), + } + } + pub fn add(&mut self, log: Box) { + self.loggers.push(log); + } + pub fn init(&self) { + for l in &self.loggers { + l.init(); + } + } + pub fn arp_recv(&self, p: &ArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_recv(p); + } + } + } + pub fn arp_recv_whohas(&self, p: &ArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_recv_whohas(p); + } + } + } + pub fn arp_drop(&self, p: &ArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_drop(p); + } + } + } + pub fn arp_send(&self, p: &MutableArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_send(p); + } + } + } + pub fn arp_send_isat(&self, p: &MutableArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_send_isat(p); + } + } + } + pub fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_recv(p, c); + } + } + } + pub fn eth_drop(&self, p: &EthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_drop(p, c); + } + } + } + pub fn eth_send(&self, p: &MutableEthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_send(p, c); + } + } + } +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 3c788a6..35ae433 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,3 +1,5 @@ mod parsers; +mod loggers; +pub use loggers::{Logger, ConsoleLogger, MetaLogger}; pub use parsers::IpAddrParser; From 7c4e2bac558533b7d72205024b2c1bf588d5e285 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Thu, 23 Dec 2021 14:53:25 +0100 Subject: [PATCH 02/12] Cargo fmt --- src/masscanned.rs | 2 +- src/utils/loggers.rs | 36 ++++++++++++++++++++++++++---------- src/utils/mod.rs | 4 ++-- 3 files changed, 29 insertions(+), 13 deletions(-) diff --git a/src/masscanned.rs b/src/masscanned.rs index 250dabe..b77d3b4 100644 --- a/src/masscanned.rs +++ b/src/masscanned.rs @@ -35,7 +35,7 @@ use pnet::{ util::MacAddr, }; -use crate::utils::{IpAddrParser, ConsoleLogger, MetaLogger}; +use crate::utils::{ConsoleLogger, IpAddrParser, MetaLogger}; mod client; mod layer_2; diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs index e7f2ce2..a688395 100644 --- a/src/utils/loggers.rs +++ b/src/utils/loggers.rs @@ -25,14 +25,18 @@ pub trait Logger { fn init(&self); /* list of notifications that a logger might or might not implement */ /* ARP */ - fn arp_enabled(&self) -> bool { true } + fn arp_enabled(&self) -> bool { + true + } fn arp_recv(&self, _p: &ArpPacket) {} fn arp_recv_whohas(&self, _p: &ArpPacket) {} fn arp_drop(&self, _p: &ArpPacket) {} fn arp_send(&self, _p: &MutableArpPacket) {} fn arp_send_isat(&self, _p: &MutableArpPacket) {} /* Ethernet */ - fn eth_enabled(&self) -> bool { true } + fn eth_enabled(&self) -> bool { + true + } fn eth_recv(&self, _p: &EthernetPacket, _c: &ClientInfo) {} fn eth_drop(&self, _p: &EthernetPacket, _c: &ClientInfo) {} fn eth_send(&self, _p: &MutableEthernetPacket, _c: &ClientInfo) {} @@ -56,21 +60,33 @@ impl Logger for ConsoleLogger { fn init(&self) { println!("arp::init"); } - fn arp_enabled(&self) -> bool { self.arp } - fn eth_enabled(&self) -> bool { self.arp } + fn arp_enabled(&self) -> bool { + self.arp + } + fn eth_enabled(&self) -> bool { + self.arp + } fn arp_recv_whohas(&self, p: &ArpPacket) { - println!("arp::recv\twho-has\t{:}\t{:}\t{:}", p.get_sender_hw_addr(), - p.get_target_hw_addr(), p.get_target_proto_addr()); + println!( + "arp::recv\twho-has\t{:}\t{:}\t{:}", + p.get_sender_hw_addr(), + p.get_target_hw_addr(), + p.get_target_proto_addr() + ); } fn arp_send_isat(&self, p: &MutableArpPacket) { - println!("arp::send\tis-at\t{:}\t{:}\t{:}\t{:}", p.get_sender_hw_addr(), - p.get_sender_proto_addr(), - p.get_target_hw_addr(), p.get_target_proto_addr()); + println!( + "arp::send\tis-at\t{:}\t{:}\t{:}\t{:}", + p.get_sender_hw_addr(), + p.get_sender_proto_addr(), + p.get_target_hw_addr(), + p.get_target_proto_addr() + ); } } pub struct MetaLogger { - loggers: Vec> + loggers: Vec>, } impl MetaLogger { diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 35ae433..4fbb706 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,5 @@ -mod parsers; mod loggers; +mod parsers; -pub use loggers::{Logger, ConsoleLogger, MetaLogger}; +pub use loggers::{ConsoleLogger, Logger, MetaLogger}; pub use parsers::IpAddrParser; From e9212ae43818a49a9c5ec91438ede37690462899 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Thu, 23 Dec 2021 15:09:48 +0100 Subject: [PATCH 03/12] Fix tests and warning --- src/layer_2/arp.rs | 3 +++ src/layer_2/mod.rs | 3 +++ src/layer_3/ipv4.rs | 3 +++ src/layer_3/ipv6.rs | 3 +++ src/layer_4/icmpv4.rs | 3 +++ src/layer_4/icmpv6.rs | 4 ++++ src/layer_4/tcp.rs | 4 ++++ src/proto/mod.rs | 5 +++++ src/proto/stun.rs | 6 ++++++ src/utils/loggers.rs | 4 ++-- 10 files changed, 36 insertions(+), 2 deletions(-) diff --git a/src/layer_2/arp.rs b/src/layer_2/arp.rs index ae4fd52..6ef6e1f 100644 --- a/src/layer_2/arp.rs +++ b/src/layer_2/arp.rs @@ -72,6 +72,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_arp_reply() { let mut ips = HashSet::new(); @@ -82,6 +84,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let mut arp_req = MutableArpPacket::owned([0; 28].to_vec()).expect("error constructing ARP request"); diff --git a/src/layer_2/mod.rs b/src/layer_2/mod.rs index 528c224..2b3d230 100644 --- a/src/layer_2/mod.rs +++ b/src/layer_2/mod.rs @@ -193,6 +193,8 @@ mod tests { use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; + use crate::utils::MetaLogger; + #[test] fn test_eth_reply() { /* test payload is IP(src="3.2.1.0", dst=".".join(str(b) for b in [0xaa, 0x99, @@ -212,6 +214,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let mut eth_req = MutableEthernetPacket::owned(vec![ 0; diff --git a/src/layer_3/ipv4.rs b/src/layer_3/ipv4.rs index 6be97ba..f3604db 100644 --- a/src/layer_3/ipv4.rs +++ b/src/layer_3/ipv4.rs @@ -163,6 +163,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_ipv4_reply() { /* test payload is scapy> ICMP() */ @@ -178,6 +180,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let mut ip_req = MutableIpv4Packet::owned(vec![0; Ipv4Packet::minimum_packet_size() + payload.len()]) diff --git a/src/layer_3/ipv6.rs b/src/layer_3/ipv6.rs index edc5390..e7de30a 100644 --- a/src/layer_3/ipv6.rs +++ b/src/layer_3/ipv6.rs @@ -166,6 +166,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_ipv6_reply() { /* test payload is scapy> IPv6(src="7777:6666:5555:4444:3333:2222:1111:0000", @@ -187,6 +189,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let mut ip_req = MutableIpv6Packet::owned(vec![0; Ipv6Packet::minimum_packet_size() + payload.len()]) diff --git a/src/layer_4/icmpv4.rs b/src/layer_4/icmpv4.rs index 95cdf7c..e07ce07 100644 --- a/src/layer_4/icmpv4.rs +++ b/src/layer_4/icmpv4.rs @@ -70,6 +70,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_icmpv4_reply() { /* test payload is scapy> ICMP() */ @@ -81,6 +83,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: None, + log: MetaLogger::new(), }; let mut icmp_req = MutableIcmpPacket::owned(vec![0; IcmpPacket::minimum_packet_size() + payload.len()]) diff --git a/src/layer_4/icmpv6.rs b/src/layer_4/icmpv6.rs index 6db03d2..477699f 100644 --- a/src/layer_4/icmpv6.rs +++ b/src/layer_4/icmpv6.rs @@ -160,6 +160,8 @@ mod tests { use pnet::packet::icmpv6::ndp::{MutableNeighborSolicitPacket, NeighborSolicit}; use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_nd_na_reply() { let client_info = ClientInfo::new(); @@ -174,6 +176,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; /* Legitimate solicitation */ let ndp_ns = NeighborSolicit { @@ -246,6 +249,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let mut icmpv6_echo_req = MutableIcmpv6Packet::owned(vec![ 0; diff --git a/src/layer_4/tcp.rs b/src/layer_4/tcp.rs index de20d53..6b64472 100644 --- a/src/layer_4/tcp.rs +++ b/src/layer_4/tcp.rs @@ -126,6 +126,8 @@ mod tests { use pnet::util::MacAddr; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; + use crate::utils::MetaLogger; + #[test] fn test_tcp_fin_ack() { let masscanned = Masscanned { @@ -183,6 +185,7 @@ mod tests { ip_addresses: None, synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f], iface: None, + log: MetaLogger::new(), }; /* reference */ let ip_src = IpAddr::V4(Ipv4Addr::new(27, 198, 143, 1)); @@ -232,6 +235,7 @@ mod tests { ip_addresses: None, synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f], iface: None, + log: MetaLogger::new(), }; /* reference */ let ip_src = IpAddr::V6(Ipv6Addr::new(234, 52, 183, 47, 184, 172, 64, 141)); diff --git a/src/proto/mod.rs b/src/proto/mod.rs index db058cf..0e43750 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -165,6 +165,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_proto_dispatch_stun() { let mut client_info = ClientInfo::new(); @@ -180,6 +182,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; /***** TEST STUN - MAGIC *****/ /* test payload is: @@ -239,6 +242,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; /***** TEST SSH *****/ let payloads = [ @@ -278,6 +282,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; /***** TEST GHOST *****/ let payloads = [ diff --git a/src/proto/stun.rs b/src/proto/stun.rs index 1ddab10..5e8d3d4 100644 --- a/src/proto/stun.rs +++ b/src/proto/stun.rs @@ -413,6 +413,8 @@ mod tests { use pnet::util::MacAddr; + use crate::utils::MetaLogger; + #[test] fn test_proto_stun_ipv4() { /* test payload is: @@ -439,6 +441,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; let payload_resp = if let Some(r) = repl(payload, &masscanned, &mut client_info) { r @@ -498,6 +501,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; client_info.ip.src = Some(IpAddr::V6(test_ip_addr)); client_info.ip.dst = Some(IpAddr::V6(masscanned_ip_addr)); @@ -549,6 +553,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; client_info.ip.src = Some(IpAddr::V4(test_ip_addr)); client_info.ip.dst = Some(IpAddr::V4(masscanned_ip_addr)); @@ -598,6 +603,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; client_info.ip.src = Some(IpAddr::V4(test_ip_addr)); client_info.ip.dst = Some(IpAddr::V4(masscanned_ip_addr)); diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs index a688395..2ae19a5 100644 --- a/src/utils/loggers.rs +++ b/src/utils/loggers.rs @@ -44,14 +44,14 @@ pub trait Logger { pub struct ConsoleLogger { arp: bool, - eth: bool, + _eth: bool, } impl ConsoleLogger { pub fn new() -> Self { ConsoleLogger { arp: true, - eth: false, + _eth: false, } } } From 290f236157c690355d4ee9aba60440cebd31030a Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Thu, 23 Dec 2021 20:44:29 +0100 Subject: [PATCH 04/12] Fix test in proto --- src/proto/mod.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/proto/mod.rs b/src/proto/mod.rs index 0e43750..b0ebe8f 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -315,6 +315,7 @@ mod tests { mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"), iface: None, ip_addresses: Some(&ips), + log: MetaLogger::new(), }; /***** TEST COMPLETE REQUEST *****/ let payload = b"GET / HTTP/1.1\r\n\r\n"; From 908ff3689d6cb5b0efbc2a778ea288febfea1b6b Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Fri, 24 Dec 2021 06:26:52 +0100 Subject: [PATCH 05/12] Fix typo in ConsoleLogger --- src/utils/loggers.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs index 2ae19a5..80b1e55 100644 --- a/src/utils/loggers.rs +++ b/src/utils/loggers.rs @@ -44,14 +44,14 @@ pub trait Logger { pub struct ConsoleLogger { arp: bool, - _eth: bool, + eth: bool, } impl ConsoleLogger { pub fn new() -> Self { ConsoleLogger { arp: true, - _eth: false, + eth: false, } } } @@ -64,7 +64,7 @@ impl Logger for ConsoleLogger { self.arp } fn eth_enabled(&self) -> bool { - self.arp + self.eth } fn arp_recv_whohas(&self, p: &ArpPacket) { println!( From 27f1c4ba651536b751755916017091f8ed2ef7ec Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 08:32:44 +0100 Subject: [PATCH 06/12] Add Console Logger for Ethernet --- src/layer_2/arp.rs | 2 +- src/layer_2/mod.rs | 13 +++++++------ src/utils/loggers.rs | 27 ++++++++++++++++++++++++++- 3 files changed, 34 insertions(+), 8 deletions(-) diff --git a/src/layer_2/arp.rs b/src/layer_2/arp.rs index 6ef6e1f..edea343 100644 --- a/src/layer_2/arp.rs +++ b/src/layer_2/arp.rs @@ -52,7 +52,6 @@ pub fn repl<'a, 'b>( arp_repl.set_target_proto_addr(arp_req.get_sender_proto_addr().to_owned()); arp_repl.set_sender_proto_addr(arp_req.get_target_proto_addr().to_owned()); masscanned.log.arp_send_isat(&arp_repl); - masscanned.log.arp_send(&arp_repl); } _ => { info!("ARP Operation not handled: {:?}", arp_repl.get_operation()); @@ -60,6 +59,7 @@ pub fn repl<'a, 'b>( return None; } }; + masscanned.log.arp_send(&arp_repl); Some(arp_repl) } diff --git a/src/layer_2/mod.rs b/src/layer_2/mod.rs index 2b3d230..7d688cf 100644 --- a/src/layer_2/mod.rs +++ b/src/layer_2/mod.rs @@ -113,11 +113,7 @@ pub fn reply<'a, 'b>( if !get_authorized_eth_addr(&masscanned.mac, masscanned.ip_addresses) .contains(ð_req.get_destination()) { - info!( - "Ignoring Ethernet packet from {} to {}", - eth_req.get_source(), - eth_req.get_destination(), - ); + masscanned.log.eth_drop(eth_req, &client_info); return None; } /* Fill client information for this packet with MAC addresses (src and dst) */ @@ -136,6 +132,7 @@ pub fn reply<'a, 'b>( eth_repl.set_ethertype(EtherTypes::Arp); eth_repl.set_payload(arp_repl.packet()); } else { + masscanned.log.eth_drop(eth_req, &client_info); return None; } } @@ -145,6 +142,7 @@ pub fn reply<'a, 'b>( p } else { warn!("error parsing IPv4 packet"); + masscanned.log.eth_drop(eth_req, &client_info); return None; }; if let Some(mut ipv4_repl) = @@ -158,6 +156,7 @@ pub fn reply<'a, 'b>( eth_repl.set_ethertype(EtherTypes::Ipv4); eth_repl.set_payload(ipv4_repl.packet()); } else { + masscanned.log.eth_drop(eth_req, &client_info); return None; } } @@ -172,18 +171,20 @@ pub fn reply<'a, 'b>( eth_repl.set_ethertype(EtherTypes::Ipv6); eth_repl.set_payload(ipv6_repl.packet()); } else { + masscanned.log.eth_drop(eth_req, &client_info); return None; } } /* Log & drop unknown network protocol */ _ => { info!("Ethernet type not handled: {:?}", eth_req.get_ethertype()); + masscanned.log.eth_drop(eth_req, &client_info); return None; } }; eth_repl.set_source(masscanned.mac); eth_repl.set_destination(eth_req.get_source()); - debug!("sending Ethernet packet: {:?}", eth_repl); + masscanned.log.eth_send(ð_repl, &client_info); Some(eth_repl) } diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs index 80b1e55..a194368 100644 --- a/src/utils/loggers.rs +++ b/src/utils/loggers.rs @@ -51,7 +51,7 @@ impl ConsoleLogger { pub fn new() -> Self { ConsoleLogger { arp: true, - eth: false, + eth: true, } } } @@ -59,6 +59,7 @@ impl ConsoleLogger { impl Logger for ConsoleLogger { fn init(&self) { println!("arp::init"); + println!("eth::init"); } fn arp_enabled(&self) -> bool { self.arp @@ -83,6 +84,30 @@ impl Logger for ConsoleLogger { p.get_target_proto_addr() ); } + fn eth_recv(&self, p: &EthernetPacket, _c: &ClientInfo) { + println!( + "eth::recv\t{:}\t{:}\t{:}", + p.get_ethertype(), + p.get_source(), + p.get_destination(), + ); + } + fn eth_drop(&self, p: &EthernetPacket, _c: &ClientInfo) { + println!( + "eth::drop\t{:}\t{:}\t{:}", + p.get_ethertype(), + p.get_source(), + p.get_destination(), + ); + } + fn eth_send(&self, p: &MutableEthernetPacket, _c: &ClientInfo) { + println!( + "eth::send\t{:}\t{:}\t{:}", + p.get_ethertype(), + p.get_destination(), + p.get_source(), + ); + } } pub struct MetaLogger { From 26f74ad6a5d1c335632290e33a102be82391b7ea Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 09:05:50 +0100 Subject: [PATCH 07/12] Change log format (add timestamp) --- README.md | 25 +++++++++++--- src/layer_2/arp.rs | 4 +-- src/utils/loggers.rs | 79 ++++++++++++++++++++++++++------------------ 3 files changed, 69 insertions(+), 39 deletions(-) diff --git a/README.md b/README.md index 075e7a0..41574c3 100644 --- a/README.md +++ b/README.md @@ -290,12 +290,27 @@ tcpdump: pcap_loop: The interface disappeared 0 packets dropped by kernel ``` -### Logging Policy +## Logging -* `ERR`: any error - will always be displayed. -* `WARN`, `-v`: responses sent by `masscanned`. -* `INFO`, `-vv`: packets not handled, packets ignored. -* `DEBUG`, `-vvv`: all packets received and sent by `masscanned`. +### Console Logger + +**Verbs**: +* `init` +* `recv` +* `send` +* `drop` + +#### ARP + +``` +$ts arp $verb $operation $client_mac $client_ip $masscanned_mac $masscanned_ip +``` + +#### Ethernet + +``` +$ts eth $verb $ethertype $client_mac $masscanned_mac +``` ## To Do diff --git a/src/layer_2/arp.rs b/src/layer_2/arp.rs index edea343..2df1b10 100644 --- a/src/layer_2/arp.rs +++ b/src/layer_2/arp.rs @@ -35,7 +35,7 @@ pub fn repl<'a, 'b>( /* Build ARP answer depending of the type of request */ match arp_req.get_operation() { ArpOperations::Request => { - masscanned.log.arp_recv_whohas(arp_req); + masscanned.log.arp_recv(arp_req); let ip = IpAddr::V4(arp_req.get_target_proto_addr()); /* Ignore ARP requests for IP addresses not handled by masscanned */ if let Some(ip_addr_list) = masscanned.ip_addresses { @@ -51,7 +51,7 @@ pub fn repl<'a, 'b>( arp_repl.set_target_hw_addr(arp_req.get_sender_hw_addr().to_owned()); arp_repl.set_target_proto_addr(arp_req.get_sender_proto_addr().to_owned()); arp_repl.set_sender_proto_addr(arp_req.get_target_proto_addr().to_owned()); - masscanned.log.arp_send_isat(&arp_repl); + masscanned.log.arp_send(&arp_repl); } _ => { info!("ARP Operation not handled: {:?}", arp_repl.get_operation()); diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs index a194368..e1a03f4 100644 --- a/src/utils/loggers.rs +++ b/src/utils/loggers.rs @@ -14,6 +14,8 @@ // You should have received a copy of the GNU General Public License // along with Masscanned. If not, see . +use std::time::SystemTime; + use pnet::packet::{ arp::{ArpPacket, MutableArpPacket}, ethernet::{EthernetPacket, MutableEthernetPacket}, @@ -29,10 +31,8 @@ pub trait Logger { true } fn arp_recv(&self, _p: &ArpPacket) {} - fn arp_recv_whohas(&self, _p: &ArpPacket) {} fn arp_drop(&self, _p: &ArpPacket) {} fn arp_send(&self, _p: &MutableArpPacket) {} - fn arp_send_isat(&self, _p: &MutableArpPacket) {} /* Ethernet */ fn eth_enabled(&self) -> bool { true @@ -54,12 +54,22 @@ impl ConsoleLogger { eth: true, } } + fn prolog(&self, proto: &str, verb: &str, crlf: bool) { + let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); + print!("{}.{}\t{}\t{}{}", + now.as_secs(), + now.subsec_millis(), + proto, + verb, + if crlf { "\n" } else { "\t" }, + ); + } } impl Logger for ConsoleLogger { fn init(&self) { - println!("arp::init"); - println!("eth::init"); + self.prolog("arp", "init", true); + self.prolog("eth", "init", true); } fn arp_enabled(&self) -> bool { self.arp @@ -67,42 +77,61 @@ impl Logger for ConsoleLogger { fn eth_enabled(&self) -> bool { self.eth } - fn arp_recv_whohas(&self, p: &ArpPacket) { + fn arp_recv(&self, p: &ArpPacket) { + self.prolog("arp", "recv", false); println!( - "arp::recv\twho-has\t{:}\t{:}\t{:}", - p.get_sender_hw_addr(), - p.get_target_hw_addr(), - p.get_target_proto_addr() - ); - } - fn arp_send_isat(&self, p: &MutableArpPacket) { - println!( - "arp::send\tis-at\t{:}\t{:}\t{:}\t{:}", + "{:?}\t{:}\t{:}\t{:}\t{:}", + p.get_operation(), p.get_sender_hw_addr(), p.get_sender_proto_addr(), p.get_target_hw_addr(), - p.get_target_proto_addr() + p.get_target_proto_addr(), + ); + } + fn arp_send(&self, p: &MutableArpPacket) { + self.prolog("arp", "send", false); + println!( + "{:?}\t{:}\t{:}\t{:}\t{:}", + p.get_operation(), + p.get_target_hw_addr(), + p.get_target_proto_addr(), + p.get_sender_hw_addr(), + p.get_sender_proto_addr(), + ); + } + fn arp_drop(&self, p: &ArpPacket) { + self.prolog("arp", "drop", false); + println!( + "{:?}\t{:}\t{:}\t{:}\t{:}", + p.get_operation(), + p.get_target_hw_addr(), + p.get_target_proto_addr(), + p.get_sender_hw_addr(), + p.get_sender_proto_addr(), ); } fn eth_recv(&self, p: &EthernetPacket, _c: &ClientInfo) { + self.prolog("eth", "recv", false); println!( - "eth::recv\t{:}\t{:}\t{:}", + "{:}\t{:}\t{:}", p.get_ethertype(), p.get_source(), p.get_destination(), ); } fn eth_drop(&self, p: &EthernetPacket, _c: &ClientInfo) { + self.prolog("eth", "drop", false); println!( - "eth::drop\t{:}\t{:}\t{:}", + "{:}\t{:}\t{:}", p.get_ethertype(), p.get_source(), p.get_destination(), ); } fn eth_send(&self, p: &MutableEthernetPacket, _c: &ClientInfo) { + self.prolog("eth", "send", false); println!( - "eth::send\t{:}\t{:}\t{:}", + "{:}\t{:}\t{:}", p.get_ethertype(), p.get_destination(), p.get_source(), @@ -135,13 +164,6 @@ impl MetaLogger { } } } - pub fn arp_recv_whohas(&self, p: &ArpPacket) { - for l in &self.loggers { - if l.arp_enabled() { - l.arp_recv_whohas(p); - } - } - } pub fn arp_drop(&self, p: &ArpPacket) { for l in &self.loggers { if l.arp_enabled() { @@ -156,13 +178,6 @@ impl MetaLogger { } } } - pub fn arp_send_isat(&self, p: &MutableArpPacket) { - for l in &self.loggers { - if l.arp_enabled() { - l.arp_send_isat(p); - } - } - } pub fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { for l in &self.loggers { if l.eth_enabled() { From 7e5cb39dd3d00df8efe2aadf48d822eb864bbb89 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:14:47 +0100 Subject: [PATCH 08/12] Create crate for logging + add L3-L4 logging functions in Console Logger --- src/logger/console.rs | 307 ++++++++++++++++++++++++++++++++++++++++++ src/logger/meta.rs | 225 +++++++++++++++++++++++++++++++ src/logger/mod.rs | 95 +++++++++++++ src/masscanned.rs | 4 +- src/utils/loggers.rs | 202 --------------------------- src/utils/mod.rs | 2 - 6 files changed, 630 insertions(+), 205 deletions(-) create mode 100644 src/logger/console.rs create mode 100644 src/logger/meta.rs create mode 100644 src/logger/mod.rs delete mode 100644 src/utils/loggers.rs diff --git a/src/logger/console.rs b/src/logger/console.rs new file mode 100644 index 0000000..672b048 --- /dev/null +++ b/src/logger/console.rs @@ -0,0 +1,307 @@ +// This file is part of masscanned. +// Copyright 2021 - The IVRE project +// +// Masscanned is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Masscanned is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Masscanned. If not, see . + +use std::time::SystemTime; + +use pnet::packet::{ + arp::{ArpPacket, MutableArpPacket}, + ethernet::{EthernetPacket, MutableEthernetPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + icmp::{IcmpPacket, MutableIcmpPacket}, + icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, + tcp::{TcpPacket, MutableTcpPacket}, + udp::{UdpPacket, MutableUdpPacket}, +}; + +use crate::client::ClientInfo; +use crate::logger::Logger; + +pub struct ConsoleLogger { + arp: bool, + eth: bool, + ipv4: bool, + ipv6: bool, + icmpv4: bool, + icmpv6: bool, + tcp: bool, + udp: bool, +} + +impl ConsoleLogger { + pub fn new() -> Self { + ConsoleLogger { + arp: true, + eth: true, + ipv4: true, + ipv6: true, + icmpv4: true, + icmpv6: true, + tcp: true, + udp: true, + } + } + fn prolog(&self, proto: &str, verb: &str, crlf: bool) { + let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); + print!("{}.{}\t{}\t{}{}", + now.as_secs(), + now.subsec_millis(), + proto, + verb, + if crlf { "\n" } else { "\t" }, + ); + } + fn client_info(&self, c: &ClientInfo) { + print!("{}\t{}\t{}\t{}\t{}\t{}\t{}\t", + if let Some(m) = c.mac.src { format!("{}", m) } else { "".to_string() }, + if let Some(m) = c.mac.dst { format!("{}", m) } else { "".to_string() }, + if let Some(i) = c.ip.src { format!("{}", i) } else { "".to_string() }, + if let Some(i) = c.ip.dst { format!("{}", i) } else { "".to_string() }, + if let Some(t) = c.transport { format!("{}", t) } else { "".to_string() }, + if let Some(p) = c.port.src { format!("{}", p) } else { "".to_string() }, + if let Some(p) = c.port.dst { format!("{}", p) } else { "".to_string() }, + ); + } +} + +impl Logger for ConsoleLogger { + fn init(&self) { + self.prolog("arp", "init", true); + self.prolog("eth", "init", true); + self.prolog("ipv4", "init", true); + } + /* ARP */ + fn arp_enabled(&self) -> bool { + self.arp + } + fn arp_recv(&self, p: &ArpPacket) { + self.prolog("arp", "recv", false); + println!( + "{:}\t{:}\t{:}\t{:}\t{:?}", + p.get_sender_hw_addr(), + p.get_target_hw_addr(), + p.get_sender_proto_addr(), + p.get_target_proto_addr(), + p.get_operation(), + ); + } + fn arp_drop(&self, p: &ArpPacket) { + self.prolog("arp", "drop", false); + println!( + "{:}\t{:}\t{:}\t{:}\t{:?}", + p.get_sender_hw_addr(), + p.get_target_hw_addr(), + p.get_sender_proto_addr(), + p.get_target_proto_addr(), + p.get_operation(), + ); + } + fn arp_send(&self, p: &MutableArpPacket) { + self.prolog("arp", "send", false); + println!( + "{:}\t{:}\t{:}\t{:}\t{:?}", + p.get_target_hw_addr(), + p.get_sender_hw_addr(), + p.get_target_proto_addr(), + p.get_sender_proto_addr(), + p.get_operation(), + ); + } + /* Ethernet */ + fn eth_enabled(&self) -> bool { + self.eth + } + fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { + self.prolog("eth", "recv", false); + self.client_info(c); + println!( + "{:}", + p.get_ethertype(), + ); + } + fn eth_drop(&self, p: &EthernetPacket, c: &ClientInfo) { + self.prolog("eth", "drop", false); + self.client_info(c); + println!( + "{:}", + p.get_ethertype(), + ); + } + fn eth_send(&self, p: &MutableEthernetPacket, c: &ClientInfo) { + self.prolog("eth", "send", false); + self.client_info(c); + println!( + "{:}", + p.get_ethertype(), + ); + } + /* IPv4 */ + fn ipv4_enabled(&self) -> bool { + self.ipv4 + } + fn ipv4_recv(&self, p: &Ipv4Packet, c: &ClientInfo) { + self.prolog("ipv4", "recv", false); + self.client_info(c); + println!( + "{:}", + p.get_next_level_protocol(), + ); + } + fn ipv4_drop(&self, p: &Ipv4Packet, c: &ClientInfo) { + self.prolog("ipv4", "drop", false); + self.client_info(c); + println!( + "{:}", + p.get_next_level_protocol(), + ); + } + fn ipv4_send(&self, p: &MutableIpv4Packet, c: &ClientInfo) { + self.prolog("ipv4", "send", false); + self.client_info(c); + println!( + "{:}", + p.get_next_level_protocol(), + ); + } + /* IPv6 */ + fn ipv6_enabled(&self) -> bool { + self.ipv6 + } + fn ipv6_recv(&self, p: &Ipv6Packet, c: &ClientInfo) { + self.prolog("ipv6", "recv", false); + self.client_info(c); + println!( + "{:}", + p.get_next_header(), + ); + } + fn ipv6_drop(&self, p: &Ipv6Packet, c: &ClientInfo) { + self.prolog("ipv6", "drop", false); + self.client_info(c); + println!( + "{:}", + p.get_next_header(), + ); + } + fn ipv6_send(&self, p: &MutableIpv6Packet, c: &ClientInfo) { + self.prolog("ipv6", "send", false); + self.client_info(c); + println!( + "{:}", + p.get_next_header(), + ); + } + /* ICMPv4 */ + fn icmpv4_enabled(&self) -> bool { + self.icmpv4 + } + fn icmpv4_recv(&self, p: &IcmpPacket, c: &ClientInfo) { + self.prolog("icmpv4", "recv", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmp_type(), + p.get_icmp_code(), + ); + } + fn icmpv4_drop(&self, p: &IcmpPacket, c: &ClientInfo) { + self.prolog("icmpv4", "drop", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmp_type(), + p.get_icmp_code(), + ); + } + fn icmpv4_send(&self, p: &MutableIcmpPacket, c: &ClientInfo) { + self.prolog("icmpv4", "send", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmp_type(), + p.get_icmp_code(), + ); + } + /* ICMPv6 */ + fn icmpv6_enabled(&self) -> bool { + self.icmpv6 + } + fn icmpv6_recv(&self, p: &Icmpv6Packet, c: &ClientInfo) { + self.prolog("icmpv6", "recv", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmpv6_type(), + p.get_icmpv6_code(), + ); + } + fn icmpv6_drop(&self, p: &Icmpv6Packet, c: &ClientInfo) { + self.prolog("icmpv6", "drop", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmpv6_type(), + p.get_icmpv6_code(), + ); + } + fn icmpv6_send(&self, p: &MutableIcmpv6Packet, c: &ClientInfo) { + self.prolog("icmpv6", "send", false); + self.client_info(c); + println!( + "{:?}\t{:?}", + p.get_icmpv6_type(), + p.get_icmpv6_code(), + ); + } + /* TCP */ + fn tcp_enabled(&self) -> bool { + self.tcp + } + fn tcp_recv(&self, p: &TcpPacket, c: &ClientInfo) { + self.prolog("tcp", "recv", false); + self.client_info(c); + println!(""); + } + fn tcp_drop(&self, p: &TcpPacket, c: &ClientInfo) { + self.prolog("tcp", "drop", false); + self.client_info(c); + println!(""); + } + fn tcp_send(&self, p: &MutableTcpPacket, c: &ClientInfo) { + self.prolog("tcp", "send", false); + self.client_info(c); + println!(""); + } + /* UDP */ + fn udp_enabled(&self) -> bool { + self.udp + } + fn udp_recv(&self, p: &UdpPacket, c: &ClientInfo) { + self.prolog("udp", "recv", false); + self.client_info(c); + println!(""); + } + fn udp_drop(&self, p: &UdpPacket, c: &ClientInfo) { + self.prolog("udp", "drop", false); + self.client_info(c); + println!(""); + } + fn udp_send(&self, p: &MutableUdpPacket, c: &ClientInfo) { + self.prolog("udp", "send", false); + self.client_info(c); + println!(""); + } +} diff --git a/src/logger/meta.rs b/src/logger/meta.rs new file mode 100644 index 0000000..61b4ccb --- /dev/null +++ b/src/logger/meta.rs @@ -0,0 +1,225 @@ +// This file is part of masscanned. +// Copyright 2021 - The IVRE project +// +// Masscanned is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Masscanned is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Masscanned. If not, see . + +use pnet::packet::{ + arp::{ArpPacket, MutableArpPacket}, + ethernet::{EthernetPacket, MutableEthernetPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + icmp::{IcmpPacket, MutableIcmpPacket}, + icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, + tcp::{TcpPacket, MutableTcpPacket}, + udp::{UdpPacket, MutableUdpPacket}, +}; + +use crate::client::ClientInfo; +use crate::logger::Logger; + +pub struct MetaLogger { + loggers: Vec>, +} + +impl MetaLogger { + pub fn new() -> Self { + MetaLogger { + loggers: Vec::new(), + } + } + pub fn add(&mut self, log: Box) { + self.loggers.push(log); + } + pub fn init(&self) { + for l in &self.loggers { + l.init(); + } + } + /* ARP */ + pub fn arp_recv(&self, p: &ArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_recv(p); + } + } + } + pub fn arp_drop(&self, p: &ArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_drop(p); + } + } + } + pub fn arp_send(&self, p: &MutableArpPacket) { + for l in &self.loggers { + if l.arp_enabled() { + l.arp_send(p); + } + } + } + /* Ethernet */ + pub fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_recv(p, c); + } + } + } + pub fn eth_drop(&self, p: &EthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_drop(p, c); + } + } + } + pub fn eth_send(&self, p: &MutableEthernetPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.eth_enabled() { + l.eth_send(p, c); + } + } + } + /* IPv4 */ + pub fn ipv4_recv(&self, p: &Ipv4Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv4_enabled() { + l.ipv4_recv(p, c); + } + } + } + pub fn ipv4_drop(&self, p: &Ipv4Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv4_enabled() { + l.ipv4_drop(p, c); + } + } + } + pub fn ipv4_send(&self, p: &MutableIpv4Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv4_enabled() { + l.ipv4_send(p, c); + } + } + } + /* IPv6 */ + pub fn ipv6_recv(&self, p: &Ipv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv6_enabled() { + l.ipv6_recv(p, c); + } + } + } + pub fn ipv6_drop(&self, p: &Ipv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv6_enabled() { + l.ipv6_drop(p, c); + } + } + } + pub fn ipv6_send(&self, p: &MutableIpv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.ipv6_enabled() { + l.ipv6_send(p, c); + } + } + } + /* ICMPv4 */ + pub fn icmpv4_recv(&self, p: &IcmpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv4_enabled() { + l.icmpv4_recv(p, c); + } + } + } + pub fn icmpv4_drop(&self, p: &IcmpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv4_enabled() { + l.icmpv4_drop(p, c); + } + } + } + pub fn icmpv4_send(&self, p: &MutableIcmpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv4_enabled() { + l.icmpv4_send(p, c); + } + } + } + /* ICMPv6 */ + pub fn icmpv6_recv(&self, p: &Icmpv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv6_enabled() { + l.icmpv6_recv(p, c); + } + } + } + pub fn icmpv6_drop(&self, p: &Icmpv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv6_enabled() { + l.icmpv6_drop(p, c); + } + } + } + pub fn icmpv6_send(&self, p: &MutableIcmpv6Packet, c: &ClientInfo) { + for l in &self.loggers { + if l.icmpv6_enabled() { + l.icmpv6_send(p, c); + } + } + } + /* TCP */ + pub fn tcp_recv(&self, p: &TcpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.tcp_enabled() { + l.tcp_recv(p, c); + } + } + } + pub fn tcp_drop(&self, p: &TcpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.tcp_enabled() { + l.tcp_drop(p, c); + } + } + } + pub fn tcp_send(&self, p: &MutableTcpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.tcp_enabled() { + l.tcp_send(p, c); + } + } + } + /* UDP */ + pub fn udp_recv(&self, p: &UdpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.udp_enabled() { + l.udp_recv(p, c); + } + } + } + pub fn udp_drop(&self, p: &UdpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.udp_enabled() { + l.udp_drop(p, c); + } + } + } + pub fn udp_send(&self, p: &MutableUdpPacket, c: &ClientInfo) { + for l in &self.loggers { + if l.udp_enabled() { + l.udp_send(p, c); + } + } + } +} diff --git a/src/logger/mod.rs b/src/logger/mod.rs new file mode 100644 index 0000000..d3f0d9c --- /dev/null +++ b/src/logger/mod.rs @@ -0,0 +1,95 @@ +// This file is part of masscanned. +// Copyright 2021 - The IVRE project +// +// Masscanned is free software: you can redistribute it and/or modify it +// under the terms of the GNU General Public License as published by +// the Free Software Foundation, either version 3 of the License, or +// (at your option) any later version. +// +// Masscanned is distributed in the hope that it will be useful, but WITHOUT +// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY +// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public +// License for more details. +// +// You should have received a copy of the GNU General Public License +// along with Masscanned. If not, see . + +use pnet::packet::{ + arp::{ArpPacket, MutableArpPacket}, + ethernet::{EthernetPacket, MutableEthernetPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + icmp::{IcmpPacket, MutableIcmpPacket}, + icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, + tcp::{TcpPacket, MutableTcpPacket}, + udp::{UdpPacket, MutableUdpPacket}, +}; + +use crate::client::ClientInfo; + +mod meta; +mod console; + +pub use meta::MetaLogger; +pub use console::ConsoleLogger; + +pub trait Logger { + fn init(&self); + /* list of notifications that a logger might or might not implement */ + /* ARP */ + fn arp_enabled(&self) -> bool { + true + } + fn arp_recv(&self, _p: &ArpPacket) {} + fn arp_drop(&self, _p: &ArpPacket) {} + fn arp_send(&self, _p: &MutableArpPacket) {} + /* Ethernet */ + fn eth_enabled(&self) -> bool { + true + } + fn eth_recv(&self, _p: &EthernetPacket, _c: &ClientInfo) {} + fn eth_drop(&self, _p: &EthernetPacket, _c: &ClientInfo) {} + fn eth_send(&self, _p: &MutableEthernetPacket, _c: &ClientInfo) {} + /* IPv4 */ + fn ipv4_enabled(&self) -> bool { + true + } + fn ipv4_recv(&self, _p: &Ipv4Packet, _c: &ClientInfo) {} + fn ipv4_drop(&self, _p: &Ipv4Packet, _c: &ClientInfo) {} + fn ipv4_send(&self, _p: &MutableIpv4Packet, _c: &ClientInfo) {} + /* IPv6 */ + fn ipv6_enabled(&self) -> bool { + true + } + fn ipv6_recv(&self, _p: &Ipv6Packet, _c: &ClientInfo) {} + fn ipv6_drop(&self, _p: &Ipv6Packet, _c: &ClientInfo) {} + fn ipv6_send(&self, _p: &MutableIpv6Packet, _c: &ClientInfo) {} + /* ICMPv4 */ + fn icmpv4_enabled(&self) -> bool { + true + } + fn icmpv4_recv(&self, _p: &IcmpPacket, _c: &ClientInfo) {} + fn icmpv4_drop(&self, _p: &IcmpPacket, _c: &ClientInfo) {} + fn icmpv4_send(&self, _p: &MutableIcmpPacket, _c: &ClientInfo) {} + /* ICMPv6 */ + fn icmpv6_enabled(&self) -> bool { + true + } + fn icmpv6_recv(&self, _p: &Icmpv6Packet, _c: &ClientInfo) {} + fn icmpv6_drop(&self, _p: &Icmpv6Packet, _c: &ClientInfo) {} + fn icmpv6_send(&self, _p: &MutableIcmpv6Packet, _c: &ClientInfo) {} + /* TCP */ + fn tcp_enabled(&self) -> bool { + true + } + fn tcp_recv(&self, _p: &TcpPacket, _c: &ClientInfo) {} + fn tcp_drop(&self, _p: &TcpPacket, _c: &ClientInfo) {} + fn tcp_send(&self, _p: &MutableTcpPacket, _c: &ClientInfo) {} + /* UDP */ + fn udp_enabled(&self) -> bool { + true + } + fn udp_recv(&self, _p: &UdpPacket, _c: &ClientInfo) {} + fn udp_drop(&self, _p: &UdpPacket, _c: &ClientInfo) {} + fn udp_send(&self, _p: &MutableUdpPacket, _c: &ClientInfo) {} +} diff --git a/src/masscanned.rs b/src/masscanned.rs index b77d3b4..301cb4a 100644 --- a/src/masscanned.rs +++ b/src/masscanned.rs @@ -35,12 +35,14 @@ use pnet::{ util::MacAddr, }; -use crate::utils::{ConsoleLogger, IpAddrParser, MetaLogger}; +use crate::utils::IpAddrParser; +use crate::logger::{ConsoleLogger, MetaLogger}; mod client; mod layer_2; mod layer_3; mod layer_4; +mod logger; mod proto; mod smack; mod synackcookie; diff --git a/src/utils/loggers.rs b/src/utils/loggers.rs deleted file mode 100644 index e1a03f4..0000000 --- a/src/utils/loggers.rs +++ /dev/null @@ -1,202 +0,0 @@ -// This file is part of masscanned. -// Copyright 2021 - The IVRE project -// -// Masscanned is free software: you can redistribute it and/or modify it -// under the terms of the GNU General Public License as published by -// the Free Software Foundation, either version 3 of the License, or -// (at your option) any later version. -// -// Masscanned is distributed in the hope that it will be useful, but WITHOUT -// ANY WARRANTY; without even the implied warranty of MERCHANTABILITY -// or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public -// License for more details. -// -// You should have received a copy of the GNU General Public License -// along with Masscanned. If not, see . - -use std::time::SystemTime; - -use pnet::packet::{ - arp::{ArpPacket, MutableArpPacket}, - ethernet::{EthernetPacket, MutableEthernetPacket}, -}; - -use crate::client::ClientInfo; - -pub trait Logger { - fn init(&self); - /* list of notifications that a logger might or might not implement */ - /* ARP */ - fn arp_enabled(&self) -> bool { - true - } - fn arp_recv(&self, _p: &ArpPacket) {} - fn arp_drop(&self, _p: &ArpPacket) {} - fn arp_send(&self, _p: &MutableArpPacket) {} - /* Ethernet */ - fn eth_enabled(&self) -> bool { - true - } - fn eth_recv(&self, _p: &EthernetPacket, _c: &ClientInfo) {} - fn eth_drop(&self, _p: &EthernetPacket, _c: &ClientInfo) {} - fn eth_send(&self, _p: &MutableEthernetPacket, _c: &ClientInfo) {} -} - -pub struct ConsoleLogger { - arp: bool, - eth: bool, -} - -impl ConsoleLogger { - pub fn new() -> Self { - ConsoleLogger { - arp: true, - eth: true, - } - } - fn prolog(&self, proto: &str, verb: &str, crlf: bool) { - let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); - print!("{}.{}\t{}\t{}{}", - now.as_secs(), - now.subsec_millis(), - proto, - verb, - if crlf { "\n" } else { "\t" }, - ); - } -} - -impl Logger for ConsoleLogger { - fn init(&self) { - self.prolog("arp", "init", true); - self.prolog("eth", "init", true); - } - fn arp_enabled(&self) -> bool { - self.arp - } - fn eth_enabled(&self) -> bool { - self.eth - } - fn arp_recv(&self, p: &ArpPacket) { - self.prolog("arp", "recv", false); - println!( - "{:?}\t{:}\t{:}\t{:}\t{:}", - p.get_operation(), - p.get_sender_hw_addr(), - p.get_sender_proto_addr(), - p.get_target_hw_addr(), - p.get_target_proto_addr(), - ); - } - fn arp_send(&self, p: &MutableArpPacket) { - self.prolog("arp", "send", false); - println!( - "{:?}\t{:}\t{:}\t{:}\t{:}", - p.get_operation(), - p.get_target_hw_addr(), - p.get_target_proto_addr(), - p.get_sender_hw_addr(), - p.get_sender_proto_addr(), - ); - } - fn arp_drop(&self, p: &ArpPacket) { - self.prolog("arp", "drop", false); - println!( - "{:?}\t{:}\t{:}\t{:}\t{:}", - p.get_operation(), - p.get_target_hw_addr(), - p.get_target_proto_addr(), - p.get_sender_hw_addr(), - p.get_sender_proto_addr(), - ); - } - fn eth_recv(&self, p: &EthernetPacket, _c: &ClientInfo) { - self.prolog("eth", "recv", false); - println!( - "{:}\t{:}\t{:}", - p.get_ethertype(), - p.get_source(), - p.get_destination(), - ); - } - fn eth_drop(&self, p: &EthernetPacket, _c: &ClientInfo) { - self.prolog("eth", "drop", false); - println!( - "{:}\t{:}\t{:}", - p.get_ethertype(), - p.get_source(), - p.get_destination(), - ); - } - fn eth_send(&self, p: &MutableEthernetPacket, _c: &ClientInfo) { - self.prolog("eth", "send", false); - println!( - "{:}\t{:}\t{:}", - p.get_ethertype(), - p.get_destination(), - p.get_source(), - ); - } -} - -pub struct MetaLogger { - loggers: Vec>, -} - -impl MetaLogger { - pub fn new() -> Self { - MetaLogger { - loggers: Vec::new(), - } - } - pub fn add(&mut self, log: Box) { - self.loggers.push(log); - } - pub fn init(&self) { - for l in &self.loggers { - l.init(); - } - } - pub fn arp_recv(&self, p: &ArpPacket) { - for l in &self.loggers { - if l.arp_enabled() { - l.arp_recv(p); - } - } - } - pub fn arp_drop(&self, p: &ArpPacket) { - for l in &self.loggers { - if l.arp_enabled() { - l.arp_drop(p); - } - } - } - pub fn arp_send(&self, p: &MutableArpPacket) { - for l in &self.loggers { - if l.arp_enabled() { - l.arp_send(p); - } - } - } - pub fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { - for l in &self.loggers { - if l.eth_enabled() { - l.eth_recv(p, c); - } - } - } - pub fn eth_drop(&self, p: &EthernetPacket, c: &ClientInfo) { - for l in &self.loggers { - if l.eth_enabled() { - l.eth_drop(p, c); - } - } - } - pub fn eth_send(&self, p: &MutableEthernetPacket, c: &ClientInfo) { - for l in &self.loggers { - if l.eth_enabled() { - l.eth_send(p, c); - } - } - } -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 4fbb706..3c788a6 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -1,5 +1,3 @@ -mod loggers; mod parsers; -pub use loggers::{ConsoleLogger, Logger, MetaLogger}; pub use parsers::IpAddrParser; From 7b431950eb4f17df2c342b15821d33c0f2ff0b05 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:16:37 +0100 Subject: [PATCH 09/12] Add logging function calls for L3 dissectors --- src/layer_2/mod.rs | 6 +++--- src/layer_3/ipv4.rs | 24 ++++++++++-------------- src/layer_3/ipv6.rs | 17 ++++++++++------- 3 files changed, 23 insertions(+), 24 deletions(-) diff --git a/src/layer_2/mod.rs b/src/layer_2/mod.rs index 7d688cf..3f42e51 100644 --- a/src/layer_2/mod.rs +++ b/src/layer_2/mod.rs @@ -104,6 +104,9 @@ pub fn reply<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { + /* Fill client information for this packet with MAC addresses (src and dst) */ + client_info.mac.src = Some(eth_req.get_source()); + client_info.mac.dst = Some(eth_req.get_destination()); masscanned.log.eth_recv(eth_req, &client_info); let mut eth_repl; /* First, check if the destination MAC address is one of those masscanned @@ -116,9 +119,6 @@ pub fn reply<'a, 'b>( masscanned.log.eth_drop(eth_req, &client_info); return None; } - /* Fill client information for this packet with MAC addresses (src and dst) */ - client_info.mac.src = Some(eth_req.get_source()); - client_info.mac.dst = Some(eth_req.get_destination()); /* Build next layer payload for answer depending on the incoming packet */ match eth_req.get_ethertype() { /* Construct answer to ARP request */ diff --git a/src/layer_3/ipv4.rs b/src/layer_3/ipv4.rs index f3604db..fd4e133 100644 --- a/src/layer_3/ipv4.rs +++ b/src/layer_3/ipv4.rs @@ -39,24 +39,20 @@ pub fn repl<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { - debug!("receiving IPv4 packet: {:?}", ip_req); + /* Fill client info with source and dest. IP addresses */ + client_info.ip.src = Some(IpAddr::V4(ip_req.get_source())); + client_info.ip.dst = Some(IpAddr::V4(ip_req.get_destination())); + masscanned.log.ipv4_recv(&ip_req, &client_info); /* If masscanned is configured with IP addresses, then * check that the dest. IP address of the packet is one of * those handled by masscanned - otherwise, drop the packet. **/ if let Some(ip_addr_list) = masscanned.ip_addresses { if !ip_addr_list.contains(&IpAddr::V4(ip_req.get_destination())) { - info!( - "Ignoring IP packet from {} for {}", - ip_req.get_source(), - ip_req.get_destination() - ); + masscanned.log.ipv4_drop(&ip_req, &client_info); return None; } } - /* Fill client info with source and dest. IP addresses */ - client_info.ip.src = Some(IpAddr::V4(ip_req.get_source())); - client_info.ip.dst = Some(IpAddr::V4(ip_req.get_destination())); /* Fill client info with transport layer procotol */ client_info.transport = Some(ip_req.get_next_level_protocol()); let mut ip_repl; @@ -77,6 +73,7 @@ pub fn repl<'a, 'b>( ip_repl.set_payload(icmp_repl.packet()); ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Icmp); } else { + masscanned.log.ipv4_drop(&ip_req, &client_info); return None; } } @@ -99,6 +96,7 @@ pub fn repl<'a, 'b>( ip_repl.set_payload(tcp_repl.packet()); ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Tcp); } else { + masscanned.log.ipv4_drop(&ip_req, &client_info); return None; } } @@ -123,15 +121,13 @@ pub fn repl<'a, 'b>( ip_repl.set_payload(udp_repl.packet()); ip_repl.set_next_level_protocol(IpNextHeaderProtocols::Udp); } else { + masscanned.log.ipv4_drop(&ip_req, &client_info); return None; } } /* Next layer protocol not handled (yet) - dropping packet */ _ => { - info!( - "IPv4 upper layer not handled: {:?}", - ip_req.get_next_level_protocol() - ); + masscanned.log.ipv4_drop(&ip_req, &client_info); return None; } }; @@ -150,7 +146,7 @@ pub fn repl<'a, 'b>( /* FIXME when dest. was a multicast IP address */ ip_repl.set_source(ip_req.get_destination()); ip_repl.set_destination(ip_req.get_source()); - debug!("sending IPv4 packet: {:?}", ip_repl); + masscanned.log.ipv4_send(&ip_repl, &client_info); Some(ip_repl) } diff --git a/src/layer_3/ipv6.rs b/src/layer_3/ipv6.rs index e7de30a..3fd7a52 100644 --- a/src/layer_3/ipv6.rs +++ b/src/layer_3/ipv6.rs @@ -35,7 +35,10 @@ pub fn repl<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { - debug!("receiving IPv6 packet: {:?}", ip_req); + /* Fill client info with source and dest. IP address */ + client_info.ip.src = Some(IpAddr::V6(ip_req.get_source())); + client_info.ip.dst = Some(IpAddr::V6(ip_req.get_destination())); + masscanned.log.ipv6_recv(ip_req, client_info); let src = ip_req.get_source(); let mut dst = ip_req.get_destination(); /* If masscanned is configured with IP addresses, check that @@ -46,7 +49,7 @@ pub fn repl<'a, 'b>( if !ip_addr_list.contains(&IpAddr::V6(dst)) && ip_req.get_next_header() != IpNextHeaderProtocols::Icmpv6 { - info!("Ignoring IP packet from {} for {}", &src, &dst); + masscanned.log.ipv6_drop(ip_req, client_info); return None; } } @@ -84,6 +87,7 @@ pub fn repl<'a, 'b>( ip_repl.set_hop_limit(255); }; } else { + masscanned.log.ipv6_drop(ip_req, client_info); return None; } } @@ -108,6 +112,7 @@ pub fn repl<'a, 'b>( ip_repl.set_payload_length(tcp_len as u16); ip_repl.set_payload(&tcp_repl.packet()); } else { + masscanned.log.ipv6_drop(ip_req, client_info); return None; } } @@ -132,15 +137,13 @@ pub fn repl<'a, 'b>( ip_repl.set_payload_length(udp_len as u16); ip_repl.set_payload(&udp_repl.packet()); } else { + masscanned.log.ipv6_drop(ip_req, client_info); return None; } } /* Other protocols are not handled (yet) - dropping */ _ => { - info!( - "IPv6 upper layer not handled: {:?}", - ip_req.get_next_header() - ); + masscanned.log.ipv6_drop(ip_req, client_info); return None; } }; @@ -153,7 +156,7 @@ pub fn repl<'a, 'b>( /* Set packet source and dest. */ ip_repl.set_source(dst); ip_repl.set_destination(src); - debug!("sending IPv6 packet: {:?}", ip_repl); + masscanned.log.ipv6_send(&ip_repl, client_info); Some(ip_repl) } From 77ee5e2401a791c618098209c9e748f6eecb9f60 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:24:46 +0100 Subject: [PATCH 10/12] Add logging function calls for L4 dissectors --- src/layer_3/ipv6.rs | 1 - src/layer_4/icmpv4.rs | 14 ++-- src/layer_4/icmpv6.rs | 11 +-- src/layer_4/tcp.rs | 11 +-- src/layer_4/udp.rs | 7 +- src/logger/console.rs | 170 +++++++++++++++++++++--------------------- src/logger/meta.rs | 8 +- src/logger/mod.rs | 12 +-- src/masscanned.rs | 2 +- 9 files changed, 113 insertions(+), 123 deletions(-) diff --git a/src/layer_3/ipv6.rs b/src/layer_3/ipv6.rs index 3fd7a52..ab64708 100644 --- a/src/layer_3/ipv6.rs +++ b/src/layer_3/ipv6.rs @@ -14,7 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Masscanned. If not, see . -use log::*; use std::net::IpAddr; use pnet::packet::{ diff --git a/src/layer_4/icmpv4.rs b/src/layer_4/icmpv4.rs index e07ce07..d54c469 100644 --- a/src/layer_4/icmpv4.rs +++ b/src/layer_4/icmpv4.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Masscanned. If not, see . -use log::*; - use pnet::packet::{ icmp::{IcmpCode, IcmpPacket, IcmpTypes, MutableIcmpPacket}, Packet, @@ -26,16 +24,16 @@ use crate::Masscanned; pub fn repl<'a, 'b>( icmp_req: &'a IcmpPacket, - _masscanned: &Masscanned, - mut _client_info: &ClientInfo, + masscanned: &Masscanned, + client_info: &ClientInfo, ) -> Option> { - debug!("receiving ICMPv4 packet: {:?}", icmp_req); + masscanned.log.icmpv4_recv(icmp_req, client_info); let mut icmp_repl; match icmp_req.get_icmp_type() { IcmpTypes::EchoRequest => { /* Check code of ICMP packet */ if icmp_req.get_icmp_code() != IcmpCode(0) { - info!("ICMP code not handled: {:?}", icmp_req.get_icmp_code()); + masscanned.log.icmpv4_drop(icmp_req, client_info); return None; } /* Compute answer length */ @@ -53,13 +51,13 @@ pub fn repl<'a, 'b>( * reply message." **/ icmp_repl.set_payload(icmp_req.payload()); - warn!("ICMP-Echo-Reply to ICMP-Echo-Request"); } _ => { + masscanned.log.icmpv4_drop(icmp_req, client_info); return None; } }; - debug!("sending ICMPv4 packet: {:?}", icmp_repl); + masscanned.log.icmpv4_send(&icmp_repl, client_info); Some(icmp_repl) } diff --git a/src/layer_4/icmpv6.rs b/src/layer_4/icmpv6.rs index 477699f..c295570 100644 --- a/src/layer_4/icmpv6.rs +++ b/src/layer_4/icmpv6.rs @@ -103,7 +103,7 @@ pub fn repl<'a, 'b>( masscanned: &Masscanned, client_info: &ClientInfo, ) -> (Option>, Option) { - debug!("receiving ICMPv6 packet: {:?}", icmp_req); + masscanned.log.icmpv6_recv(icmp_req, client_info); let mut dst_ip = None; if icmp_req.get_icmpv6_code() != Icmpv6Codes::NoCode { return (None, None); @@ -120,6 +120,7 @@ pub fn repl<'a, 'b>( icmp_repl = MutableIcmpv6Packet::owned(nd_na_repl.packet().to_vec()) .expect("error constructing an ICMPv6 packet"); } else { + masscanned.log.icmpv6_drop(icmp_req, client_info); return (None, None); } } @@ -136,17 +137,13 @@ pub fn repl<'a, 'b>( icmp_repl = MutableIcmpv6Packet::owned(vec![0; Icmpv6Packet::packet_size(&echo_repl)]) .expect("error constructing an ICMPv6 packet"); icmp_repl.populate(&echo_repl); - warn!("ICMPv6-Echo-Reply to ICMPv6-Echo-Request"); } _ => { - info!( - "ICMPv6 packet not handled: {:?}", - icmp_req.get_icmpv6_type() - ); + masscanned.log.icmpv6_drop(icmp_req, client_info); return (None, None); } }; - debug!("sending ICMPv6 packet: {:?}", icmp_repl); + masscanned.log.icmpv6_send(&icmp_repl, client_info); (Some(icmp_repl), dst_ip) } diff --git a/src/layer_4/tcp.rs b/src/layer_4/tcp.rs index 6b64472..28b72a0 100644 --- a/src/layer_4/tcp.rs +++ b/src/layer_4/tcp.rs @@ -31,7 +31,7 @@ pub fn repl<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { - debug!("receiving TCP packet: {:?}", tcp_req); + masscanned.log.tcp_recv(tcp_req, client_info); /* Fill client info with source and dest. TCP port */ client_info.port.src = Some(tcp_req.get_source()); client_info.port.dst = Some(tcp_req.get_destination()); @@ -50,7 +50,7 @@ pub fn repl<'a, 'b>( /* Compute syncookie */ if let Ok(cookie) = synackcookie::generate(&client_info, &masscanned.synack_key) { if cookie != ackno { - info!("PSH-ACK ignored: synackcookie not valid"); + masscanned.log.tcp_drop(tcp_req, client_info); return None; } client_info.cookie = Some(cookie); @@ -76,10 +76,12 @@ pub fn repl<'a, 'b>( /* Answer to ACK: nothing */ flags if flags == TcpFlags::ACK => { /* answer here when server needs to speak first after handshake */ + masscanned.log.tcp_drop(tcp_req, client_info); return None; } /* Answer to RST: nothing */ flags if flags == TcpFlags::RST => { + masscanned.log.tcp_drop(tcp_req, client_info); return None; } /* Answer to FIN,ACK with FIN,ACK */ @@ -101,10 +103,9 @@ pub fn repl<'a, 'b>( tcp_repl.set_sequence( synackcookie::generate(&client_info, &masscanned.synack_key).unwrap(), ); - warn!("SYN-ACK to ACK on port {}", tcp_req.get_destination()); } _ => { - info!("TCP flag not handled: {}", tcp_req.get_flags()); + masscanned.log.tcp_drop(tcp_req, client_info); return None; } } @@ -115,7 +116,7 @@ pub fn repl<'a, 'b>( /* Set TCP headers */ tcp_repl.set_data_offset(5); tcp_repl.set_window(65535); - debug!("sending TCP packet: {:?}", tcp_repl); + masscanned.log.tcp_send(&tcp_repl, client_info); Some(tcp_repl) } diff --git a/src/layer_4/udp.rs b/src/layer_4/udp.rs index cdc1d47..75b0b8b 100644 --- a/src/layer_4/udp.rs +++ b/src/layer_4/udp.rs @@ -14,8 +14,6 @@ // You should have received a copy of the GNU General Public License // along with Masscanned. If not, see . -use log::*; - use pnet::packet::{ udp::{MutableUdpPacket, UdpPacket}, Packet, @@ -30,7 +28,7 @@ pub fn repl<'a, 'b>( masscanned: &Masscanned, mut client_info: &mut ClientInfo, ) -> Option> { - debug!("receiving UDP packet: {:?}", udp_req); + masscanned.log.udp_recv(udp_req, client_info); /* Fill client info with source and dest. UDP port */ client_info.port.src = Some(udp_req.get_source()); client_info.port.dst = Some(udp_req.get_destination()); @@ -43,12 +41,13 @@ pub fn repl<'a, 'b>( .expect("error constructing a UDP packet"); udp_repl.set_length(udp_repl.packet().len() as u16); } else { + masscanned.log.udp_drop(udp_req, client_info); return None; } /* Set source and dest. port for response packet from client info */ /* Note: client info could have been modified by upper layers (e.g., STUN) */ udp_repl.set_source(client_info.port.dst.unwrap()); udp_repl.set_destination(client_info.port.src.unwrap()); - debug!("sending UDP packet: {:?}", udp_repl); + masscanned.log.udp_send(&udp_repl, client_info); Some(udp_repl) } diff --git a/src/logger/console.rs b/src/logger/console.rs index 672b048..97fef38 100644 --- a/src/logger/console.rs +++ b/src/logger/console.rs @@ -19,12 +19,12 @@ use std::time::SystemTime; use pnet::packet::{ arp::{ArpPacket, MutableArpPacket}, ethernet::{EthernetPacket, MutableEthernetPacket}, - ipv4::{Ipv4Packet, MutableIpv4Packet}, - ipv6::{Ipv6Packet, MutableIpv6Packet}, icmp::{IcmpPacket, MutableIcmpPacket}, icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, - tcp::{TcpPacket, MutableTcpPacket}, - udp::{UdpPacket, MutableUdpPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + tcp::{MutableTcpPacket, TcpPacket}, + udp::{MutableUdpPacket, UdpPacket}, }; use crate::client::ClientInfo; @@ -55,24 +55,56 @@ impl ConsoleLogger { } } fn prolog(&self, proto: &str, verb: &str, crlf: bool) { - let now = SystemTime::now().duration_since(SystemTime::UNIX_EPOCH).unwrap(); - print!("{}.{}\t{}\t{}{}", + let now = SystemTime::now() + .duration_since(SystemTime::UNIX_EPOCH) + .unwrap(); + print!( + "{}.{}\t{}\t{}{}", now.as_secs(), now.subsec_millis(), proto, verb, if crlf { "\n" } else { "\t" }, - ); + ); } fn client_info(&self, c: &ClientInfo) { - print!("{}\t{}\t{}\t{}\t{}\t{}\t{}\t", - if let Some(m) = c.mac.src { format!("{}", m) } else { "".to_string() }, - if let Some(m) = c.mac.dst { format!("{}", m) } else { "".to_string() }, - if let Some(i) = c.ip.src { format!("{}", i) } else { "".to_string() }, - if let Some(i) = c.ip.dst { format!("{}", i) } else { "".to_string() }, - if let Some(t) = c.transport { format!("{}", t) } else { "".to_string() }, - if let Some(p) = c.port.src { format!("{}", p) } else { "".to_string() }, - if let Some(p) = c.port.dst { format!("{}", p) } else { "".to_string() }, + print!( + "{}\t{}\t{}\t{}\t{}\t{}\t{}\t", + if let Some(m) = c.mac.src { + format!("{}", m) + } else { + "".to_string() + }, + if let Some(m) = c.mac.dst { + format!("{}", m) + } else { + "".to_string() + }, + if let Some(i) = c.ip.src { + format!("{}", i) + } else { + "".to_string() + }, + if let Some(i) = c.ip.dst { + format!("{}", i) + } else { + "".to_string() + }, + if let Some(t) = c.transport { + format!("{}", t) + } else { + "".to_string() + }, + if let Some(p) = c.port.src { + format!("{}", p) + } else { + "".to_string() + }, + if let Some(p) = c.port.dst { + format!("{}", p) + } else { + "".to_string() + }, ); } } @@ -127,26 +159,17 @@ impl Logger for ConsoleLogger { fn eth_recv(&self, p: &EthernetPacket, c: &ClientInfo) { self.prolog("eth", "recv", false); self.client_info(c); - println!( - "{:}", - p.get_ethertype(), - ); + println!("{:}", p.get_ethertype(),); } fn eth_drop(&self, p: &EthernetPacket, c: &ClientInfo) { self.prolog("eth", "drop", false); self.client_info(c); - println!( - "{:}", - p.get_ethertype(), - ); + println!("{:}", p.get_ethertype(),); } fn eth_send(&self, p: &MutableEthernetPacket, c: &ClientInfo) { self.prolog("eth", "send", false); self.client_info(c); - println!( - "{:}", - p.get_ethertype(), - ); + println!("{:}", p.get_ethertype(),); } /* IPv4 */ fn ipv4_enabled(&self) -> bool { @@ -155,26 +178,17 @@ impl Logger for ConsoleLogger { fn ipv4_recv(&self, p: &Ipv4Packet, c: &ClientInfo) { self.prolog("ipv4", "recv", false); self.client_info(c); - println!( - "{:}", - p.get_next_level_protocol(), - ); + println!("{:}", p.get_next_level_protocol(),); } fn ipv4_drop(&self, p: &Ipv4Packet, c: &ClientInfo) { self.prolog("ipv4", "drop", false); self.client_info(c); - println!( - "{:}", - p.get_next_level_protocol(), - ); + println!("{:}", p.get_next_level_protocol(),); } fn ipv4_send(&self, p: &MutableIpv4Packet, c: &ClientInfo) { self.prolog("ipv4", "send", false); self.client_info(c); - println!( - "{:}", - p.get_next_level_protocol(), - ); + println!("{:}", p.get_next_level_protocol(),); } /* IPv6 */ fn ipv6_enabled(&self) -> bool { @@ -183,26 +197,17 @@ impl Logger for ConsoleLogger { fn ipv6_recv(&self, p: &Ipv6Packet, c: &ClientInfo) { self.prolog("ipv6", "recv", false); self.client_info(c); - println!( - "{:}", - p.get_next_header(), - ); + println!("{:}", p.get_next_header(),); } fn ipv6_drop(&self, p: &Ipv6Packet, c: &ClientInfo) { self.prolog("ipv6", "drop", false); self.client_info(c); - println!( - "{:}", - p.get_next_header(), - ); + println!("{:}", p.get_next_header(),); } fn ipv6_send(&self, p: &MutableIpv6Packet, c: &ClientInfo) { self.prolog("ipv6", "send", false); self.client_info(c); - println!( - "{:}", - p.get_next_header(), - ); + println!("{:}", p.get_next_header(),); } /* ICMPv4 */ fn icmpv4_enabled(&self) -> bool { @@ -211,29 +216,17 @@ impl Logger for ConsoleLogger { fn icmpv4_recv(&self, p: &IcmpPacket, c: &ClientInfo) { self.prolog("icmpv4", "recv", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmp_type(), - p.get_icmp_code(), - ); + println!("{:?}\t{:?}", p.get_icmp_type(), p.get_icmp_code(),); } fn icmpv4_drop(&self, p: &IcmpPacket, c: &ClientInfo) { self.prolog("icmpv4", "drop", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmp_type(), - p.get_icmp_code(), - ); + println!("{:?}\t{:?}", p.get_icmp_type(), p.get_icmp_code(),); } fn icmpv4_send(&self, p: &MutableIcmpPacket, c: &ClientInfo) { self.prolog("icmpv4", "send", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmp_type(), - p.get_icmp_code(), - ); + println!("{:?}\t{:?}", p.get_icmp_type(), p.get_icmp_code(),); } /* ICMPv6 */ fn icmpv6_enabled(&self) -> bool { @@ -242,29 +235,17 @@ impl Logger for ConsoleLogger { fn icmpv6_recv(&self, p: &Icmpv6Packet, c: &ClientInfo) { self.prolog("icmpv6", "recv", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmpv6_type(), - p.get_icmpv6_code(), - ); + println!("{:?}\t{:?}", p.get_icmpv6_type(), p.get_icmpv6_code(),); } fn icmpv6_drop(&self, p: &Icmpv6Packet, c: &ClientInfo) { self.prolog("icmpv6", "drop", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmpv6_type(), - p.get_icmpv6_code(), - ); + println!("{:?}\t{:?}", p.get_icmpv6_type(), p.get_icmpv6_code(),); } fn icmpv6_send(&self, p: &MutableIcmpv6Packet, c: &ClientInfo) { self.prolog("icmpv6", "send", false); self.client_info(c); - println!( - "{:?}\t{:?}", - p.get_icmpv6_type(), - p.get_icmpv6_code(), - ); + println!("{:?}\t{:?}", p.get_icmpv6_type(), p.get_icmpv6_code(),); } /* TCP */ fn tcp_enabled(&self) -> bool { @@ -273,33 +254,48 @@ impl Logger for ConsoleLogger { fn tcp_recv(&self, p: &TcpPacket, c: &ClientInfo) { self.prolog("tcp", "recv", false); self.client_info(c); - println!(""); + println!( + "{:?}\t{:}\t{:}", + p.get_flags(), + p.get_sequence(), + p.get_acknowledgement(), + ); } fn tcp_drop(&self, p: &TcpPacket, c: &ClientInfo) { self.prolog("tcp", "drop", false); self.client_info(c); - println!(""); + println!( + "{:?}\t{:}\t{:}", + p.get_flags(), + p.get_sequence(), + p.get_acknowledgement(), + ); } fn tcp_send(&self, p: &MutableTcpPacket, c: &ClientInfo) { self.prolog("tcp", "send", false); self.client_info(c); - println!(""); + println!( + "{:?}\t{:}\t{:}", + p.get_flags(), + p.get_sequence(), + p.get_acknowledgement(), + ); } /* UDP */ fn udp_enabled(&self) -> bool { self.udp } - fn udp_recv(&self, p: &UdpPacket, c: &ClientInfo) { + fn udp_recv(&self, _p: &UdpPacket, c: &ClientInfo) { self.prolog("udp", "recv", false); self.client_info(c); println!(""); } - fn udp_drop(&self, p: &UdpPacket, c: &ClientInfo) { + fn udp_drop(&self, _p: &UdpPacket, c: &ClientInfo) { self.prolog("udp", "drop", false); self.client_info(c); println!(""); } - fn udp_send(&self, p: &MutableUdpPacket, c: &ClientInfo) { + fn udp_send(&self, _p: &MutableUdpPacket, c: &ClientInfo) { self.prolog("udp", "send", false); self.client_info(c); println!(""); diff --git a/src/logger/meta.rs b/src/logger/meta.rs index 61b4ccb..94c752b 100644 --- a/src/logger/meta.rs +++ b/src/logger/meta.rs @@ -17,12 +17,12 @@ use pnet::packet::{ arp::{ArpPacket, MutableArpPacket}, ethernet::{EthernetPacket, MutableEthernetPacket}, - ipv4::{Ipv4Packet, MutableIpv4Packet}, - ipv6::{Ipv6Packet, MutableIpv6Packet}, icmp::{IcmpPacket, MutableIcmpPacket}, icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, - tcp::{TcpPacket, MutableTcpPacket}, - udp::{UdpPacket, MutableUdpPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + tcp::{MutableTcpPacket, TcpPacket}, + udp::{MutableUdpPacket, UdpPacket}, }; use crate::client::ClientInfo; diff --git a/src/logger/mod.rs b/src/logger/mod.rs index d3f0d9c..bcd6f5e 100644 --- a/src/logger/mod.rs +++ b/src/logger/mod.rs @@ -17,21 +17,21 @@ use pnet::packet::{ arp::{ArpPacket, MutableArpPacket}, ethernet::{EthernetPacket, MutableEthernetPacket}, - ipv4::{Ipv4Packet, MutableIpv4Packet}, - ipv6::{Ipv6Packet, MutableIpv6Packet}, icmp::{IcmpPacket, MutableIcmpPacket}, icmpv6::{Icmpv6Packet, MutableIcmpv6Packet}, - tcp::{TcpPacket, MutableTcpPacket}, - udp::{UdpPacket, MutableUdpPacket}, + ipv4::{Ipv4Packet, MutableIpv4Packet}, + ipv6::{Ipv6Packet, MutableIpv6Packet}, + tcp::{MutableTcpPacket, TcpPacket}, + udp::{MutableUdpPacket, UdpPacket}, }; use crate::client::ClientInfo; -mod meta; mod console; +mod meta; -pub use meta::MetaLogger; pub use console::ConsoleLogger; +pub use meta::MetaLogger; pub trait Logger { fn init(&self); diff --git a/src/masscanned.rs b/src/masscanned.rs index 301cb4a..52ed059 100644 --- a/src/masscanned.rs +++ b/src/masscanned.rs @@ -35,8 +35,8 @@ use pnet::{ util::MacAddr, }; -use crate::utils::IpAddrParser; use crate::logger::{ConsoleLogger, MetaLogger}; +use crate::utils::IpAddrParser; mod client; mod layer_2; From f3d8ff3d128cdb01e4ba10742723d2da8a4fb0f8 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:27:10 +0100 Subject: [PATCH 11/12] Fix import in unit tests --- src/layer_2/arp.rs | 2 +- src/layer_2/mod.rs | 2 +- src/layer_3/ipv4.rs | 2 +- src/layer_3/ipv6.rs | 2 +- src/layer_4/icmpv4.rs | 2 +- src/layer_4/icmpv6.rs | 2 +- src/layer_4/tcp.rs | 2 +- src/proto/mod.rs | 2 +- src/proto/stun.rs | 2 +- 9 files changed, 9 insertions(+), 9 deletions(-) diff --git a/src/layer_2/arp.rs b/src/layer_2/arp.rs index 2df1b10..7986028 100644 --- a/src/layer_2/arp.rs +++ b/src/layer_2/arp.rs @@ -72,7 +72,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_arp_reply() { diff --git a/src/layer_2/mod.rs b/src/layer_2/mod.rs index 3f42e51..5e90e96 100644 --- a/src/layer_2/mod.rs +++ b/src/layer_2/mod.rs @@ -194,7 +194,7 @@ mod tests { use std::net::{Ipv4Addr, Ipv6Addr}; use std::str::FromStr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_eth_reply() { diff --git a/src/layer_3/ipv4.rs b/src/layer_3/ipv4.rs index fd4e133..f5d8f25 100644 --- a/src/layer_3/ipv4.rs +++ b/src/layer_3/ipv4.rs @@ -159,7 +159,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_ipv4_reply() { diff --git a/src/layer_3/ipv6.rs b/src/layer_3/ipv6.rs index ab64708..1d4128d 100644 --- a/src/layer_3/ipv6.rs +++ b/src/layer_3/ipv6.rs @@ -168,7 +168,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_ipv6_reply() { diff --git a/src/layer_4/icmpv4.rs b/src/layer_4/icmpv4.rs index d54c469..096f88a 100644 --- a/src/layer_4/icmpv4.rs +++ b/src/layer_4/icmpv4.rs @@ -68,7 +68,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_icmpv4_reply() { diff --git a/src/layer_4/icmpv6.rs b/src/layer_4/icmpv6.rs index c295570..59d48fe 100644 --- a/src/layer_4/icmpv6.rs +++ b/src/layer_4/icmpv6.rs @@ -157,7 +157,7 @@ mod tests { use pnet::packet::icmpv6::ndp::{MutableNeighborSolicitPacket, NeighborSolicit}; use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_nd_na_reply() { diff --git a/src/layer_4/tcp.rs b/src/layer_4/tcp.rs index 28b72a0..6e211f2 100644 --- a/src/layer_4/tcp.rs +++ b/src/layer_4/tcp.rs @@ -127,7 +127,7 @@ mod tests { use pnet::util::MacAddr; use std::net::{IpAddr, Ipv4Addr, Ipv6Addr}; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_tcp_fin_ack() { diff --git a/src/proto/mod.rs b/src/proto/mod.rs index b0ebe8f..7d425bb 100644 --- a/src/proto/mod.rs +++ b/src/proto/mod.rs @@ -165,7 +165,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_proto_dispatch_stun() { diff --git a/src/proto/stun.rs b/src/proto/stun.rs index 5e8d3d4..7dce6bc 100644 --- a/src/proto/stun.rs +++ b/src/proto/stun.rs @@ -413,7 +413,7 @@ mod tests { use pnet::util::MacAddr; - use crate::utils::MetaLogger; + use crate::logger::MetaLogger; #[test] fn test_proto_stun_ipv4() { From 6cace5d64b22eba2311d3bc8175cd26abb169b94 Mon Sep 17 00:00:00 2001 From: _Frky <3105926+Frky@users.noreply.github.com> Date: Sat, 12 Feb 2022 10:33:51 +0100 Subject: [PATCH 12/12] Fix bug --- src/layer_4/tcp.rs | 1 + src/logger/console.rs | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/src/layer_4/tcp.rs b/src/layer_4/tcp.rs index 6e211f2..e0dec1d 100644 --- a/src/layer_4/tcp.rs +++ b/src/layer_4/tcp.rs @@ -136,6 +136,7 @@ mod tests { ip_addresses: None, synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f], iface: None, + log: MetaLogger::new(), }; /* reference */ let ip_src = IpAddr::V4(Ipv4Addr::new(27, 198, 143, 1)); diff --git a/src/logger/console.rs b/src/logger/console.rs index 97fef38..fe7f7ec 100644 --- a/src/logger/console.rs +++ b/src/logger/console.rs @@ -114,6 +114,11 @@ impl Logger for ConsoleLogger { self.prolog("arp", "init", true); self.prolog("eth", "init", true); self.prolog("ipv4", "init", true); + self.prolog("ipv6", "init", true); + self.prolog("icmpv4", "init", true); + self.prolog("icmpv6", "init", true); + self.prolog("tcp", "init", true); + self.prolog("udp", "init", true); } /* ARP */ fn arp_enabled(&self) -> bool {