From 387c12a247f1612489851a133efb05be93ba438e Mon Sep 17 00:00:00 2001 From: Pyro57000 Date: Wed, 28 May 2025 15:29:19 -0500 Subject: [PATCH] fixed the nmap scanning function! --- pentest_tool/src/enumeration.rs | 19 ++++++--- pentest_tool/src/main.rs | 13 ++++++ pentest_tool/src/portscan_controls.rs | 59 +++++++++++++++++++-------- 3 files changed, 68 insertions(+), 23 deletions(-) diff --git a/pentest_tool/src/enumeration.rs b/pentest_tool/src/enumeration.rs index 0dee431..5bb2ac4 100644 --- a/pentest_tool/src/enumeration.rs +++ b/pentest_tool/src/enumeration.rs @@ -9,6 +9,9 @@ use dns_lookup::lookup_host; use crate::get_user_input; use crate::Project; use crate::open_append; +use crate::print_error; +use crate::print_success; +use crate::print_informational; #[allow(unused)] pub fn run_dns_enumeration(project: &Project, given_domains: Option<&Vec>, standalone: bool) -> Option>{ @@ -66,6 +69,7 @@ pub fn run_dns_enumeration(project: &Project, given_domains: Option<&Vec println!("{}", error.to_string().red()); return; } + print_success("DNS Enumeration Done, Writing to file..."); let output_string = output_string_res.unwrap(); let lines: Vec<&str> = output_string.split("\n").collect(); let mut out_data = String::new(); @@ -110,8 +114,8 @@ pub fn run_dns_enumeration(project: &Project, given_domains: Option<&Vec if standalone{ out_data.push_str("\n---\n"); } - println!("From DNS Enumeration Thread: Finished gathering data for {} writing to notes...", domain); write!(enumeration_file, "{}", &out_data).unwrap(); + print_success("DNS Records: Gathered | Notes: Written | DNS Record Thread OUT!"); let remove_res = remove_file("dns_temp.csv"); if remove_res.is_err(){ println!("From DNS Enumeration Thread: error removing temporay data file!"); @@ -129,8 +133,7 @@ pub fn bruteforce_subs(project: &Project, given_domains: Option<&Vec>, g let enumeration_file_res = OpenOptions::new().append(true).create(true).open(enumeration_path); if enumeration_file_res.is_err(){ let error = enumeration_file_res.err().unwrap(); - println!("{}","error opening enumeration notes file!".red()); - println!("{}", error.to_string().red()); + print_error("FROM GOBUSTER THREAD: error opening enumeration notes file!", error.to_string()); return None; } let mut enumeration_file = enumeration_file_res.unwrap(); @@ -187,10 +190,10 @@ pub fn bruteforce_subs(project: &Project, given_domains: Option<&Vec>, g println!("{}", error.to_string().red()); return; } - println!("sleeping for 10 seconds to allow for sudo password input."); + print_informational("sleeping for 10 seconds to allow for sudo password input."); sleep(Duration::from_secs(10)); let gobuser_output = gobuster_cmd_res.unwrap().stdout; - println!("From Gobuster Thread: Sudomain enumeration Done!"); + print_success("Gobuster enumeration Done!"); let gobuster_string = String::from_utf8_lossy(&gobuser_output); let mut domain_names = Vec::new(); let lines: Vec<&str> = gobuster_string.split("\n").collect(); @@ -224,6 +227,7 @@ pub fn bruteforce_subs(project: &Project, given_domains: Option<&Vec>, g return; } write_res.unwrap(); + print_success("Subdomains: Bruteforced | Enumeration notes: Written | Gobuster thread out!"); }); return Some(gobuster_thread); } @@ -285,7 +289,7 @@ pub fn dns_squatting(project: &Project, given_domains: Option<&Vec>, sta println!("{}", error.to_string().red()); return; } - println!("sleeping for 10 seconds to allow for sudo password input."); + print_informational("sleeping for 10 seconds to get sudo password."); sleep(Duration::from_secs(10)); let twist_output_vec = twist_output.unwrap().stdout; let output_string = String::from_utf8_lossy(&twist_output_vec); @@ -301,6 +305,7 @@ pub fn dns_squatting(project: &Project, given_domains: Option<&Vec>, sta } } }); + print_success("Domains: Squatted | Notes: Written | DNSTwist thread OUT!"); return Some(squatting_thread); } @@ -326,6 +331,7 @@ pub fn do_all_dns_enumeration(project: &Project) -> Option>{ } } let wordlist = get_user_input("path to wordlist for sub domain bruteforcing?"); + print_informational("target data gathered. Spawning threads to do enumeration..."); let working_project = project.clone(); let all_dns_handle = spawn(move ||{ let mut write_success = true; @@ -357,6 +363,7 @@ pub fn do_all_dns_enumeration(project: &Project) -> Option>{ } write!(enumeration_file, "\n---\n").unwrap(); } + print_success("All DNS Enum threads finished, notes have been written. DNS Enumeration Thread OUT!"); } }); return Some(all_dns_handle); diff --git a/pentest_tool/src/main.rs b/pentest_tool/src/main.rs index c77f12a..2f8cf7c 100644 --- a/pentest_tool/src/main.rs +++ b/pentest_tool/src/main.rs @@ -29,6 +29,19 @@ mod enumeration; mod tool_controls; mod configuration; +pub fn print_error(message: &str ,error: String){ + println!("{}", message.red()); + println!("{}", error.red()); +} + +pub fn print_success(message: T) where T: AsRef { + println!("{}", message.as_ref().green()); +} + +pub fn print_informational(message: T) where T: AsRef{ + println!("{}", message.as_ref()); +} + pub fn open_overwrite(path: &PathBuf) -> Option{ let file_create_res = fs::OpenOptions::new().create(true).write(true).open(path); if file_create_res.is_err(){ diff --git a/pentest_tool/src/portscan_controls.rs b/pentest_tool/src/portscan_controls.rs index 14dc331..030c754 100644 --- a/pentest_tool/src/portscan_controls.rs +++ b/pentest_tool/src/portscan_controls.rs @@ -8,7 +8,7 @@ use std::thread::{sleep, spawn, JoinHandle}; use std::time::Duration; use colored::Colorize; use walkdir::WalkDir; -use crate::get_user_input; +use crate::{get_user_input, print_error, print_informational, print_success}; use crate::Project; use crate::open_overwrite; use crate::open_append; @@ -318,7 +318,7 @@ pub fn parse_csportscan(project: &Project){ outfile.clear(); outfile.push(get_user_input("ok, please enter the full path to the folder you want to save them to.")); } - print!(" + let host_number_results = format!(" {} Windows hosts found! {} SSH hosts found! {} FTP hosts found! @@ -328,7 +328,8 @@ pub fn parse_csportscan(project: &Project){ {} RDP hosts found! {} untagged hosts found! ", windows_hosts.len(), ssh_hosts.len(), ftp_hosts.len(), telnet_hosts.len(), snmp_hosts.len(), dns_hosts.len(), rdp_hosts.len(), unknown_ports.len()); - println!("lines parsed! creating output files..."); + print_success(host_number_results); + print_informational("data gathered, writing to notes..."); outfile.push("windows_hosts.txt"); let file_option = open_overwrite(&outfile); if file_option.is_some(){ @@ -342,6 +343,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("windows hosts file written!"); } } } @@ -359,6 +361,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("ssh hosts file written!"); } } } @@ -376,6 +379,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("telnet hosts file written!"); } } } @@ -393,6 +397,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("fpt hosts file written!"); } } } @@ -410,6 +415,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("snmp hosts file written!") } } } @@ -427,6 +433,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("dns hosts file written!") } } } @@ -444,6 +451,7 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("rdp hosts file written!"); } } } @@ -461,10 +469,11 @@ pub fn parse_csportscan(project: &Project){ } else{ write_res.unwrap(); + print_success("web hosts file written!"); } } } - println!("interesting ports have been written to... writing untagged port files..."); + print_informational("tagged port files have been written to, saving untagged ports..."); outfile.pop(); outfile.push("untagged ports"); if !outfile.exists(){ @@ -476,6 +485,7 @@ pub fn parse_csportscan(project: &Project){ } else{ untagged_res.unwrap(); + print_success("untagged port file written!"); } } for line in unknown_ports{ @@ -496,7 +506,7 @@ pub fn parse_csportscan(project: &Project){ } outfile.pop(); } - println!("DONE all files saved to {}", outfile.display()); + print_success(format!("DONE all files saved to {}", outfile.display())); println!("note if no hosts were found for a protocol their files will be empty."); } @@ -526,7 +536,7 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ return None; } let mut targets = targets_res.unwrap(); - println!("Got targets from scope!"); + print_success("Got targets from scope!"); for target in &targets{ println!("{}", target); } @@ -579,7 +589,16 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ } } let proxy = get_user_input("will you be using proxychains for this scan?").to_lowercase().contains("y"); - println!("sweet we have what we need!"); + print_success("sweet we have what we need!"); + print_informational("Targets:"); + for target in &targets{ + print_informational(format!("{}", target)); + } + print_informational("\nPorts:"); + for port in &ports_to_scan{ + print_informational(format!("{}", port)); + } + print_informational("\n"); println!("building portscan command..."); let working_project = project.clone(); let mut save_path = project.files_folder.clone(); @@ -591,8 +610,8 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ save_path.push("services.tsv"); let mut enumeration_notes_path = project.notes_folder.clone(); enumeration_notes_path.push("enumeration.md"); - println!("{}", save_path.display()); let mut nmap_output = Vec::new(); + print_informational(format!("{}", ports_to_scan.join(","))); let nmap_thread = spawn(move || { if proxy{ let port_scancmd_res = Command::new("distrobox") @@ -644,6 +663,7 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ if nmap_log_file.is_some(){ let mut nmap_log_file = nmap_log_file.unwrap(); write!(nmap_log_file, "{}", nmap_output_string).unwrap(); + print_success("nmap log file written!"); } let mut host_ports = Vec::new(); let host_sections: Vec<&str> = nmap_output_string.split("Nmap scan report ").collect(); @@ -690,8 +710,7 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ let mut services_file = services_file_open_res.unwrap(); let enumeration_open_res = open_append(&enumeration_notes_path); if enumeration_open_res.is_none(){ - println!("error opening enumeration notes file!"); - println!("scan data will not be saved to enumeration notes!"); + print_error("error opening enumeration notes file!", "".to_owned()); } let services_write_res = write!(services_file, "host\tport\tbanner\tnotes\n"); if services_write_res.is_err(){ @@ -707,10 +726,16 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ let mut host_all_ports: HashMap> = HashMap::new(); for host in &host_ports{ write!(services_file, "{}\n", host).unwrap(); - let host_data: Vec<&str> = host.split_whitespace().collect(); + let host_data: Vec<&str> = host.split("\t").collect(); + println!("#####"); + println!("{}", host); + println!("address: {}", host_data[0]); + println!("port: {}", host_data[1]); + println!("service: {}", host_data[2]); + println!("#####"); let address = host_data[0].to_owned(); let port = host_data[1].to_owned(); - let service = host_data[2..].join(" "); + let service = host_data[2].to_owned(); if host_all_ports.contains_key(&address){ host_all_ports.get_mut(&address).unwrap().push(format!("{}:{}", port, service)); } @@ -730,13 +755,13 @@ pub fn run_nmap_portscan(project: &Project) -> Option>{ let parts: Vec<&str> = port_entry.split(":").collect(); let port = parts[0]; let services = parts[1]; - write!(enumeration_file, "| {} | {} |\n", port, services).unwrap(); + write!(enumeration_file, "| {} | {} | {} |\n", host, port, services).unwrap(); } } - write!(enumeration_file, "---\n").unwrap(); + write!(enumeration_file, "\n---\n").unwrap(); } } - println!("FROM NMAP THREAD: Parsing done! You're scan results are saved in cobalt strike services.tsv format at {}", save_path.display()); + print_success(format!("FROM NMAP THREAD: Parsing done! You're scan results are saved in cobalt strike services.tsv format at {}", save_path.display())); }); sleep(Duration::from_secs(10)); return Some(nmap_thread); @@ -823,9 +848,9 @@ pub fn build_nmap_command(project: &Project){ let targets_string = targets.join(" "); println!("\nYour portscan command is:"); if get_user_input("will you be using proxychains for this scan?").to_lowercase().contains("y"){ - println!("\n\nproxychains nmap -sT -p {} {} -Pn | tee {}", ports_string, targets_string, save_path.display()); + print_success(format!("\n\nproxychains nmap -sT -p {} {} -Pn | tee {}", ports_string, targets_string, save_path.display())); } else{ - println!("nmap -p {} {} -Pn | tee {}", ports_string, targets_string, save_path.display()); + print_success(format!("nmap -p {} {} -Pn | tee {}", ports_string, targets_string, save_path.display())); } } \ No newline at end of file