diff --git a/src/args.rs b/src/args.rs index 747a630..c462225 100644 --- a/src/args.rs +++ b/src/args.rs @@ -58,6 +58,7 @@ pub fn get_args() -> Args { no_keep_nmap_logs: matches.is_present("no-keep-nmap-logs"), raw_output: matches.is_present("raw-output"), url_output: matches.is_present("url-output"), + from_stdin: matches.is_present("stdin"), 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 fc02883..ca109bd 100644 --- a/src/cli.yml +++ b/src/cli.yml @@ -13,6 +13,7 @@ args: multiple: false conflicts_with: - files + - stdin - files: short: f @@ -22,6 +23,7 @@ args: multiple: true conflicts_with: - target + - stdin - output: short: o @@ -100,3 +102,12 @@ args: multiple: false conflicts_with: - raw-output + + - stdin: + help: Read from stdin instead of files or aguments. + long: stdin + takes_value: false + multiple: false + conflicts_with: + - files + - target diff --git a/src/lib.rs b/src/lib.rs index 5b46bea..b7b2238 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -11,11 +11,11 @@ pub mod args; pub mod errors; pub mod files; pub mod logger; +pub mod misc; pub mod resolver_engine; mod defaults; mod logic; -mod misc; mod networking; mod nmap; mod structs; diff --git a/src/main.rs b/src/main.rs index 49b95f7..afaa2af 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,7 +1,7 @@ use { log::{error, Level}, std::{collections::HashSet, iter::FromIterator}, - unimap::{args, errors::*, files::return_file_targets, logger, resolver_engine}, + unimap::{args, errors::*, files::return_file_targets, logger, misc, resolver_engine}, }; fn run() -> Result<()> { @@ -14,8 +14,10 @@ fn run() -> Result<()> { if !arguments.files.is_empty() { arguments.targets = HashSet::from_iter(return_file_targets(&arguments, arguments.files.clone())) - } else { + } else if !arguments.target.is_empty() { arguments.targets.insert(arguments.target.clone()); + } else { + arguments.targets = misc::read_stdin() } if arguments.targets.len() < 50 { @@ -27,7 +29,7 @@ fn run() -> Result<()> { .build_global() .unwrap(); - if !arguments.target.is_empty() || !arguments.files.is_empty() { + if !arguments.targets.is_empty() { resolver_engine::parallel_resolver_all(&mut arguments) } else { error!("Error: Target is empty or invalid!\n"); diff --git a/src/misc.rs b/src/misc.rs index 15ad273..6c0bc2a 100644 --- a/src/misc.rs +++ b/src/misc.rs @@ -1,4 +1,7 @@ -use std::collections::HashSet; +use std::{ + collections::HashSet, + io::{self, Read}, +}; pub fn sanitize_target_string(target: String) -> String { target @@ -32,3 +35,12 @@ pub fn return_matches_hashset(matches: &clap::ArgMatches, value: &str) -> HashSe HashSet::new() } } + +pub fn read_stdin() -> HashSet { + let mut buffer = String::new(); + let mut stdin = io::stdin(); + stdin + .read_to_string(&mut buffer) + .expect("Error getting input list."); + buffer.lines().map(str::to_owned).collect() +} diff --git a/src/structs.rs b/src/structs.rs index edc937c..5802894 100644 --- a/src/structs.rs +++ b/src/structs.rs @@ -22,6 +22,7 @@ pub struct Args { pub raw_output: bool, pub fast_scan: bool, pub url_output: bool, + pub from_stdin: bool, pub files: Vec, pub resolvers: Vec, pub targets: HashSet,