use std::net::{IpAddr, Ipv4Addr};
use std::sync::Arc;
use std::time::{Duration, SystemTime};
use crate::config::{IdleScan, ZondConfig};
use crate::evasion::EvasionProfile;
use crate::model::capture::CaptureCounts;
use crate::model::confidence::Confidence;
use crate::model::exclusion::Exclusions;
use crate::model::finding::{
DetectionClass, DetectionId, Excerpt, Finding, Reference, Severity, Version,
};
use crate::model::host::{
EvidenceSource, Filtering, HardwareDescription, HardwareInfo, Hop, Host, HostName, HostStatus,
IpProtocolState, NameKind, NameSource, NetworkRole, OsFingerprint, StatusProtocol,
StatusReason,
};
use crate::model::ip::scoped::Zone;
use crate::model::ip::set::IpSet;
use crate::model::mac::MacAddr;
use crate::model::port::{
CertificateInfo, Discovery, Port, PortState, Protocol, ScanResponse, Security, Service,
};
use crate::model::tls::{
CipherSuite, Interruption, TlsSupport, TlsVersion, UnfinishedVersion, VersionSupport,
};
use crate::protocols::tcp::flags;
use crate::report::ScannerKind;
use crate::report::WindowSummary;
use crate::report::{
Attachment, AttachmentSource, BUCKET_BOUNDS_MS, ProbeStats, ScanKind, ScanReport, StopReason,
TargetScope,
};
use crate::scanner::recorder::PhaseRecorder;
use crate::scanner::session::ScanSession;
use crate::system::privilege::Privilege;
fn ip(last: u8) -> IpAddr {
IpAddr::V4(Ipv4Addr::new(203, 0, 113, last))
}
fn router() -> Host {
let mut host = Host::new(ip(1));
host.set_hostname(Some("router.local".to_string()));
for (kind, name) in [
(NameKind::Host, "gw01.corp.example"),
(NameKind::Domain, "corp.example"),
(NameKind::Forest, "corp.example"),
] {
host.record_name(HostName::new(kind, NameSource::Ldap, name).expect("a name"));
}
host.set_status(HostStatus::Up);
host.add_reason(StatusReason::new(StatusProtocol::Arp, "reply from gateway"));
host.add_reason(
StatusReason::new(
StatusProtocol::IcmpUnreachable,
"unreachable, from the path",
)
.from_source(IpAddr::V4(Ipv4Addr::new(198, 51, 100, 1))),
);
let mut withheld = StatusReason::new(StatusProtocol::IcmpUnreachable, "unreachable");
withheld.source = EvidenceSource::Withheld;
host.add_reason(withheld);
host.record_mac(MacAddr::new(0x2c, 0xcf, 0x67, 0x00, 0x00, 0x01));
let mut os = OsFingerprint::new("Linux", 95)
.with_family("Unix-like")
.with_device("Printer")
.with_generation("5.15.0")
.with_evidence("syn-ack hops>=64 opts=M,S,T,N,W win=65160=45x1448 ws=7 mss=1460");
os.add_cpe("cpe:/o:linux:linux_kernel:5.15.0");
host.set_os(os);
host.add_rtt(Duration::from_micros(1_200));
host.add_rtt(Duration::from_micros(1_800));
host.add_rtt(Duration::from_micros(3_000));
host.record_hop(Hop::withheld(4));
host.record_hop(Hop::answered(
3,
IpAddr::V4(Ipv4Addr::new(198, 51, 100, 1)),
Some(Duration::from_micros(4_100)),
));
host.record_hop(Hop::silent(2));
host.record_hop(
Hop::answered(1, IpAddr::V4(Ipv4Addr::new(203, 0, 113, 254)), None).as_inferred(),
);
host.add_port(https_port());
host.add_port(ssh_port());
host.add_port(Port::new(80, Protocol::Tcp, PortState::Open));
host.add_filtering(Filtering::InlineMiddlebox);
host.add_filtering(Filtering::StatefulFilter);
host.add_filtering(Filtering::PortTrustingAcl);
host.add_filtering(Filtering::StatelessFilter);
host.record_ip_protocol(1, IpProtocolState::Open);
host.record_ip_protocol(47, IpProtocolState::Closed);
host.record_ip_protocol(50, IpProtocolState::Filtered);
host.record_ip_protocol(89, IpProtocolState::OpenFiltered);
host.record_ip_protocol(103, IpProtocolState::Unasked);
host
}
fn ssh_port() -> Port {
let service = Service::new("ssh", 100)
.with_product("OpenSSH")
.with_vendor("OpenBSD")
.with_version("8.9p1")
.with_cpe("cpe:/a:openbsd:openssh:8.9p1");
let discovery = Discovery::new(ScanResponse::TcpSynAck)
.with_rtt(Duration::from_micros(1_450))
.with_ttl(64)
.with_source_ip(ip(50));
Port::new(22, Protocol::Tcp, PortState::Open)
.with_service(service)
.with_discovery(discovery)
}
fn https_port() -> Port {
let certificate = CertificateInfo::new(
"router.local",
"Local CA",
std::time::UNIX_EPOCH + Duration::from_secs(1_767_225_600),
std::time::UNIX_EPOCH + Duration::from_secs(1_798_761_600),
"9f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
)
.with_sans([Arc::from("www.router.local")])
.with_public_key("ECDSA", 256);
let security = Security::new()
.with_tls_version("TLSv1.3")
.with_cipher_suite("TLS_AES_256_GCM_SHA384")
.with_alpn("h2")
.with_alpn("http/1.1")
.with_certificate(certificate)
.with_support(accepted());
Port::new(443, Protocol::Tcp, PortState::Open).with_security(security)
}
fn accepted() -> TlsSupport {
let suite = |code: u16| CipherSuite::from_code(code).expect("a suite in the registry");
TlsSupport::new()
.accepting(VersionSupport::new(
TlsVersion::Tls10,
vec![suite(0x000A), suite(0x002F)],
Vec::new(),
))
.accepting(VersionSupport::new(
TlsVersion::Tls12,
vec![suite(0xC030), suite(0x009C)],
vec![0xFF01],
))
.accepting(VersionSupport::new(
TlsVersion::Tls13,
vec![suite(0x1302)],
Vec::new(),
))
.leaving_unfinished(UnfinishedVersion::new(
TlsVersion::Tls11,
Interruption::Unanswered,
))
.leaving_unfinished(UnfinishedVersion::new(
TlsVersion::Tls12,
Interruption::Stopped,
))
}
fn filtered_host() -> Host {
let mut host = Host::new(ip(2));
host.set_status(HostStatus::Filtered);
host.add_reason(StatusReason::basic(StatusProtocol::TcpSyn));
host.add_port(Port::new(445, Protocol::Tcp, PortState::Filtered));
host
}
fn bare_host() -> Host {
let mut host = Host::new(ip(9));
host.set_status(HostStatus::Down);
host
}
pub(crate) fn probe_stats() -> ProbeStats {
let mut found_at = [0u64; BUCKET_BOUNDS_MS.len() + 1];
found_at[0] = 4;
found_at[3] = 3;
found_at[BUCKET_BOUNDS_MS.len()] = 2;
ProbeStats {
window: Some(WindowSummary {
capacity: 48,
peak: 256,
reductions: 2,
adaptive: true,
at_floor: false,
}),
scanner: ScannerKind::Routed,
targets: 256,
stop_reason: StopReason::DeadlineExpired,
elapsed: Duration::from_millis(412),
sends_attempted: 512,
sends_failed: 0,
sends_witnessed: 0,
segments_seen: 271,
segments_off_target: 3,
replies_without_rtt: 2,
hosts_found: 9,
answered_on: [7, 2, 0, 0, 0, 0],
answered_unattributed: 0,
first_reply: Some(Duration::from_micros(900)),
last_reply: Some(Duration::from_millis(405)),
found_at,
capture: Some(CaptureCounts {
received: 271,
dropped: 0,
if_dropped: 0,
stopped_early: 0,
}),
}
}
pub(crate) fn report() -> ScanReport {
let (_session, ctx) = ScanSession::builder()
.host_timeout(Some(Duration::ZERO))
.build();
let mut targets = IpSet::new();
targets.insert_range("203.0.113.0/24".parse().expect("a valid range"));
let mut excluded = IpSet::new();
excluded.insert_range("203.0.113.128/25".parse().expect("a valid range"));
let config = ZondConfig {
evasion: EvasionProfile::default()
.with_source_port(53)
.with_ttl(40)
.with_padding(24)
.with_bad_tcp_checksum(true)
.with_spoof_mac(MacAddr::new(0xDE, 0xAD, 0xBE, 0xEF, 0x00, 0x01))
.with_fragment(28)
.with_decoys(vec![
"192.0.2.61".parse().expect("a valid decoy address"),
"192.0.2.62".parse().expect("a valid decoy address"),
])
.with_flags(flags::SYN | flags::FIN),
idle_scan: Some(IdleScan {
zombie: "192.0.2.9".parse().expect("a valid zombie address"),
zombie_port: Some(113),
}),
host_timeout: Some(Duration::from_secs(300)),
scan_timeout: Some(Duration::from_secs(3600)),
sctp_technique: crate::model::technique::SctpScanTechnique::CookieEcho,
excluded_ports: "9100-9107,u:161".try_into().expect("a port specification"),
..Default::default()
};
let recorder = PhaseRecorder::start(
ScanKind::Discovery,
Privilege::Raw,
TargetScope::from_ip_set(&mut targets, &Exclusions::new(excluded)),
&config,
)
.skipping_liveness(crate::report::LivenessSkip::PortsNoDearer);
ctx.record_failure(ScannerKind::Local, "raw socket unavailable".to_string());
ctx.file_cut_short(
ScannerKind::Connect,
"1 port left unasked: source port 53 still closing".to_string(),
);
ctx.record_probe_stats(probe_stats());
ctx.record_sweep(Zone::new(3, "en0"));
ctx.record_attachment(
Attachment::new(
Zone::new(3, "en0"),
AttachmentSource::Lldp,
SystemTime::UNIX_EPOCH + Duration::from_secs(1_772_000_000),
)
.with_device_mac(MacAddr::new(0x00, 0x1B, 0x2C, 0x3D, 0x4E, 0x5F))
.with_device_name("core-sw-02")
.with_port("GigabitEthernet1/0/14")
.with_native_vlan(40)
.with_management_address(IpAddr::V4(Ipv4Addr::new(192, 0, 2, 2))),
);
assert!(
ctx.host_expired(ip(9)),
"the fixture's budget is spent before it is asked"
);
let mut connected = IpSet::new();
connected.insert(IpAddr::V4(Ipv4Addr::LOCALHOST));
connected.insert_range("198.51.100.0/30".parse().expect("a valid range"));
ctx.record_reached_by_connect(&connected);
for host in [router(), filtered_host(), bare_host()] {
ctx.store.insert(host.scoped_ip(), host);
}
for mut entry in ctx.store.iter_mut() {
crate::cve::correlate(entry.value_mut());
}
ctx.record_unreached(1_024);
ctx.handle.abort();
assert!(ctx.stopping_before(crate::report::Pass::Tls));
recorder.finish(&ctx)
}
const BASELINE_AT: Duration = Duration::from_secs(1_780_000_000);
const DAY: Duration = Duration::from_secs(86_400);
const COMPARED_PORTS: &str = "22,80,443,8080,8443";
pub(crate) fn compared() -> (ScanReport, ScanReport) {
(
compared_phase(0, before_hosts()),
compared_phase(35, after_hosts()),
)
}
fn compared_phase(days: u64, hosts: Vec<Host>) -> ScanReport {
use crate::model::port::PortSet;
use crate::model::target::{TargetMap, TargetSet};
use crate::report::{PhaseParts, ScanPhase, ScanSettings};
let mut targets = TargetMap::new();
let mut addresses = IpSet::new();
addresses.insert_range("203.0.113.0/25".parse().expect("a valid range"));
targets.add_unit(TargetSet::new(
addresses,
PortSet::try_from(COMPARED_PORTS).expect("a valid port set"),
));
let phase = ScanPhase::from_parts(PhaseParts {
open: false,
attachments: Vec::new(),
kind: ScanKind::PortScan,
started_at: std::time::UNIX_EPOCH + BASELINE_AT + DAY * days as u32,
elapsed: Duration::from_secs(12),
privilege: Some(Privilege::Raw),
targets: TargetScope::from_target_map(&mut targets, &Exclusions::none()),
settings: ScanSettings::from(&ZondConfig::default()),
failures: Vec::new(),
refusals: Vec::new(),
unroutable: Vec::new(),
refused_by_route: Vec::new(),
timed_out: Vec::new(),
icmp_rate_limited: Vec::new(),
reached_by_connect: Vec::new(),
undecided: Vec::new(),
liveness_skipped: None,
silent: Vec::new(),
stopped: None,
passes_cut: Vec::new(),
unreached: 0,
unheard_probes: 0,
probes: Vec::new(),
origin: None,
});
ScanReport::recorded(crate::report::ENGINE_VERSION, vec![phase], hosts)
}
fn certificate(fingerprint: &str, issuer: &str, ends: Duration) -> Security {
Security::new()
.with_tls_version("TLSv1.3")
.with_cipher_suite("TLS_AES_256_GCM_SHA384")
.with_certificate(CertificateInfo::new(
"www.example.test",
issuer,
std::time::UNIX_EPOCH + BASELINE_AT - DAY * 90,
std::time::UNIX_EPOCH + ends,
fingerprint,
))
}
fn compared_router(later: bool) -> Host {
let mut host = Host::new(ip(1));
host.set_status(HostStatus::Up);
host.add_reason(StatusReason::new(StatusProtocol::Arp, "reply from gateway"));
host.record_mac(MacAddr::new(0x2c, 0xcf, 0x67, 0x00, 0x00, 0x01));
host.set_hostname(Some(
if later {
"gateway.local"
} else {
"router.local"
}
.to_string(),
));
host.set_os(
OsFingerprint::new("Linux", 95)
.with_family("Unix-like")
.with_generation(if later { "6.1.0" } else { "5.15.0" }),
);
host.record_name(
HostName::new(
NameKind::NetbiosHost,
NameSource::Ntlm,
if later { "GATEWAY" } else { "ROUTER" },
)
.expect("a name"),
);
if later {
host.add_finding(
Finding::new(
DetectionId::new("kev", Version::new(1, 0, 0), "seed")
.expect("a valid detection id"),
"Known exploited vulnerability in the management interface",
Severity::High,
Confidence::Strong,
DetectionClass::Passive,
)
.expect("a titled finding"),
);
}
host.add_finding(
Finding::new(
DetectionId::new("tls-audit", Version::new(1, 0, 0), "seed")
.expect("a valid detection id"),
"Management interface accepts a deprecated TLS version",
if later {
Severity::High
} else {
Severity::Medium
},
Confidence::Strong,
DetectionClass::Passive,
)
.expect("a titled finding"),
);
host.add_port(
Port::new(22, Protocol::Tcp, PortState::Open).with_service(
Service::new("ssh", 100)
.with_product("OpenSSH")
.with_version(if later { "9.6p1" } else { "8.9p1" }),
),
);
host.add_port(Port::new(
80,
Protocol::Tcp,
if later {
PortState::Closed
} else {
PortState::Open
},
));
host.add_port(
Port::new(443, Protocol::Tcp, PortState::Open).with_security(if later {
certificate(
"bbbb2b0b822cd15d6c15b0f00a089f86d081884c7d659a2feaa0c55ad015",
"Public CA",
BASELINE_AT + DAY * 400,
)
} else {
certificate(
"aaaa884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"Local CA",
BASELINE_AT + DAY * 200,
)
}),
);
if later {
host.add_port(
Port::new(8080, Protocol::Tcp, PortState::Open).with_service(
Service::new("http-alt", 90)
.with_product("Caddy")
.with_version("2.7.6"),
),
);
}
host
}
fn compared_expiring() -> Host {
let mut host = Host::new(ip(4));
host.set_status(HostStatus::Up);
host.add_port(
Port::new(8443, Protocol::Tcp, PortState::Open)
.with_security(certificate(
"cccc7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
"Local CA",
BASELINE_AT + DAY * 60,
)),
);
host
}
fn before_hosts() -> Vec<Host> {
let mut gone = Host::new(ip(9));
gone.set_status(HostStatus::Up);
vec![compared_router(false), compared_expiring(), gone]
}
fn after_hosts() -> Vec<Host> {
let mut arrived = Host::new(ip(7));
arrived.set_status(HostStatus::Up);
arrived.add_reason(StatusReason::new(StatusProtocol::IcmpEcho, "echo reply"));
arrived.add_port(Port::new(22, Protocol::Tcp, PortState::Open));
vec![compared_router(true), compared_expiring(), arrived]
}
pub(crate) const HOSTILE: &str = "=<script>alert(\"x\")</script>&'\u{202e}";
fn hostile_finding() -> Finding {
Finding::new(
DetectionId::new(HOSTILE, Version::new(1, 0, 0), HOSTILE).unwrap(),
HOSTILE,
Severity::Critical,
Confidence::Certain,
DetectionClass::Exploit,
)
.unwrap()
.with_excerpt(Excerpt::new(HOSTILE))
.with_reference(Reference::url(HOSTILE))
.with_remediation(HOSTILE)
.with_cpe(HOSTILE)
}
fn hostile_host() -> Host {
let mut host = Host::new(ip(3));
host.set_hostname(Some(HOSTILE.to_string()));
host.record_name(
HostName::new(NameKind::NetbiosDomain, NameSource::Ntlm, HOSTILE).expect("a name"),
);
host.set_status(HostStatus::Up);
host.add_reason(StatusReason::new(StatusProtocol::Arp, HOSTILE));
host.set_hardware(hostile_hardware());
host.add_network_role(NetworkRole::Tarpit);
let mut os = OsFingerprint::new(HOSTILE, 90)
.with_family(HOSTILE)
.with_device(HOSTILE)
.with_generation(HOSTILE)
.with_kernel(HOSTILE)
.with_arch(HOSTILE)
.with_evidence(HOSTILE);
os.add_cpe(HOSTILE);
host.set_os(os);
host.add_rtt(Duration::from_micros(1_000));
host.add_finding(hostile_finding());
host.add_port(hostile_port());
host
}
fn hostile_hardware() -> HardwareInfo {
let mut hardware = HardwareInfo::new(MacAddr::new(0xde, 0xad, 0xbe, 0xef, 0x00, 0x01));
hardware.merge(
HardwareInfo::described(HardwareDescription {
vendor: Some(HOSTILE),
product: Some(HOSTILE),
family: Some(HOSTILE),
cpe23: Some(HOSTILE),
model: Some(HOSTILE),
version: Some(HOSTILE),
serial_number: Some(HOSTILE),
})
.expect("a description naming every field names something"),
);
hardware
}
fn hostile_port() -> Port {
let service = Service::new(HOSTILE, 100)
.with_product(HOSTILE)
.with_vendor(HOSTILE)
.with_version(HOSTILE)
.with_extrainfo(HOSTILE)
.with_cpe(HOSTILE);
let certificate = CertificateInfo::new(
HOSTILE,
HOSTILE,
std::time::UNIX_EPOCH + Duration::from_secs(1_767_225_600),
std::time::UNIX_EPOCH + Duration::from_secs(1_798_761_600),
HOSTILE,
)
.with_sans([Arc::from(HOSTILE)])
.with_public_key(HOSTILE, 256);
let security = Security::new()
.with_tls_version(HOSTILE)
.with_cipher_suite(HOSTILE)
.with_alpn(HOSTILE)
.with_certificate(certificate);
let mut port = Port::new(8443, Protocol::Tcp, PortState::Open)
.with_service(service)
.with_security(security)
.with_discovery(Discovery::new(ScanResponse::TcpSynAck).with_source_ip(ip(50)));
port.add_finding(hostile_finding());
port
}
pub(crate) fn hostile() -> ScanReport {
let (_session, ctx) = ScanSession::new();
let mut targets = IpSet::new();
targets.insert_range("203.0.113.0/24".parse().expect("a valid range"));
let recorder = PhaseRecorder::start(
ScanKind::Discovery,
Privilege::Raw,
TargetScope::from_ip_set(&mut targets, &Exclusions::none()),
&ZondConfig::default(),
);
ctx.record_failure(ScannerKind::Local, HOSTILE.to_string());
ctx.record_attachment(
crate::report::Attachment::new(
crate::model::ip::scoped::Zone::new(1, HOSTILE),
crate::report::AttachmentSource::Lldp,
std::time::UNIX_EPOCH + Duration::from_secs(1_767_225_600),
)
.with_device_name(HOSTILE)
.with_device_mac(MacAddr::new(0xde, 0xad, 0xbe, 0xef, 0x00, 0x02))
.with_port(HOSTILE)
.with_native_vlan(42)
.with_management_address(ip(9)),
);
ctx.record_probe_stats(probe_stats());
ctx.store.insert(
crate::model::ip::scoped::ScopedIp::unscoped(ip(3)),
hostile_host(),
);
recorder.finish(&ctx)
}
pub(crate) const NAMED_HOST: &str = "FS01";
pub(crate) const NAMED_DOMAIN: &str = "CONTOSO";
fn smb1_negotiate_reply() -> String {
let mut bytes: Vec<u8> = b"\x00\x00\x00\x55\xffSMBr\x00\x00\x00\x00\x88\x01\xc8".to_vec();
for name in [NAMED_DOMAIN, NAMED_HOST] {
for byte in name.bytes() {
bytes.extend([byte, 0]);
}
bytes.extend([0, 0]);
}
bytes.into_iter().map(char::from).collect()
}
fn named_finding(id: &str, title: &str, excerpt: &str) -> Finding {
Finding::new(
DetectionId::new(id, Version::new(1, 0, 0), "0123abcd").expect("a valid id"),
title,
Severity::High,
Confidence::Certain,
DetectionClass::ActiveBenign,
)
.expect("a valid finding")
.with_excerpt(Excerpt::new(excerpt))
.with_remediation(format!("Turn it off on {NAMED_HOST}"))
}
fn named_correlation(title: &str, cpe: &str) -> Finding {
named_finding("cve-correlation", title, &format!("identified as {cpe}"))
.with_cpe(cpe)
.with_reference(Reference::cve("CVE-2023-38408").expect("a CVE id"))
.with_reference(Reference::url(format!(
"https://advisories.example/{NAMED_HOST}"
)))
}
fn named_host(names: bool, words: bool) -> Host {
let mut host = Host::new(ip(20));
host.set_status(HostStatus::Up);
host.add_reason(StatusReason::basic(StatusProtocol::TcpSyn));
if names {
name_host(&mut host, NAMED_HOST, NAMED_DOMAIN);
}
if !words {
return host;
}
host.add_reason(StatusReason::new(
StatusProtocol::TcpSyn,
format!("syn-ack from {NAMED_HOST}"),
));
let mut os = OsFingerprint::new(format!("Windows Server 2019 ({NAMED_HOST})"), 90)
.with_evidence(format!(
"smb native os on {NAMED_HOST}: Windows Server 2019"
))
.with_family(format!("Windows {NAMED_HOST}"))
.with_generation(format!("2019 {NAMED_HOST}"))
.with_vendor(format!("Microsoft {NAMED_HOST}"))
.with_kernel(format!("10.0 {NAMED_HOST}"))
.with_arch(format!("x86_64 {NAMED_HOST}"))
.with_device(format!("file server {NAMED_HOST}"));
os.add_cpe(format!("cpe:/o:microsoft:windows_server_2019:{NAMED_HOST}"));
host.set_os(os);
host.add_finding(named_correlation(
&format!("Windows Server 2019 on {NAMED_HOST} is past its support"),
&format!("cpe:/o:microsoft:windows_server_2019:{NAMED_HOST}"),
));
let mut hardware = HardwareInfo::described(HardwareDescription {
vendor: Some(&format!("Dell for {NAMED_DOMAIN}")),
product: Some(&format!("PowerEdge {NAMED_HOST}")),
family: Some(&format!("PowerEdge R {NAMED_HOST}")),
cpe23: Some(&format!("cpe:/h:dell:poweredge:{NAMED_HOST}")),
model: Some(&format!("R740 {NAMED_HOST}")),
version: Some(&format!("A01 {NAMED_HOST}")),
serial_number: Some(&format!("SN-{NAMED_HOST}-0001")),
})
.expect("a description naming something");
hardware.add_mac(MacAddr::new(0x02, 0x00, 0x5e, 0x10, 0x20, 0x30));
host.set_hardware(hardware);
let mut smb = Port::new(445, Protocol::Tcp, PortState::Open).with_service(
Service::new("microsoft-ds", 95)
.with_product(format!("Samba smbd for {NAMED_DOMAIN}"))
.with_vendor(format!("Samba for {NAMED_DOMAIN}"))
.with_cpe(format!("cpe:/a:samba:samba:4.15:{NAMED_HOST}"))
.with_version(format!("4.15 {NAMED_HOST}"))
.with_extrainfo(format!("workgroup: {NAMED_DOMAIN}")),
);
smb.add_finding(named_finding(
"smbv1-enabled",
&format!("SMBv1 is enabled on {NAMED_HOST}"),
&smb1_negotiate_reply(),
));
host.add_port(smb);
let mut smtp = Port::new(25, Protocol::Tcp, PortState::Open)
.with_service(Service::new("smtp", 90).with_product("Microsoft ESMTP"));
smtp.add_finding(named_finding(
"smtp-open-relay",
"The mail server relays for anyone",
&format!(
"220 fs01.{}.example Microsoft ESMTP MAIL Service ready",
NAMED_DOMAIN.to_lowercase()
),
));
host.add_port(smtp);
let ssh_cpe = format!("cpe:/a:openbsd:openssh:{NAMED_HOST}");
let mut ssh = Port::new(22, Protocol::Tcp, PortState::Open).with_service(
Service::new("ssh", 95)
.with_product("OpenSSH")
.with_cpe(ssh_cpe.clone()),
);
ssh.add_finding(named_correlation(
"OpenSSH carries known vulnerabilities",
&ssh_cpe,
));
host.add_port(ssh);
let ldaps = Port::new(636, Protocol::Tcp, PortState::Open).with_security(
Security::new().with_certificate(
CertificateInfo::new(
format!("fs01.{}.example", NAMED_DOMAIN.to_lowercase()),
format!("CN={}-{NAMED_HOST}-CA", NAMED_DOMAIN.to_lowercase()),
std::time::UNIX_EPOCH + BASELINE_AT - DAY * 90,
std::time::UNIX_EPOCH + BASELINE_AT + DAY * 300,
"5f86d081884c7d659a2feaa0c55ad015a3bf4f1b2b0b822cd15d6c15b0f00a08",
)
.with_sans([Arc::from(format!(
"{NAMED_HOST}.{}.example",
NAMED_DOMAIN.to_lowercase()
))]),
),
);
host.add_port(ldaps);
host.add_port(
Port::new(40390, Protocol::Tcp, PortState::Open).with_service(Service::new(
format!(
"banner: zq7 node fs01.{}.example ok",
NAMED_DOMAIN.to_lowercase()
),
0,
)),
);
host
}
fn name_host(host: &mut Host, machine: &str, domain: &str) {
let lower = domain.to_lowercase();
host.set_hostname(Some(format!("{}.{lower}.example", machine.to_lowercase())));
for (kind, name) in [
(NameKind::NetbiosHost, machine.to_owned()),
(NameKind::NetbiosDomain, domain.to_owned()),
(NameKind::Domain, format!("{lower}.example")),
] {
host.record_name(HostName::new(kind, NameSource::Smb, &name).expect("a name"));
}
}
pub(crate) fn named() -> (ScanReport, ScanReport) {
(
compared_phase(0, vec![named_host(true, false)]),
compared_phase(35, vec![named_host(true, true)]),
)
}
pub(crate) fn named_late() -> (ScanReport, ScanReport) {
(
compared_phase(0, vec![named_host(false, true)]),
compared_phase(35, vec![named_host(true, true)]),
)
}
pub(crate) const RENAMED_HOST: &str = "FS02";
pub(crate) const RENAMED_DOMAIN: &str = "FABRIKAM";
pub(crate) fn renamed() -> (ScanReport, ScanReport) {
let mut later = named_host(false, false);
name_host(&mut later, RENAMED_HOST, RENAMED_DOMAIN);
(
compared_phase(0, vec![named_host(true, true)]),
compared_phase(35, vec![later]),
)
}