11use std:: collections:: HashMap ;
2+ use std:: fmt:: write;
23use std:: fs;
4+ use std:: fs:: create_dir_all;
35use std:: fs:: read_to_string;
46use std:: fs:: OpenOptions ;
57use std:: hash:: Hash ;
@@ -13,12 +15,15 @@ use std::time::Duration;
1315use std:: io:: stdin;
1416use std:: thread:: JoinHandle ;
1517use chrono:: format;
18+ use fs_extra:: file;
1619use reqwest:: dns:: Name ;
1720use walkdir:: WalkDir ;
1821use clearscreen:: clear;
1922use clearscreen;
2023use rodio:: { Decoder , OutputStream , Sink } ;
2124use crate :: get_user_input;
25+ use crate :: open_overwrite;
26+ use crate :: open_append;
2227use crate :: Project ;
2328
2429pub 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}
0 commit comments