Skip to content

Commit 89b78ae

Browse files
committed
Fix CI: clippy warnings, formatting, and remove missing examples
1 parent 7a38eba commit 89b78ae

File tree

5 files changed

+89
-37
lines changed

5 files changed

+89
-37
lines changed

Cargo.toml

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -36,10 +36,3 @@ criterion = "0.5"
3636
name = "scan_network"
3737
path = "examples/scan_network.rs"
3838

39-
[[example]]
40-
name = "vulnerability_scan"
41-
path = "examples/vulnerability_scan.rs"
42-
43-
[[bench]]
44-
name = "scanner_benchmark"
45-
harness = false

src/compliance.rs

Lines changed: 57 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -168,7 +168,12 @@ impl ComplianceScanner {
168168
}
169169

170170
/// Scan for PCI-DSS compliance
171-
pub fn scan_pci_dss(&self, target: &str, open_ports: &[u16], services: &HashMap<u16, String>) -> ComplianceResult {
171+
pub fn scan_pci_dss(
172+
&self,
173+
target: &str,
174+
open_ports: &[u16],
175+
services: &HashMap<u16, String>,
176+
) -> ComplianceResult {
172177
let mut result = ComplianceResult::new(target, ComplianceFramework::PCIDSS);
173178

174179
// PCI-DSS 1.3.1 - Restrict inbound traffic
@@ -193,7 +198,12 @@ impl ComplianceScanner {
193198
}
194199

195200
/// Scan for CIS Benchmark compliance
196-
pub fn scan_cis_benchmark(&self, target: &str, open_ports: &[u16], services: &HashMap<u16, String>) -> ComplianceResult {
201+
pub fn scan_cis_benchmark(
202+
&self,
203+
target: &str,
204+
open_ports: &[u16],
205+
services: &HashMap<u16, String>,
206+
) -> ComplianceResult {
197207
let mut result = ComplianceResult::new(target, ComplianceFramework::CISBenchmark);
198208

199209
// CIS Control 4.1 - Secure configuration
@@ -238,12 +248,19 @@ impl ComplianceScanner {
238248
description: "No insecure or unnecessary ports should be accessible".to_string(),
239249
status,
240250
evidence,
241-
remediation: Some("Close or firewall prohibited ports: Telnet (23), FTP (21), TFTP (69)".to_string()),
251+
remediation: Some(
252+
"Close or firewall prohibited ports: Telnet (23), FTP (21), TFTP (69)".to_string(),
253+
),
242254
});
243255
}
244256

245257
/// Check encryption requirements (PCI-DSS 2.2.7)
246-
fn check_encryption_required(&self, result: &mut ComplianceResult, open_ports: &[u16], services: &HashMap<u16, String>) {
258+
fn check_encryption_required(
259+
&self,
260+
result: &mut ComplianceResult,
261+
open_ports: &[u16],
262+
_services: &HashMap<u16, String>,
263+
) {
247264
let unencrypted: Vec<u16> = open_ports
248265
.iter()
249266
.filter(|p| self.port_config.encryption_required_ports.contains(p))
@@ -265,16 +282,24 @@ impl ComplianceScanner {
265282
result.add_check(ComplianceCheck {
266283
id: "PCI-DSS-2.2.7".to_string(),
267284
framework: ComplianceFramework::PCIDSS,
268-
requirement: "Use strong cryptography for non-console administrative access".to_string(),
285+
requirement: "Use strong cryptography for non-console administrative access"
286+
.to_string(),
269287
description: "All administrative access must be encrypted".to_string(),
270288
status,
271289
evidence,
272-
remediation: Some("Replace HTTP with HTTPS, use IMAPS/POP3S instead of IMAP/POP3".to_string()),
290+
remediation: Some(
291+
"Replace HTTP with HTTPS, use IMAPS/POP3S instead of IMAP/POP3".to_string(),
292+
),
273293
});
274294
}
275295

276296
/// Check secure administrative access (PCI-DSS 2.3)
277-
fn check_secure_admin(&self, result: &mut ComplianceResult, open_ports: &[u16], _services: &HashMap<u16, String>) {
297+
fn check_secure_admin(
298+
&self,
299+
result: &mut ComplianceResult,
300+
open_ports: &[u16],
301+
_services: &HashMap<u16, String>,
302+
) {
278303
// Check for SSH (secure) vs Telnet (insecure)
279304
let has_telnet = open_ports.contains(&23);
280305
let has_ssh = open_ports.contains(&22);
@@ -300,7 +325,9 @@ impl ComplianceScanner {
300325
description: "Use SSH instead of Telnet for remote administration".to_string(),
301326
status,
302327
evidence,
303-
remediation: Some("Disable Telnet and use SSH with key-based authentication".to_string()),
328+
remediation: Some(
329+
"Disable Telnet and use SSH with key-based authentication".to_string(),
330+
),
304331
});
305332
}
306333

@@ -328,7 +355,8 @@ impl ComplianceScanner {
328355
result.add_check(ComplianceCheck {
329356
id: "PCI-DSS-4.1".to_string(),
330357
framework: ComplianceFramework::PCIDSS,
331-
requirement: "Use strong cryptography to protect cardholder data during transmission".to_string(),
358+
requirement: "Use strong cryptography to protect cardholder data during transmission"
359+
.to_string(),
332360
description: "All data transmission must be encrypted with TLS 1.2+".to_string(),
333361
status,
334362
evidence,
@@ -337,7 +365,11 @@ impl ComplianceScanner {
337365
}
338366

339367
/// Check for insecure protocols (PCI-DSS 6.5.4)
340-
fn check_insecure_protocols(&self, result: &mut ComplianceResult, services: &HashMap<u16, String>) {
368+
fn check_insecure_protocols(
369+
&self,
370+
result: &mut ComplianceResult,
371+
services: &HashMap<u16, String>,
372+
) {
341373
let insecure_services: Vec<String> = services
342374
.values()
343375
.filter(|s| {
@@ -410,12 +442,19 @@ impl ComplianceScanner {
410442
description: "Minimize attack surface by closing unnecessary ports".to_string(),
411443
status,
412444
evidence: format!("High-risk ports open: {:?}", high_risk_ports),
413-
remediation: Some("Close or restrict high-risk ports, use encrypted alternatives".to_string()),
445+
remediation: Some(
446+
"Close or restrict high-risk ports, use encrypted alternatives".to_string(),
447+
),
414448
});
415449
}
416450

417451
/// Check for unnecessary services (CIS Control 4.8)
418-
fn check_unnecessary_services(&self, result: &mut ComplianceResult, open_ports: &[u16], _services: &HashMap<u16, String>) {
452+
fn check_unnecessary_services(
453+
&self,
454+
result: &mut ComplianceResult,
455+
open_ports: &[u16],
456+
_services: &HashMap<u16, String>,
457+
) {
419458
let common_unnecessary: Vec<u16> = open_ports
420459
.iter()
421460
.filter(|p| [7, 9, 13, 17, 19, 37, 79].contains(p))
@@ -435,7 +474,9 @@ impl ComplianceScanner {
435474
description: "Legacy and unnecessary services should be disabled".to_string(),
436475
status,
437476
evidence: format!("Unnecessary service ports: {:?}", common_unnecessary),
438-
remediation: Some("Disable echo, discard, daytime, chargen, finger services".to_string()),
477+
remediation: Some(
478+
"Disable echo, discard, daytime, chargen, finger services".to_string(),
479+
),
439480
});
440481
}
441482

@@ -458,7 +499,9 @@ impl ComplianceScanner {
458499
description: "Limit network exposure to minimum necessary ports".to_string(),
459500
status,
460501
evidence: format!("{} ports open: {:?}", port_count, open_ports),
461-
remediation: Some("Review and close unnecessary ports, implement firewall rules".to_string()),
502+
remediation: Some(
503+
"Review and close unnecessary ports, implement firewall rules".to_string(),
504+
),
462505
});
463506
}
464507
}

src/lib.rs

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -32,15 +32,17 @@
3232
//! - **Report Generation**: HTML and PDF report output
3333
//! - **Rate Limiting**: Avoid IDS/IPS detection
3434
35-
pub mod service_detection;
35+
pub mod compliance;
3636
pub mod os_fingerprint;
37+
pub mod service_detection;
3738
pub mod vulnerability;
38-
pub mod compliance;
3939

40+
pub use compliance::{
41+
ComplianceFramework as NetworkComplianceFramework, ComplianceResult, ComplianceScanner,
42+
};
43+
pub use os_fingerprint::{OSDetector, OSFingerprint, OperatingSystem};
4044
pub use service_detection::{BannerGrabber, ServiceInfo, ServiceSignatures};
41-
pub use os_fingerprint::{OSFingerprint, OSDetector, OperatingSystem};
42-
pub use vulnerability::{VulnerabilityScanner, CVE, VulnerabilityReport};
43-
pub use compliance::{ComplianceScanner, ComplianceResult, ComplianceFramework as NetworkComplianceFramework};
45+
pub use vulnerability::{VulnerabilityReport, VulnerabilityScanner, CVE};
4446

4547
use chrono::{DateTime, Utc};
4648
use futures::future::join_all;

src/os_fingerprint.rs

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,10 @@ impl OSSignatures {
8888
);
8989
signatures.insert(
9090
"ttl:128:win:8192".to_string(),
91-
(OperatingSystem::Windows(WindowsVersion::WindowsServer2019), 0.8),
91+
(
92+
OperatingSystem::Windows(WindowsVersion::WindowsServer2019),
93+
0.8,
94+
),
9295
);
9396

9497
// Linux signatures (TTL 64)
@@ -108,10 +111,7 @@ impl OSSignatures {
108111
);
109112

110113
// Cisco signatures (TTL 255)
111-
signatures.insert(
112-
"ttl:255:cisco".to_string(),
113-
(OperatingSystem::Cisco, 0.9),
114-
);
114+
signatures.insert("ttl:255:cisco".to_string(), (OperatingSystem::Cisco, 0.9));
115115

116116
Self { signatures }
117117
}
@@ -334,10 +334,15 @@ mod tests {
334334
let detector = OSDetector::new();
335335

336336
let ubuntu = detector.detect_from_banner("Ubuntu 22.04 LTS").unwrap();
337-
assert!(matches!(ubuntu.os, OperatingSystem::Linux(LinuxDistro::Ubuntu)));
337+
assert!(matches!(
338+
ubuntu.os,
339+
OperatingSystem::Linux(LinuxDistro::Ubuntu)
340+
));
338341
assert!(ubuntu.confidence >= 0.9);
339342

340-
let windows = detector.detect_from_banner("Microsoft Windows Server 2019").unwrap();
343+
let windows = detector
344+
.detect_from_banner("Microsoft Windows Server 2019")
345+
.unwrap();
341346
assert!(matches!(windows.os, OperatingSystem::Windows(_)));
342347
}
343348

@@ -352,7 +357,10 @@ mod tests {
352357
Some("OpenSSH 8.2p1 Ubuntu"),
353358
);
354359

355-
assert!(matches!(result.os, OperatingSystem::Linux(LinuxDistro::Ubuntu)));
360+
assert!(matches!(
361+
result.os,
362+
OperatingSystem::Linux(LinuxDistro::Ubuntu)
363+
));
356364
assert!(result.confidence >= 0.9);
357365
}
358366

src/vulnerability.rs

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,9 @@ impl CVE {
6060

6161
/// Check if a version is affected
6262
pub fn affects_version(&self, version: &str) -> bool {
63-
self.affected_versions.iter().any(|v| version.contains(v) || v.contains(version))
63+
self.affected_versions
64+
.iter()
65+
.any(|v| version.contains(v) || v.contains(version))
6466
}
6567

6668
/// Check if a product is affected
@@ -266,7 +268,8 @@ impl VulnerabilityReport {
266268

267269
/// Sort findings by severity
268270
pub fn sort_by_severity(&mut self) {
269-
self.findings.sort_by(|a, b| b.cve.severity.cmp(&a.cve.severity));
271+
self.findings
272+
.sort_by(|a, b| b.cve.severity.cmp(&a.cve.severity));
270273
}
271274
}
272275

@@ -325,7 +328,10 @@ impl VulnerabilityScanner {
325328

326329
// Try generic version pattern
327330
let generic = Regex::new(r"([\d]+\.[\d]+(?:\.[\d]+)?)").ok()?;
328-
generic.captures(banner)?.get(1).map(|m| m.as_str().to_string())
331+
generic
332+
.captures(banner)?
333+
.get(1)
334+
.map(|m| m.as_str().to_string())
329335
}
330336

331337
/// Scan a service for vulnerabilities

0 commit comments

Comments
 (0)