|
|
@ -9,70 +9,64 @@ fn tcp_scan(mut target: ipv4::IPv4, target_port: u16) -> bool { |
|
|
|
let dest = target.to_socketaddr(target_port).unwrap(); |
|
|
|
let dest = target.to_socketaddr(target_port).unwrap(); |
|
|
|
|
|
|
|
|
|
|
|
false |
|
|
|
false |
|
|
|
// TODO: FIX
|
|
|
|
// TODO: FIX
|
|
|
|
// if let Ok(res) = TcpStream::connect(dest) {
|
|
|
|
// if let Ok(res) = TcpStream::connect(dest) {
|
|
|
|
// info!("* Got TCP ack from: {:?} | {:?}", dest, res);
|
|
|
|
// info!("* Got TCP ack from: {:?} | {:?}", dest, res);
|
|
|
|
// return true;
|
|
|
|
// return true;
|
|
|
|
// }
|
|
|
|
// }
|
|
|
|
// false
|
|
|
|
// false
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
fn create_scan_thread( |
|
|
|
// fn create_scan_thread(
|
|
|
|
ip_list: Vec<ipv4::IPv4>, |
|
|
|
// ip_list: Vec<ipv4::IPv4>,
|
|
|
|
thread_id: u32, |
|
|
|
// thread_id: u32,
|
|
|
|
ips_per_thread: u32, |
|
|
|
// ips_per_thread: u32,
|
|
|
|
target_port: u16, |
|
|
|
// target_port: u16,
|
|
|
|
) -> JoinHandle<Vec<bool>> { |
|
|
|
// ) -> JoinHandle<Vec<bool>> {
|
|
|
|
thread::spawn(move || { |
|
|
|
// thread::spawn(move || {
|
|
|
|
info!("Starting thread worker #{}", thread_id); |
|
|
|
// info!("Starting thread worker #{}", thread_id);
|
|
|
|
let mut results: Vec<bool> = Vec::new(); |
|
|
|
// let mut results: Vec<bool> = Vec::new();
|
|
|
|
|
|
|
|
//
|
|
|
|
// do the scan thing
|
|
|
|
// // do the scan thing
|
|
|
|
for i in 0..ips_per_thread { |
|
|
|
// for i in 0..ips_per_thread {
|
|
|
|
let id = (thread_id * ips_per_thread) + i; |
|
|
|
// let id = (thread_id * ips_per_thread) + i;
|
|
|
|
let ref target = ip_list[id as usize]; |
|
|
|
// let ref target = ip_list[id as usize];
|
|
|
|
let result = tcp_scan(*target, target_port); |
|
|
|
// let result = tcp_scan(*target, target_port);
|
|
|
|
results.push(result); |
|
|
|
// results.push(result);
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
//
|
|
|
|
results |
|
|
|
// results
|
|
|
|
}) |
|
|
|
// })
|
|
|
|
} |
|
|
|
// }
|
|
|
|
|
|
|
|
|
|
|
|
pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Option<Vec<u64>>) -> Result<()> { |
|
|
|
pub fn start_scan( |
|
|
|
|
|
|
|
from: u32, |
|
|
|
|
|
|
|
to: u32, |
|
|
|
|
|
|
|
target_port: u16, |
|
|
|
|
|
|
|
num_threads: u32, |
|
|
|
|
|
|
|
ignorelist: Option<Vec<u32>>, |
|
|
|
|
|
|
|
) -> Result<()> { |
|
|
|
println!("Starting wwmap..."); |
|
|
|
println!("Starting wwmap..."); |
|
|
|
let ip_list = ipv4::get_all(ignorelist)?; |
|
|
|
//let ip_list = ipv4::get_all(ignorelist)?;
|
|
|
|
|
|
|
|
|
|
|
|
println!("Post list gen"); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
let ips_per_thread = ((ip_list.len() as f32) / num_threads as f32) as u32; |
|
|
|
let ips_per_thread = (((to - from) as f32) / num_threads as f32) as u32; |
|
|
|
let ips_left = num_threads * ips_per_thread; // how many ips we have left after the first threads
|
|
|
|
let ips_left = num_threads * ips_per_thread; // how many ips we have left after the first threads
|
|
|
|
|
|
|
|
|
|
|
|
// container for all of our threads
|
|
|
|
let ip_ranges: Vec<ipv4::IPv4_Range> = Vec::new(); |
|
|
|
let mut threads: Vec<JoinHandle<Vec<bool>>> = Vec::new(); |
|
|
|
|
|
|
|
let result_list: Vec<bool> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create all of our threads
|
|
|
|
|
|
|
|
for thread_id in 0..num_threads { |
|
|
|
for thread_id in 0..num_threads { |
|
|
|
threads.push(create_scan_thread( |
|
|
|
let (f, t) = ((thread_id * ips_per_thread), ((thread_id + 1) * ips_per_thread)); |
|
|
|
ip_list.clone(), |
|
|
|
let range = ipv4::IPv4_Range::new(f, t, ignorelist);
|
|
|
|
thread_id, |
|
|
|
|
|
|
|
ips_per_thread, |
|
|
|
|
|
|
|
target_port, |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// create the last thread to do the job
|
|
|
|
ip_ranges.push(range); |
|
|
|
if ips_left > 0 { |
|
|
|
|
|
|
|
threads.push(create_scan_thread( |
|
|
|
|
|
|
|
ip_list, |
|
|
|
|
|
|
|
num_threads, |
|
|
|
|
|
|
|
ips_left, |
|
|
|
|
|
|
|
target_port, |
|
|
|
|
|
|
|
)); |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
// Append all of the results into the list
|
|
|
|
// container for all of our threads
|
|
|
|
|
|
|
|
let mut threads: Vec<JoinHandle<Vec<bool>>> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// container for all the results
|
|
|
|
|
|
|
|
let mut result_list: Vec<bool> = Vec::new(); |
|
|
|
|
|
|
|
|
|
|
|
Ok(()) |
|
|
|
Ok(()) |
|
|
|
} |
|
|
|
} |
|
|
|