Skip to content

Commit 2346988

Browse files
committed
added an option to parse cs portscann output
1 parent 5bfa645 commit 2346988

File tree

3 files changed

+313
-16
lines changed

3 files changed

+313
-16
lines changed

pentest_tool/src/info_controls.rs

Lines changed: 267 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
use std::collections::HashMap;
2+
use std::fmt::write;
23
use std::fs;
4+
use std::fs::create_dir_all;
35
use std::fs::read_to_string;
46
use std::fs::OpenOptions;
57
use std::hash::Hash;
@@ -13,12 +15,15 @@ use std::time::Duration;
1315
use std::io::stdin;
1416
use std::thread::JoinHandle;
1517
use chrono::format;
18+
use fs_extra::file;
1619
use reqwest::dns::Name;
1720
use walkdir::WalkDir;
1821
use clearscreen::clear;
1922
use clearscreen;
2023
use rodio::{Decoder, OutputStream, Sink};
2124
use crate::get_user_input;
25+
use crate::open_overwrite;
26+
use crate::open_append;
2227
use crate::Project;
2328

2429
pub fn run_initial_enum(project: &Project){
@@ -889,4 +894,266 @@ last
889894
write!(email_note_file, "{}\n", outline).expect("error writing email notes file!");
890895
write!(email_text_file, "{}\n", outline).expect("error writing email text file!");
891896
}
897+
}
898+
899+
pub fn parse_csportscan(project: &Project){
900+
let mut tsv_path = project.files_folder.clone();
901+
tsv_path.push("working/tsvs/services.tsv");
902+
let mut outfile = tsv_path.clone();
903+
outfile.pop();
904+
outfile.pop();
905+
let mut windows_hosts = Vec::new();
906+
let mut ssh_hosts = Vec::new();
907+
let mut ftp_hosts = Vec::new();
908+
let mut rdp_hosts = Vec::new();
909+
let mut dns_hosts = Vec::new();
910+
let mut snmp_hosts = Vec::new();
911+
let mut web_hosts = Vec::new();
912+
let mut telnet_hosts = Vec::new();
913+
let mut unknown_ports = Vec::new();
914+
915+
if !get_user_input("do you have the tsv saved in the project folder under working/tsvs/services.tsv?").to_lowercase().contains("y"){
916+
tsv_path.clear();
917+
tsv_path.push(get_user_input("ooof ok, please enter the full path to your tsv file."));
918+
}
919+
let tsv_read_res = read_to_string(tsv_path);
920+
if tsv_read_res.is_err(){
921+
let error = tsv_read_res.err().unwrap();
922+
println!("ooof error reading tsv file!");
923+
println!("{}", error);
924+
return;
925+
}
926+
println!("tsv read, parsing lines...");
927+
let tsv_string = tsv_read_res.unwrap();
928+
let lines: Vec<&str> = tsv_string.split("\n").collect();
929+
for line in lines{
930+
let words: Vec<&str> = line.split("\t").collect();
931+
if words.len() > 1{
932+
let host = words[0].to_lowercase().to_owned();
933+
let port = words[1].to_lowercase().to_owned();
934+
let host_entry = format!("{}:{}", &host, &port);
935+
match words[1]{
936+
"135" => {if !windows_hosts.contains(&host){windows_hosts.push(host)}},
937+
"445" => {if !windows_hosts.contains(&host){windows_hosts.push(host)}},
938+
"22" => {if !ssh_hosts.contains(&host){ssh_hosts.push(host);}},
939+
"21" => {if !ftp_hosts.contains(&host){ftp_hosts.push(host);}},
940+
"23" => {if !telnet_hosts.contains(&host){telnet_hosts.push(host)}},
941+
"3389" => {if !rdp_hosts.contains(&host){rdp_hosts.push(host);}},
942+
"80" | "443" | "8080" | "8443" | "4433" | "8000" => {if !web_hosts.contains(&host_entry){web_hosts.push(host_entry);}},
943+
"53" => {if !dns_hosts.contains(&host){dns_hosts.push(host);}},
944+
"161" => {if !snmp_hosts.contains(&host){snmp_hosts.push(host);}},
945+
_ => {
946+
if words.len() == 3{
947+
let banner = words[2].to_lowercase().to_owned();
948+
if words[2].to_lowercase().contains("ssh"){
949+
if !ssh_hosts.contains(&host_entry){
950+
ssh_hosts.push(host_entry);
951+
}
952+
}
953+
else if banner.contains("ftp"){
954+
if !ftp_hosts.contains(&host_entry){
955+
ftp_hosts.push(host_entry);
956+
}
957+
}
958+
else if banner.contains("nginx") || banner.contains("apache"){
959+
if !web_hosts.contains(&host_entry){
960+
web_hosts.push(host_entry);
961+
}
962+
}
963+
else{
964+
continue;
965+
}
966+
}
967+
else if words.len() == 2{
968+
unknown_ports.push(host_entry);
969+
}
970+
}
971+
}
972+
}
973+
}
974+
println!("is {} where you want to save your files?", outfile.display());
975+
if get_user_input("").to_lowercase().contains("n"){
976+
outfile.clear();
977+
outfile.push(get_user_input("ok, please enter the full path to the folder you want to save them to."));
978+
}
979+
print!("
980+
{} Windows hosts found!
981+
{} SSH hosts found!
982+
{} FTP hosts found!
983+
{} Telnet hosts found!
984+
{} SNMP hosts found!
985+
{} DNS hosts found!
986+
{} RDP hosts found!
987+
{} untagged hosts found!
988+
", windows_hosts.len(), ssh_hosts.len(), ftp_hosts.len(), telnet_hosts.len(), snmp_hosts.len(), dns_hosts.len(), rdp_hosts.len(), unknown_ports.len());
989+
println!("lines parsed! creating output files...");
990+
outfile.push("windows_hosts.txt");
991+
let file_option = open_overwrite(&outfile);
992+
if file_option.is_some(){
993+
let mut windows_file = file_option.unwrap();
994+
for host in windows_hosts{
995+
let write_res = write!(windows_file, "{}\n", host);
996+
if write_res.is_err(){
997+
let error = write_res.err().unwrap();
998+
println!("oooof error writing windows_hosts.txt!!");
999+
println!("{}", error);
1000+
}
1001+
else{
1002+
write_res.unwrap();
1003+
}
1004+
}
1005+
}
1006+
outfile.pop();
1007+
outfile.push("ssh_hosts.txt");
1008+
let file_option = open_overwrite(&outfile);
1009+
if file_option.is_some(){
1010+
let mut ssh_file = file_option.unwrap();
1011+
for host in ssh_hosts{
1012+
let write_res = write!(ssh_file, "{}\n", host);
1013+
if write_res.is_err(){
1014+
let error = write_res.err().unwrap();
1015+
println!("oooof error writing ssh_hosts.txt!!");
1016+
println!("{}", error);
1017+
}
1018+
else{
1019+
write_res.unwrap();
1020+
}
1021+
}
1022+
}
1023+
outfile.pop();
1024+
outfile.push("telnet_hosts.txt");
1025+
let file_option = open_overwrite(&outfile);
1026+
if file_option.is_some(){
1027+
let mut telnet_file = file_option.unwrap();
1028+
for host in telnet_hosts{
1029+
let write_res = write!(telnet_file, "{}\n", host);
1030+
if write_res.is_err(){
1031+
let error = write_res.err().unwrap();
1032+
println!("oooof error writing _hosts.txt!!");
1033+
println!("{}", error);
1034+
}
1035+
else{
1036+
write_res.unwrap();
1037+
}
1038+
}
1039+
}
1040+
outfile.pop();
1041+
outfile.push("ftp_hosts.txt");
1042+
let file_option = open_overwrite(&outfile);
1043+
if file_option.is_some(){
1044+
let mut ftp_file = file_option.unwrap();
1045+
for host in ftp_hosts{
1046+
let write_res = write!(ftp_file, "{}\n", host);
1047+
if write_res.is_err(){
1048+
let error = write_res.err().unwrap();
1049+
println!("oooof error writing _hosts.txt!!");
1050+
println!("{}", error);
1051+
}
1052+
else{
1053+
write_res.unwrap();
1054+
}
1055+
}
1056+
}
1057+
outfile.pop();
1058+
outfile.push("snmp_hosts.txt");
1059+
let file_option = open_overwrite(&outfile);
1060+
if file_option.is_some(){
1061+
let mut snmp_file = file_option.unwrap();
1062+
for host in snmp_hosts{
1063+
let write_res = write!(snmp_file, "{}\n", host);
1064+
if write_res.is_err(){
1065+
let error = write_res.err().unwrap();
1066+
println!("oooof error writing _hosts.txt!!");
1067+
println!("{}", error);
1068+
}
1069+
else{
1070+
write_res.unwrap();
1071+
}
1072+
}
1073+
}
1074+
outfile.pop();
1075+
outfile.push("dns_hosts.txt");
1076+
let file_option = open_overwrite(&outfile);
1077+
if file_option.is_some(){
1078+
let mut dns_file = file_option.unwrap();
1079+
for host in dns_hosts{
1080+
let write_res = write!(dns_file, "{}\n", host);
1081+
if write_res.is_err(){
1082+
let error = write_res.err().unwrap();
1083+
println!("oooof error writing _hosts.txt!!");
1084+
println!("{}", error);
1085+
}
1086+
else{
1087+
write_res.unwrap();
1088+
}
1089+
}
1090+
}
1091+
outfile.pop();
1092+
outfile.push("rdp_hosts.txt");
1093+
let file_option = open_overwrite(&outfile);
1094+
if file_option.is_some(){
1095+
let mut rdp_file = file_option.unwrap();
1096+
for host in rdp_hosts{
1097+
let write_res = write!(rdp_file, "{}\n", host);
1098+
if write_res.is_err(){
1099+
let error = write_res.err().unwrap();
1100+
println!("oooof error writing _hosts.txt!!");
1101+
println!("{}", error);
1102+
}
1103+
else{
1104+
write_res.unwrap();
1105+
}
1106+
}
1107+
}
1108+
outfile.pop();
1109+
outfile.push("web_hosts.txt");
1110+
let file_option = open_overwrite(&outfile);
1111+
if file_option.is_some(){
1112+
let mut web_file = file_option.unwrap();
1113+
for host in web_hosts{
1114+
let write_res = write!(web_file, "{}\n", host);
1115+
if write_res.is_err(){
1116+
let error = write_res.err().unwrap();
1117+
println!("oooof error writing _hosts.txt!!");
1118+
println!("{}", error);
1119+
}
1120+
else{
1121+
write_res.unwrap();
1122+
}
1123+
}
1124+
}
1125+
println!("interesting ports have been written to... writing untagged port files...");
1126+
outfile.pop();
1127+
outfile.push("untagged ports");
1128+
if !outfile.exists(){
1129+
let untagged_res = create_dir_all(&outfile);
1130+
if untagged_res.is_err(){
1131+
let error = untagged_res.err().unwrap();
1132+
println!("ooof error creating untagged folder!");
1133+
println!("{}", error);
1134+
}
1135+
else{
1136+
untagged_res.unwrap();
1137+
}
1138+
}
1139+
for line in unknown_ports{
1140+
let line_vec:Vec<&str> = line.split(":").collect();
1141+
let host = line_vec[0].to_owned();
1142+
let port = line_vec[1].to_owned();
1143+
let file_name = format!("{}_hosts.txt", port);
1144+
outfile.push(file_name);
1145+
let write_file_opt = open_append(&outfile);
1146+
if write_file_opt.is_some(){
1147+
let mut write_file = write_file_opt.unwrap();
1148+
let write_res = write!(write_file, "{}\n", host);
1149+
if write_res.is_err(){
1150+
let error = write_res.err().unwrap();
1151+
println!("ooof error writing to file...");
1152+
println!("{}", error);
1153+
}
1154+
}
1155+
outfile.pop();
1156+
}
1157+
println!("DONE all files saved to {}", outfile.display());
1158+
println!("note if no hosts were found for a protocol their files will be empty.");
8921159
}

pentest_tool/src/main.rs

Lines changed: 29 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ use std::{io::stdin, path::PathBuf, process::Command};
22
use directories::UserDirs;
33
use reqwest::Response;
44
use std::process::exit;
5-
use std::fs;
5+
use std::fs::{self, File};
66

77
#[derive(Clone)]
88
pub struct Project{
@@ -23,6 +23,34 @@ mod box_controls;
2323
mod info_controls;
2424
mod start_pentest;
2525

26+
pub fn open_overwrite(path: &PathBuf) -> Option<File>{
27+
let file_create_res = fs::OpenOptions::new().create(true).write(true).open(path);
28+
if file_create_res.is_err(){
29+
let error = file_create_res.err().unwrap();
30+
println!("error opening {} file!", path.display());
31+
println!("{}", error);
32+
return None;
33+
}
34+
else {
35+
let file = file_create_res.unwrap();
36+
return Some(file);
37+
}
38+
}
39+
40+
pub fn open_append(path: &PathBuf) -> Option<File>{
41+
let file_create_res = fs::OpenOptions::new().create(true).append(true).open(path);
42+
if file_create_res.is_err(){
43+
let error = file_create_res.err().unwrap();
44+
println!("error opening {} file!", path.display());
45+
println!("{}", error);
46+
return None;
47+
}
48+
else {
49+
let file = file_create_res.unwrap();
50+
return Some(file);
51+
}
52+
}
53+
2654
pub fn get_user_input(prompt: &str) -> String{
2755
let mut response = String::new();
2856
loop{

pentest_tool/src/menu.rs

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -113,7 +113,7 @@ pub fn main_menu(mut projects: Vec<Project>, config_path: PathBuf, base_files: &
113113
114114
115115
116-
NOTE OPTION 27 WILL SAVE YOUR PROJECTS BEFORE QUITTING
116+
NOTE OPTION 28 WILL SAVE YOUR PROJECTS BEFORE QUITTING
117117
118118
base prject folder: {}
119119
upcoming project folder: {}
@@ -147,13 +147,14 @@ General Notes: {}
147147
18.) Print Project Info For Report
148148
19.) Build host discovery cmd command from scope in notes
149149
20.) build portscan command from scope in notes
150-
21.) Stop All Distroboxes
151-
22.) Password Spray (will print password to spray, and wait the obervation window time)
152-
23.) crack password hashes on your cracking rig
153-
24.) Launch bloodhound with the current project's distrobox
154-
25.) Parse GatherContacts output file
155-
26.) prune unused distroboxes (free up system storage)
156-
27.) Quit Application
150+
21.) parse a cs portscan services.tsv file
151+
22.) Stop All Distroboxes
152+
23.) Password Spray (will print password to spray, and wait the obervation window time)
153+
24.) crack password hashes on your cracking rig
154+
25.) Launch bloodhound with the current project's distrobox
155+
26.) Parse GatherContacts output file
156+
27.) prune unused distroboxes (free up system storage)
157+
28.) Quit Application
157158
\n",&base_files.display(), &upcoming_files.display(), active_project.customer, active_project.project_name, active_project.files_folder.display(), active_project.notes_folder.display(), active_project.boxname, terminal, season, year, &obsidian_uri);
158159
std::io::stdin().read_line(&mut response).expect("error getting menu input");
159160
clear().expect("error clearing screen");
@@ -181,13 +182,14 @@ General Notes: {}
181182
"18" => info_controls::print_report_information(active_project.clone()),
182183
"19" => info_controls::build_cmd_for_host_discovery(&active_project),
183184
"20" => info_controls::build_cs_portscan_cmd(&active_project),
184-
"21" => box_controls::stop_all_boxes(&projects),
185-
"22" => info_controls::password_spray_help(&active_project, season, lseason, year, &tools_dir, &config_path),
186-
"23" => info_controls::crack_hashes(&cracking_rig, &active_project, &terminal, &rockyou, &rule),
187-
"24" => {let bloodhound_handle = box_controls::launch_bloodhound_gui(active_project.clone()).unwrap(); threads.push(bloodhound_handle);},
188-
"25" => info_controls::partse_gathercontacts(&active_project),
189-
"26" => {let prune_thread = box_controls::clean_unused_boxes(&projects, &boxtemplate); if prune_thread.is_some(){threads.push(prune_thread.unwrap());}},
190-
"27" => {project_controls::save_projects(&projects, &config_path);
185+
"21" => info_controls::parse_csportscan(&active_project),
186+
"22" => box_controls::stop_all_boxes(&projects),
187+
"23" => info_controls::password_spray_help(&active_project, season, lseason, year, &tools_dir, &config_path),
188+
"24" => info_controls::crack_hashes(&cracking_rig, &active_project, &terminal, &rockyou, &rule),
189+
"25" => {let bloodhound_handle = box_controls::launch_bloodhound_gui(active_project.clone()).unwrap(); threads.push(bloodhound_handle);},
190+
"26" => info_controls::partse_gathercontacts(&active_project),
191+
"27" => {let prune_thread = box_controls::clean_unused_boxes(&projects, &boxtemplate); if prune_thread.is_some(){threads.push(prune_thread.unwrap());}},
192+
"28" => {project_controls::save_projects(&projects, &config_path);
191193
let mut stop = String::new();
192194
println!("stop all boxes?\ny/n");
193195
std::io::stdin().read_line(&mut stop).unwrap();

0 commit comments

Comments
 (0)