Skip to content

Commit 9dbc52f

Browse files
authored
Merge pull request #24 from shellrow/dev
Dev
2 parents 24bedb0 + 0dc618c commit 9dbc52f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

56 files changed

+1697
-926
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "nrev"
3-
version = "0.2.0"
3+
version = "0.3.0"
44
edition = "2021"
55
authors = ["shellrow <[email protected]>"]
66
description = "Simple and Fast Network Revealer/Mapper."

src/app.rs

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
use std::sync::{Mutex, OnceLock};
2-
use clap::{crate_name, crate_version, crate_description};
31
use crate::sys;
2+
use clap::{crate_description, crate_name, crate_version};
3+
use std::sync::{Mutex, OnceLock};
44

55
// APP information
66
pub const CRATE_BIN_NAME: &str = "nrev";
@@ -13,11 +13,9 @@ pub static QUIET_MODE: OnceLock<Mutex<bool>> = OnceLock::new();
1313
/// Check if quiet mode is enabled
1414
pub fn is_quiet_mode() -> bool {
1515
match QUIET_MODE.get() {
16-
Some(mutex) => {
17-
match mutex.try_lock() {
18-
Ok(guard) => *guard,
19-
Err(_) => false,
20-
}
16+
Some(mutex) => match mutex.try_lock() {
17+
Ok(guard) => *guard,
18+
Err(_) => false,
2119
},
2220
None => false,
2321
}
@@ -29,7 +27,7 @@ pub fn set_quiet_mode(enabled: bool) -> Result<(), String> {
2927
Ok(mut guard) => {
3028
*guard = enabled;
3129
Ok(())
32-
},
30+
}
3331
Err(_) => Err("Failed to lock mutex".to_string()),
3432
}
3533
}
@@ -58,7 +56,7 @@ impl AppCommands {
5856
"interfaces" => Some(AppCommands::Interfaces),
5957
"interface" => Some(AppCommands::Interface),
6058
"check" => Some(AppCommands::CheckDependencies),
61-
_ => None
59+
_ => None,
6260
}
6361
}
6462
}

src/config/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,8 @@ pub const PCAP_WAIT_TIME_MILLIS: u64 = 10;
1111
pub const DEFAULT_PORTS_BIN: &[u8] = include_bytes!("../../resources/ndb-default-ports.bin");
1212
pub const HTTP_PORTS_BIN: &[u8] = include_bytes!("../../resources/ndb-http-ports.bin");
1313
pub const HTTPS_PORTS_BIN: &[u8] = include_bytes!("../../resources/ndb-https-ports.bin");
14-
pub const OS_FAMILY_FINGERPRINT_BIN: &[u8] = include_bytes!("../../resources/ndb-os-family-fingerprint.bin");
14+
pub const OS_FAMILY_FINGERPRINT_BIN: &[u8] =
15+
include_bytes!("../../resources/ndb-os-family-fingerprint.bin");
1516
pub const OS_TTL_BIN: &[u8] = include_bytes!("../../resources/ndb-os-ttl.bin");
1617
pub const OS_FAMILY_BIN: &[u8] = include_bytes!("../../resources/ndb-os-family.bin");
1718
pub const OUI_BIN: &[u8] = include_bytes!("../../resources/ndb-oui.bin");

src/db/mod.rs

Lines changed: 15 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,8 @@ pub fn get_vm_oui_map() -> HashMap<String, String> {
2828

2929
pub fn get_tcp_map() -> HashMap<u16, String> {
3030
let mut tcp_map: HashMap<u16, String> = HashMap::new();
31-
let ds_tcp_service: Vec<model::TcpService> = bincode::deserialize(config::TCP_SERVICE_BIN).unwrap_or(vec![]);
31+
let ds_tcp_service: Vec<model::TcpService> =
32+
bincode::deserialize(config::TCP_SERVICE_BIN).unwrap_or(vec![]);
3233
for port in ds_tcp_service {
3334
tcp_map.insert(port.port, port.service_name);
3435
}
@@ -41,7 +42,8 @@ pub fn get_default_ports() -> Vec<u16> {
4142
}
4243

4344
pub fn get_wellknown_ports() -> Vec<u16> {
44-
let wellknown_ports: Vec<u16> = bincode::deserialize(config::WELLKNOWN_PORTS_BIN).unwrap_or(vec![]);
45+
let wellknown_ports: Vec<u16> =
46+
bincode::deserialize(config::WELLKNOWN_PORTS_BIN).unwrap_or(vec![]);
4547
wellknown_ports
4648
}
4749

@@ -75,7 +77,8 @@ pub fn get_subdomain() -> Vec<String> {
7577
}
7678

7779
pub fn get_os_family_fingerprints() -> Vec<model::OsFamilyFingerprint> {
78-
let ds_os_fingerprints: Vec<model::OsFamilyFingerprint> = bincode::deserialize(config::OS_FAMILY_FINGERPRINT_BIN).unwrap_or(vec![]);
80+
let ds_os_fingerprints: Vec<model::OsFamilyFingerprint> =
81+
bincode::deserialize(config::OS_FAMILY_FINGERPRINT_BIN).unwrap_or(vec![]);
7982
ds_os_fingerprints
8083
}
8184

@@ -85,7 +88,9 @@ pub fn get_os_family_list() -> Vec<String> {
8588
}
8689

8790
pub fn is_vm_fingerprint(fingerprint: &model::OsFingerprint) -> bool {
88-
if fingerprint.os_family == "Player".to_string() && fingerprint.device_type == "specialized".to_string() {
91+
if fingerprint.os_family == "Player".to_string()
92+
&& fingerprint.device_type == "specialized".to_string()
93+
{
8994
return true;
9095
}
9196
false
@@ -239,7 +244,11 @@ pub fn verify_os_family_fingerprint(fingerprint: &PacketFrame) -> model::OsFamil
239244
};
240245
}
241246

242-
pub fn get_os_family(fingerprint: &PacketFrame, os_family_list: &Vec<String>, os_family_fingerprints: &Vec<model::OsFamilyFingerprint>) -> model::OsFamilyFingerprint {
247+
pub fn get_os_family(
248+
fingerprint: &PacketFrame,
249+
os_family_list: &Vec<String>,
250+
os_family_fingerprints: &Vec<model::OsFamilyFingerprint>,
251+
) -> model::OsFamilyFingerprint {
243252
let in_vm: bool = if let Some(ether_header) = &fingerprint.ethernet_header {
244253
in_vm_network(ether_header.clone())
245254
} else {
@@ -383,7 +392,7 @@ pub fn get_fingerprint_map(fingerprints: &Vec<PacketFrame>) -> HashMap<IpAddr, S
383392
let os_fingerprint = get_os_family(&f, &os_family_list, &os_family_fingerprints);
384393
if let Some(ipv4_header) = &f.ipv4_header {
385394
fingerprint_map.insert(IpAddr::V4(ipv4_header.source), os_fingerprint.os_family);
386-
}else{
395+
} else {
387396
if let Some(ipv6_header) = &f.ipv6_header {
388397
fingerprint_map.insert(IpAddr::V6(ipv6_header.source), os_fingerprint.os_family);
389398
}

src/db/tcp_service.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5844,4 +5844,4 @@ pub(crate) static PORT_SERVICE_MAP: Map<u16, &'static str> = phf_map! {
58445844
49000u16 => "matahari",
58455845
49001u16 => "nusrp",
58465846
49150u16 => "inspider",
5847-
};
5847+
};

src/dns/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ use std::collections::HashMap;
1616
use std::str::FromStr;
1717
use std::thread;
1818

19-
2019
#[cfg(not(target_os = "windows"))]
2120
const DEFAULT_TIMEOUT: Duration = Duration::from_millis(200);
2221
#[cfg(not(target_os = "windows"))]

src/dns/result.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
use crate::scan::result::ScanStatus;
22

33
use super::domain::Domain;
4-
use std::time::Duration;
54
use serde::{Deserialize, Serialize};
5+
use std::time::Duration;
66

77
/// Result of domain scan
88
#[derive(Clone, Debug, Serialize, Deserialize)]

src/dns/scanner.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -143,7 +143,8 @@ impl DomainScanner {
143143
/// Results are stored in DomainScanner::scan_result
144144
pub async fn run_scan(&mut self) {
145145
if self.passive && cfg!(not(feature = "passive")) {
146-
self.scan_result.scan_status = ScanStatus::Error(String::from("Passive scan not supported"));
146+
self.scan_result.scan_status =
147+
ScanStatus::Error(String::from("Passive scan not supported"));
147148
return;
148149
}
149150
let start_time = Instant::now();
@@ -318,8 +319,8 @@ async fn scan_subdomain_passive(
318319
if r.status().is_success() {
319320
match r.text().await {
320321
Ok(res_text) => {
321-
let certs_json: serde_json::Value =
322-
serde_json::from_str(res_text.as_str()).unwrap_or(serde_json::json!({}));
322+
let certs_json: serde_json::Value = serde_json::from_str(res_text.as_str())
323+
.unwrap_or(serde_json::json!({}));
323324
if certs_json.is_array() {
324325
let cert_array = certs_json.as_array().unwrap();
325326
for cert in cert_array {
@@ -398,4 +399,4 @@ async fn scan_subdomain_passive(
398399
result.push(domain.to_owned());
399400
}
400401
result
401-
}
402+
}

src/fp/setting.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
use std::net::IpAddr;
2-
use serde::{Deserialize, Serialize};
31
use crate::protocol::Protocol;
2+
use serde::{Deserialize, Serialize};
3+
use std::net::IpAddr;
44

55
#[derive(Deserialize, Serialize, Clone, Copy, Debug, PartialEq, Eq)]
6-
pub enum FingerprintType {
6+
pub enum FingerprintType {
77
IcmpEcho,
88
IcmpTimestamp,
99
IcmpAddressMask,

src/handler/check.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
use clap::ArgMatches;
21
use crate::dep;
2+
use clap::ArgMatches;
33

44
pub fn check_dependencies(_arg: &ArgMatches) {
55
match dep::check_dependencies() {
66
Ok(_) => {
77
println!("All dependencies are installed.");
88
std::process::exit(0);
9-
},
9+
}
1010
Err(e) => {
1111
println!("Error: {}", e);
1212
std::process::exit(1);

src/handler/dns.rs

Lines changed: 50 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
1-
use std::path::PathBuf;
2-
use std::{thread, time::Duration};
31
use crate::db;
42
use crate::dns::domain::Domain;
3+
use crate::dns::{result::DomainScanResult, scanner::DomainScanner};
4+
use crate::util::tree::node_label;
55
use clap::ArgMatches;
66
use indicatif::{ProgressBar, ProgressDrawTarget};
7-
use crate::dns::{result::DomainScanResult, scanner::DomainScanner};
8-
use tokio::runtime::Runtime;
7+
use std::path::PathBuf;
8+
use std::{thread, time::Duration};
99
use termtree::Tree;
10-
use crate::util::tree::node_label;
10+
use tokio::runtime::Runtime;
1111

1212
use crate::output;
1313

@@ -36,23 +36,21 @@ pub fn handle_subdomain_scan(args: &ArgMatches) {
3636
Some(timeout) => Duration::from_millis(*timeout),
3737
None => Duration::from_secs(30),
3838
};
39-
39+
4040
let word_list: Vec<String> = match host_args.get_one::<PathBuf>("wordlist") {
41-
Some(file_path) => {
42-
match std::fs::read_to_string(&file_path) {
43-
Ok(contents) => {
44-
let mut word_list: Vec<String> = Vec::new();
45-
for word in contents.lines() {
46-
let word = word.trim();
47-
if word.is_empty() {
48-
continue;
49-
}
50-
word_list.push(word.to_owned());
41+
Some(file_path) => match std::fs::read_to_string(&file_path) {
42+
Ok(contents) => {
43+
let mut word_list: Vec<String> = Vec::new();
44+
for word in contents.lines() {
45+
let word = word.trim();
46+
if word.is_empty() {
47+
continue;
5148
}
52-
word_list
49+
word_list.push(word.to_owned());
5350
}
54-
Err(_) => vec![],
51+
word_list
5552
}
53+
Err(_) => vec![],
5654
},
5755
None => db::get_subdomain(),
5856
};
@@ -94,22 +92,25 @@ pub fn handle_subdomain_scan(args: &ArgMatches) {
9492
if args.get_flag("json") {
9593
let json_result = serde_json::to_string_pretty(&result).unwrap();
9694
println!("{}", json_result);
97-
}else {
95+
} else {
9896
show_domainscan_result(&result, target_domain);
9997
}
10098
output::log_with_time(&format!("Scan completed in {:?}", result.scan_time), "INFO");
10199
match args.get_one::<PathBuf>("save") {
102100
Some(file_path) => {
103101
match crate::fs::save_text(file_path, serde_json::to_string_pretty(&result).unwrap()) {
104102
Ok(_) => {
105-
output::log_with_time(&format!("Saved to {}", file_path.to_string_lossy()), "INFO");
106-
},
103+
output::log_with_time(
104+
&format!("Saved to {}", file_path.to_string_lossy()),
105+
"INFO",
106+
);
107+
}
107108
Err(e) => {
108109
output::log_with_time(&format!("Failed to save: {}", e), "ERROR");
109-
},
110+
}
110111
}
111-
},
112-
None => {},
112+
}
113+
None => {}
113114
}
114115
}
115116

@@ -120,10 +121,26 @@ fn print_option(setting: &DomainScanner) {
120121
println!();
121122
let mut tree = Tree::new(node_label("SubdomainScan Config", None, None));
122123
let mut setting_tree = Tree::new(node_label("Settings", None, None));
123-
setting_tree.push(node_label("Words", Some(&setting.word_list.len().to_string()), None));
124-
setting_tree.push(node_label("Timeout", Some(&format!("{:?}", setting.timeout)), None));
125-
setting_tree.push(node_label("Resolve timeout", Some(&format!("{:?}", setting.resolve_timeout)), None));
126-
setting_tree.push(node_label("Concurrent limit", Some(&setting.concurrent_limit.to_string()), None));
124+
setting_tree.push(node_label(
125+
"Words",
126+
Some(&setting.word_list.len().to_string()),
127+
None,
128+
));
129+
setting_tree.push(node_label(
130+
"Timeout",
131+
Some(&format!("{:?}", setting.timeout)),
132+
None,
133+
));
134+
setting_tree.push(node_label(
135+
"Resolve timeout",
136+
Some(&format!("{:?}", setting.resolve_timeout)),
137+
None,
138+
));
139+
setting_tree.push(node_label(
140+
"Concurrent limit",
141+
Some(&setting.concurrent_limit.to_string()),
142+
None,
143+
));
127144
tree.push(setting_tree);
128145
let mut target_tree = Tree::new(node_label("Target", None, None));
129146
target_tree.push(node_label("Domain Name", Some(&setting.base_domain), None));
@@ -135,7 +152,11 @@ fn show_domainscan_result(scan_result: &DomainScanResult, target_domain: Domain)
135152
if !crate::app::is_quiet_mode() {
136153
println!();
137154
}
138-
let mut tree = Tree::new(node_label(&format!("SubdomainScan Result - {}", target_domain.domain_name), None, None));
155+
let mut tree = Tree::new(node_label(
156+
&format!("SubdomainScan Result - {}", target_domain.domain_name),
157+
None,
158+
None,
159+
));
139160
let mut domain_tree = Tree::new(node_label(&target_domain.domain_name, None, None));
140161
let mut ipv4_tree = Tree::new(node_label("IPv4 Addresses", None, None));
141162
let mut ipv6_tree = Tree::new(node_label("IPv6 Addresses", None, None));

0 commit comments

Comments
 (0)