|
|
@ -1,6 +1,6 @@ |
|
|
|
use crate::ipv4::{IPv4, IPv4Range}; |
|
|
|
use crate::ipv4::{IPv4, IPv4Range}; |
|
|
|
use core::time::Duration; |
|
|
|
use core::time::Duration; |
|
|
|
use log::{debug, info, warn}; |
|
|
|
use log::{info, warn}; |
|
|
|
use std::net::TcpStream; |
|
|
|
use std::net::TcpStream; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::thread::JoinHandle; |
|
|
|
use std::{panic, thread}; |
|
|
|
use std::{panic, thread}; |
|
|
@ -12,9 +12,8 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { |
|
|
|
|
|
|
|
|
|
|
|
let timeout = Duration::new(1, 0); |
|
|
|
let timeout = Duration::new(1, 0); |
|
|
|
|
|
|
|
|
|
|
|
println!("Sending TCP packet to: {:?} port={}", target, target_port); |
|
|
|
if let Ok(_res) = TcpStream::connect_timeout(&dest, timeout) { |
|
|
|
if let Ok(res) = TcpStream::connect_timeout(&dest, timeout) { |
|
|
|
println!("* {:?}", dest); |
|
|
|
println!("** Got TCP ack from: {:?} | {:?}", dest, res); |
|
|
|
|
|
|
|
true |
|
|
|
true |
|
|
|
} else { |
|
|
|
} else { |
|
|
|
false |
|
|
|
false |
|
|
@ -22,12 +21,10 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn create_scan_thread( |
|
|
|
fn create_scan_thread( |
|
|
|
thread_id: u64, |
|
|
|
|
|
|
|
ip_range: IPv4Range, |
|
|
|
ip_range: IPv4Range, |
|
|
|
target_port: u16, |
|
|
|
target_port: u16, |
|
|
|
) -> JoinHandle<Vec<(u32, bool)>> { |
|
|
|
) -> JoinHandle<Vec<(u32, bool)>> { |
|
|
|
thread::spawn(move || { |
|
|
|
thread::spawn(move || { |
|
|
|
println!("Creating thread worker #{}", thread_id); |
|
|
|
|
|
|
|
let mut results: Vec<(u32, bool)> = Vec::new(); |
|
|
|
let mut results: Vec<(u32, bool)> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
// do the scan thing
|
|
|
|
// do the scan thing
|
|
|
@ -52,7 +49,7 @@ fn create_scan_worker( |
|
|
|
((thread_id + 1) * ips_per_thread - 1), |
|
|
|
((thread_id + 1) * ips_per_thread - 1), |
|
|
|
); |
|
|
|
); |
|
|
|
let range = IPv4Range::new(f as u32, t as u32, ignorelist); |
|
|
|
let range = IPv4Range::new(f as u32, t as u32, ignorelist); |
|
|
|
create_scan_thread(thread_id, range, target_port) |
|
|
|
create_scan_thread(range, target_port) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn get_scan_workers( |
|
|
|
fn get_scan_workers( |
|
|
@ -65,17 +62,6 @@ fn get_scan_workers( |
|
|
|
let ip_amount = to - from; |
|
|
|
let ip_amount = to - from; |
|
|
|
let ips_per_thread: u64 = ((ip_amount as f32) / num_threads as f32).floor() as u64; |
|
|
|
let ips_per_thread: u64 = ((ip_amount as f32) / num_threads as f32).floor() as u64; |
|
|
|
|
|
|
|
|
|
|
|
println!("****** {}", (ip_amount as f32) / num_threads as f32); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
println!("{} : {}", num_threads, ips_per_thread); |
|
|
|
|
|
|
|
println!( |
|
|
|
|
|
|
|
"{} - {} = {} | {}", |
|
|
|
|
|
|
|
to, |
|
|
|
|
|
|
|
from, |
|
|
|
|
|
|
|
to - from, |
|
|
|
|
|
|
|
num_threads * ips_per_thread |
|
|
|
|
|
|
|
); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// container for all of our threads
|
|
|
|
// container for all of our threads
|
|
|
|
let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new(); |
|
|
|
let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
@ -130,10 +116,9 @@ pub fn start_scan( |
|
|
|
num_threads: u64, |
|
|
|
num_threads: u64, |
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
) -> Vec<ScanResult> { |
|
|
|
) -> Vec<ScanResult> { |
|
|
|
info!("Starting wwmap scan..."); |
|
|
|
println!("Starting wwmap scan..."); |
|
|
|
|
|
|
|
|
|
|
|
// Get the workers
|
|
|
|
// Get the workers
|
|
|
|
println!("Getting scan workers..."); |
|
|
|
|
|
|
|
let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); |
|
|
|
let scan_workers = get_scan_workers(from, to, target_port, num_threads, ignorelist); |
|
|
|
println!("Loaded {} scan worker(s).", scan_workers.len()); |
|
|
|
println!("Loaded {} scan worker(s).", scan_workers.len()); |
|
|
|
|
|
|
|
|
|
|
@ -152,10 +137,8 @@ pub fn start_scan( |
|
|
|
.map(|res| ScanResult::from_tuple(*res)) |
|
|
|
.map(|res| ScanResult::from_tuple(*res)) |
|
|
|
.collect(); |
|
|
|
.collect(); |
|
|
|
|
|
|
|
|
|
|
|
println!("\t* Worker result: {:?}", result_tuples); |
|
|
|
|
|
|
|
results.append(&mut worker_results); |
|
|
|
results.append(&mut worker_results); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
info!("Scan finished!"); |
|
|
|
|
|
|
|
results |
|
|
|
results |
|
|
|
} |
|
|
|
} |
|
|
|