Rename options for IP (self and remote) for more clarity

This commit is contained in:
_Frky 2022-12-08 21:28:03 +01:00
parent e541d1f5ee
commit bad2c5e02c
15 changed files with 116 additions and 113 deletions

View file

@ -38,7 +38,7 @@ pub fn repl<'a, 'b>(
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 {
if let Some(ip_addr_list) = masscanned.self_ip_list {
if !ip_addr_list.contains(&ip) {
masscanned.log.arp_drop(arp_req);
return None;
@ -83,8 +83,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut arp_req =

View file

@ -113,7 +113,7 @@ pub fn reply<'a, 'b>(
* is authorized to answer to (avoid answering to packets addressed to
* other machines)
**/
if !get_authorized_eth_addr(&masscanned.mac, masscanned.ip_addresses)
if !get_authorized_eth_addr(&masscanned.mac, masscanned.self_ip_list)
.contains(&eth_req.get_destination())
{
masscanned.log.eth_drop(eth_req, &client_info);
@ -225,8 +225,8 @@ mod tests {
synack_key: [0, 0],
mac: mac,
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
for proto in [EtherTypes::Ipv4, EtherTypes::Ipv6, EtherTypes::Arp] {
@ -264,8 +264,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut eth_req = MutableEthernetPacket::owned(vec![

View file

@ -47,18 +47,18 @@ pub fn repl<'a, 'b>(
* 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 let Some(ip_addr_list) = masscanned.self_ip_list {
if !ip_addr_list.contains(&IpAddr::V4(ip_req.get_destination())) {
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
}
/* If masscanned is configured with ignored IP addresses, then
/* If masscanned is configured with a remote ip deny list, then
* check if the src. IP address of the packet is one of
* those ignored by masscanned - if so, drop the packet.
**/
if let Some(ignored_ip_addr_list) = masscanned.ignored_ip_addresses {
if ignored_ip_addr_list.contains(&IpAddr::V4(ip_req.get_source())) {
if let Some(remote_ip_deny_list) = masscanned.remote_ip_deny_list {
if remote_ip_deny_list.contains(&IpAddr::V4(ip_req.get_source())) {
masscanned.log.ipv4_drop(&ip_req, &client_info);
return None;
}
@ -202,8 +202,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
for proto in [
@ -253,8 +253,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: Some(&blacklist_ips),
self_ip_list: Some(&ips),
remote_ip_deny_list: Some(&blacklist_ips),
log: MetaLogger::new(),
};
let mut ip_req =

View file

@ -45,7 +45,7 @@ pub fn repl<'a, 'b>(
* 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 let Some(ip_addr_list) = masscanned.self_ip_list {
if !ip_addr_list.contains(&IpAddr::V6(dst))
&& ip_req.get_next_header() != IpNextHeaderProtocols::Icmpv6
{
@ -53,12 +53,12 @@ pub fn repl<'a, 'b>(
return None;
}
}
/* If masscanned is configured with ignored IP addresses, then
/* If masscanned is configured with a remote ip deny list, then
* check if the src. IP address of the packet is one of
* those ignored by masscanned - if so, drop the packet.
**/
if let Some(ignored_ip_addr_list) = masscanned.ignored_ip_addresses {
if ignored_ip_addr_list.contains(&IpAddr::V6(src)) {
if let Some(remote_ip_deny_list) = masscanned.remote_ip_deny_list {
if remote_ip_deny_list.contains(&IpAddr::V6(src)) {
masscanned.log.ipv6_drop(ip_req, client_info);
return None;
}
@ -215,8 +215,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
for proto in [
@ -270,8 +270,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: Some(&blacklist_ips),
self_ip_list: Some(&ips),
remote_ip_deny_list: Some(&blacklist_ips),
log: MetaLogger::new(),
};
let mut ip_req =

View file

@ -80,8 +80,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut icmp_req =

View file

@ -40,7 +40,7 @@ pub fn nd_ns_repl<'a, 'b>(
* check that the dest. IP address of the packet is one of
* those handled by masscanned - otherwise, drop the packet.
**/
if let Some(addresses) = masscanned.ip_addresses {
if let Some(addresses) = masscanned.self_ip_list {
if !addresses.contains(&IpAddr::V6(nd_ns_req.get_target_addr())) {
return None;
}
@ -172,8 +172,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
/* Legitimate solicitation */
@ -246,8 +246,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut icmpv6_echo_req = MutableIcmpv6Packet::owned(vec![

View file

@ -145,8 +145,8 @@ mod tests {
fn test_tcp_fin_ack() {
let masscanned = Masscanned {
mac: MacAddr(0, 0, 0, 0, 0, 0),
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f],
iface: None,
log: MetaLogger::new(),
@ -197,8 +197,8 @@ mod tests {
fn test_tcp_fin_ack_wrap() {
let masscanned = Masscanned {
mac: MacAddr(0, 0, 0, 0, 0, 0),
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f],
iface: None,
log: MetaLogger::new(),
@ -249,8 +249,8 @@ mod tests {
fn test_synack_cookie_ipv4() {
let masscanned = Masscanned {
mac: MacAddr(0, 0, 0, 0, 0, 0),
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f],
iface: None,
log: MetaLogger::new(),
@ -300,8 +300,8 @@ mod tests {
fn test_synack_cookie_ipv6() {
let masscanned = Masscanned {
mac: MacAddr(0, 0, 0, 0, 0, 0),
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
synack_key: [0x06a0a1d63f305e9b, 0xd4d4bcbb7304875f],
iface: None,
log: MetaLogger::new(),

View file

@ -56,8 +56,8 @@ pub struct Masscanned<'a> {
pub mac: MacAddr,
/* iface is an Option to make tests easier */
pub iface: Option<&'a NetworkInterface>,
pub ip_addresses: Option<&'a HashSet<IpAddr>>,
pub ignored_ip_addresses: Option<&'a HashSet<IpAddr>>,
pub self_ip_list: Option<&'a HashSet<IpAddr>>,
pub remote_ip_deny_list: Option<&'a HashSet<IpAddr>>,
/* loggers */
pub log: MetaLogger,
}
@ -123,27 +123,29 @@ fn main() {
.num_args(1),
)
.arg(
Arg::new("ipfile")
.long("ip-addr-file")
.help("File with the list of IP addresses to impersonate")
Arg::new("selfipfile")
.long("self-ip-file")
.help("File with the list of IP addresses handled by masscanned")
.num_args(1),
)
.arg(
Arg::new("iplist")
.long("ip-addr")
.help("Inline list of IP addresses to impersonate, comma-separated")
Arg::new("selfiplist")
.long("self-ip-list")
.help("Inline list of IP addresses handled by masscanned, comma-separated")
.num_args(1),
)
.arg(
Arg::new("ignoredipfile")
.long("ignored-ip-addr-file")
.help("File with the list of IP addresses to NOT respond to")
Arg::new("remoteipdenyfile")
.long("remote-ip-deny-file")
.help(
"File with the list of IP addresses from which masscanned will ignore packets",
)
.num_args(1),
)
.arg(
Arg::new("ignorediplist")
.long("ignored-ip-addr")
.help("Inline list of IP addresses to NOT respond to, comma-separated")
Arg::new("remoteipdenylist")
.long("remote-ip-deny-list")
.help("Inline list of IP addresses from which masscanned will ignore packets")
.num_args(1),
)
.arg(
@ -207,9 +209,9 @@ fn main() {
};
/* Parse ip address file specified */
/* FIXME: .and_then(|path| File::open(path).map(|file| )).unwrap_or_default() ? */
let mut ip_list = if let Some(ref path) = args.get_one::<String>("ipfile") {
let mut ip_list = if let Some(ref path) = args.get_one::<String>("selfipfile") {
if let Ok(file) = File::open(path) {
info!("parsing ip address file: {}", &path);
info!("parsing self ip file: {}", &path);
file.extract_ip_addresses_only(None)
} else {
HashSet::new()
@ -217,10 +219,10 @@ fn main() {
} else {
HashSet::new()
};
if let Some(ip_inline_list) = args.get_one::<String>("iplist") {
ip_list.extend(ip_inline_list.extract_ip_addresses_only(None));
if let Some(ip_inline) = args.get_one::<String>("selfiplist") {
ip_list.extend(ip_inline.extract_ip_addresses_only(None));
}
let ip_addresses = if !ip_list.is_empty() {
let self_ip_list = if !ip_list.is_empty() {
for ip in &ip_list {
info!("binding........{}", ip);
}
@ -230,9 +232,10 @@ fn main() {
info!("binding........::");
None
};
let mut ignored_ip_list = if let Some(ref path) = args.get_one::<String>("ignoredipfile") {
/* Parse remote ip deny file specified */
let mut ip_list = if let Some(ref path) = args.get_one::<String>("remoteipdenyfile") {
if let Ok(file) = File::open(path) {
info!("parsing ignored ip address file: {}", &path);
info!("parsing remote ip deny file: {}", &path);
file.extract_ip_addresses_only(None)
} else {
HashSet::new()
@ -240,14 +243,14 @@ fn main() {
} else {
HashSet::new()
};
if let Some(ignored_ip_inline_list) = args.get_one::<String>("ignorediplist") {
ignored_ip_list.extend(ignored_ip_inline_list.extract_ip_addresses_only(None));
if let Some(ip_inline) = args.get_one::<String>("remoteipdenylist") {
ip_list.extend(ip_inline.extract_ip_addresses_only(None));
}
let ignored_ip_addresses = if !ignored_ip_list.is_empty() {
for ip in &ignored_ip_list {
let remote_ip_deny_list = if !ip_list.is_empty() {
for ip in &ip_list {
info!("ignoring.......{}", ip);
}
Some(&ignored_ip_list)
Some(&ip_list)
} else {
None
};
@ -256,8 +259,8 @@ fn main() {
synack_key: [0, 0],
mac,
iface: Some(&iface),
ip_addresses,
ignored_ip_addresses,
self_ip_list,
remote_ip_deny_list,
log: MetaLogger::new(),
};
info!("interface......{}", masscanned.iface.unwrap().name);

View file

@ -292,8 +292,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -316,8 +316,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -341,8 +341,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -366,8 +366,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();

View file

@ -628,8 +628,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut client_info = ClientInfo::new();

View file

@ -238,8 +238,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let ip_src = IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1));
@ -306,8 +306,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();

View file

@ -215,8 +215,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
/***** TEST STUN - MAGIC *****/
@ -276,8 +276,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
/***** TEST SSH *****/
@ -318,8 +318,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
/***** TEST GHOST *****/
@ -352,8 +352,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
/***** TEST COMPLETE REQUEST *****/
@ -374,8 +374,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let mut client_info = ClientInfo::new();

View file

@ -1199,8 +1199,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -1268,8 +1268,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -1332,8 +1332,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();
@ -1394,8 +1394,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:00:00:00:00:00").expect("error parsing default MAC address"),
iface: None,
ip_addresses: None,
ignored_ip_addresses: None,
self_ip_list: None,
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let client_info = ClientInfo::new();

View file

@ -442,8 +442,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let payload_resp = if let Some(r) = repl(payload, &masscanned, &mut client_info, None) {
@ -503,8 +503,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
client_info.ip.src = Some(IpAddr::V6(test_ip_addr));
@ -556,8 +556,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
client_info.ip.src = Some(IpAddr::V4(test_ip_addr));
@ -607,8 +607,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
client_info.ip.src = Some(IpAddr::V4(test_ip_addr));

View file

@ -111,8 +111,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let cookie = synackcookie::generate(&client_info, &masscanned.synack_key).unwrap();
@ -166,8 +166,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let cookie = synackcookie::generate(&client_info, &masscanned.synack_key).unwrap();
@ -227,8 +227,8 @@ mod tests {
synack_key: [0, 0],
mac: MacAddr::from_str("00:11:22:33:44:55").expect("error parsing MAC address"),
iface: None,
ip_addresses: Some(&ips),
ignored_ip_addresses: None,
self_ip_list: Some(&ips),
remote_ip_deny_list: None,
log: MetaLogger::new(),
};
let cookie = synackcookie::generate(&client_info, &masscanned.synack_key).unwrap();