From f20f6d6ce0531c5d0ec7dd7468e03b7742872ef8 Mon Sep 17 00:00:00 2001 From: Edu4rdSHL Date: Mon, 10 May 2021 11:58:50 -0500 Subject: [PATCH] Add raw output support. Signed-off-by: Edu4rdSHL --- src/args.rs | 3 ++- src/cli.yml | 11 +++++++-- src/resolver_engine.rs | 56 ++++++++++++++++++++++++------------------ src/structs.rs | 3 ++- 4 files changed, 45 insertions(+), 28 deletions(-) diff --git a/src/args.rs b/src/args.rs index a16a6e3..b50eb49 100644 --- a/src/args.rs +++ b/src/args.rs @@ -58,7 +58,8 @@ pub fn get_args() -> Args { custom_resolvers: matches.is_present("custom-resolvers"), custom_ports_range: matches.is_present("initial-port") || matches.is_present("last-port"), fast_scan: matches.is_present("fast-scan"), - keep_nmap_logs: matches.is_present("keep-nmap-logs"), + no_keep_nmap_logs: matches.is_present("no-keep-nmap-logs"), + raw_output: matches.is_present("raw-output"), files: return_matches_vec(&matches, "files"), min_rate: value_t!(matches, "min-rate", String).unwrap_or_else(|_| String::new()), resolvers: if matches.is_present("custom-resolvers") { diff --git a/src/cli.yml b/src/cli.yml index 17f50e5..56a2a7b 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -77,9 +77,16 @@ args: takes_value: true multiple: false - - keep-nmap-logs: + - no-keep-nmap-logs: help: Keep Nmap XML files created in the logs/ folder for every scanned IP. This data will be useful for other tasks. short: k - long: keep-nmap-logs + long: no-keep-nmap-logs + takes_value: false + multiple: false + + - raw-output: + help: Use raw output instead of a table. + short: r + long: raw-output takes_value: false multiple: false diff --git a/src/resolver_engine.rs b/src/resolver_engine.rs index c4cb4ad..51276c3 100644 --- a/src/resolver_engine.rs +++ b/src/resolver_engine.rs @@ -68,46 +68,52 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> { ]); for (target, resolv_data) in &data { if !resolv_data.ip.is_empty() { - let mut services_table = Table::new(); - for port_data in &resolv_data.ports_data { - services_table - .add_row(row![bc => &format!("PORT => {}", port_data.portid.clone())]); - services_table.add_row( + if args.raw_output { + for port_data in &resolv_data.ports_data { + println!("{},{},{}", target, resolv_data.ip, port_data.portid) + } + } else { + let mut services_table = Table::new(); + for port_data in &resolv_data.ports_data { + services_table + .add_row(row![bc => &format!("PORT => {}", port_data.portid.clone())]); + services_table.add_row( row![c => &format!("SERVICE: {}", port_data.service.clone().unwrap_or_default().name)], ); - services_table.add_row(row![c => &format!("VERSION: {}" ,port_data + services_table.add_row(row![c => &format!("VERSION: {}" ,port_data .service.clone().unwrap_or_default() .version .clone() .unwrap_or_else(|| "NULL".to_string()))]); - services_table.add_row(row![c => &format!("PRODUCT: {}", port_data + services_table.add_row(row![c => &format!("PRODUCT: {}", port_data .service.clone().unwrap_or_default() .product .clone() .unwrap_or_else(|| "NULL".to_string()))]); - services_table.add_row(row![c => &format!("OS TYPE: {}", port_data + services_table.add_row(row![c => &format!("OS TYPE: {}", port_data .service.clone().unwrap_or_default() .ostype .clone() .unwrap_or_else(|| "NULL".to_string()))]); - services_table.add_row(row![c => &format!("EXTRA INFO: {}", port_data + services_table.add_row(row![c => &format!("EXTRA INFO: {}", port_data .service.clone().unwrap_or_default() .extrainfo .clone() .unwrap_or_else(|| "NULL".to_string()))]); + } + table.add_row(row![ d => + target, + logic::null_ip_checker(&resolv_data.ip), + logic::return_ports_string( + &resolv_data + .ports_data + .iter() + .map(|f| f.portid.clone()) + .collect(), + ), + services_table, + ]); } - table.add_row(row![ d => - target, - logic::null_ip_checker(&resolv_data.ip), - logic::return_ports_string( - &resolv_data - .ports_data - .iter() - .map(|f| f.portid.clone()) - .collect(), - ), - services_table, - ]); } } @@ -121,7 +127,7 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> { args.file_name ) } - if !args.quiet_flag { + if !args.quiet_flag && !args.raw_output { table.printstd(); } @@ -132,7 +138,9 @@ pub fn parallel_resolver_all(args: &mut Args) -> Result<()> { ); info!("Logfile saved in {}\n\n", args.file_name); } - println!(); + if !args.quiet_flag { + println!(); + } Ok(()) } @@ -174,7 +182,7 @@ fn parallel_resolver_engine(args: &Args, targets: HashSet) -> HashMap, pub resolvers: Vec,