Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 10 additions & 9 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,19 +154,20 @@ fn main() {

// Run all the scripts we found and parsed based on the script config file tags field.
for mut script_f in scripts_to_run.clone() {
output!(
format!("Script to be run {:?}\n", script_f.call_format,),
opts.greppable,
opts.accessible
);

// This part allows us to add commandline arguments to the Script call_format, appending them to the end of the command.
if !opts.command.is_empty() {
let user_extra_args: Vec<String> = shell_words::split(&opts.command.join(" "))
.expect("Failed to parse extra user commandline arguments");
let user_extra_args = &opts.command.join(" ");
debug!("Extra args vec {:?}", user_extra_args);
if script_f.call_format.is_some() {
let mut call_f = script_f.call_format.unwrap();
call_f.push_str(&format!(" {}", &user_extra_args.join(" ")));
call_f.push(' ');
call_f.push_str(user_extra_args);
output!(
format!("Running script {:?} on ip {}\nDepending on the complexity of the script, results may take some time to appear.", call_f, &ip),
opts.greppable,
opts.accessible
);
debug!("Call format {}", call_f);
script_f.call_format = Some(call_f);
}
}
Expand Down
28 changes: 16 additions & 12 deletions src/scanner/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ use async_std::prelude::*;
use colored::Colorize;
use futures::stream::FuturesUnordered;
use std::{
io::ErrorKind,
collections::HashSet,
net::{IpAddr, Shutdown, SocketAddr},
num::NonZeroU8,
time::Duration,
Expand Down Expand Up @@ -62,6 +62,7 @@ impl Scanner {
let mut socket_iterator: SocketIterator = SocketIterator::new(&self.ips, &ports);
let mut open_sockets: Vec<SocketAddr> = Vec::new();
let mut ftrs = FuturesUnordered::new();
let mut errors: HashSet<String> = HashSet::with_capacity(self.ips.len() * 1000);

for _ in 0..self.batch_size {
if let Some(socket) = socket_iterator.next() {
Expand All @@ -82,10 +83,17 @@ impl Scanner {
ftrs.push(self.scan_socket(socket));
}

if let Ok(socket) = result {
open_sockets.push(socket);
match result {
Ok(socket) => open_sockets.push(socket),
Err(e) => {
let error_string = e.to_string();
if errors.len() < self.ips.len() * 1000 {
errors.insert(error_string);
}
}
}
}
debug!("Typical socket connection errors {:?}", errors);
debug!("Open Sockets found: {:?}", &open_sockets);
open_sockets
}
Expand Down Expand Up @@ -127,19 +135,15 @@ impl Scanner {
return Ok(socket);
}
Err(e) => {
let error_string = e.to_string();

if e.kind() == ErrorKind::Other {
debug!("Socket connect error: {} {}", &error_string, &socket);
let mut error_string = e.to_string();

if !error_string.contains("No route to host")
&& !error_string.contains("Network is unreachable")
{
panic!("Too many open files. Please reduce batch size. The default is 5000. Try -b 2500.");
}
if error_string.to_lowercase().contains("too many open files") {
panic!("Too many open files. Please reduce batch size. The default is 5000. Try -b 2500.");
}

if nr_try == tries {
error_string.push(' ');
error_string.push_str(&socket.ip().to_string());
return Err(io::Error::new(io::ErrorKind::Other, error_string));
}
}
Expand Down
14 changes: 3 additions & 11 deletions src/scripts/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,25 +231,17 @@ impl Script {
};
to_run = default_template.fill_with_struct(&exec_parts)?;
}
debug!("\nScript format to run {}", to_run);

debug!("\nTo run {}", to_run);

let arguments = shell_words::split(
&to_run
.split(' ')
.map(ToString::to_string)
.collect::<Vec<String>>()
.join(" "),
)
.expect("Failed to parse script arguments");
let arguments = shell_words::split(&to_run).expect("Failed to parse script arguments");

execute_script(arguments)
}
}

#[cfg(not(tarpaulin_include))]
fn execute_script(mut arguments: Vec<String>) -> Result<String> {
debug!("\nArguments vec: {:?}", &arguments);
debug!("\nScript arguments vec: {:?}", &arguments);
let process = Exec::cmd(&arguments.remove(0)).args(&arguments);
match process.capture() {
Ok(c) => {
Expand Down