mirror of
https://github.com/ivre/masscanned.git
synced 2025-10-02 06:38:21 +00:00
Add Console Logger for Ethernet
This commit is contained in:
parent
908ff3689d
commit
27f1c4ba65
3 changed files with 34 additions and 8 deletions
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
||||
|
|
|
@ -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 {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue