From 09bf94bcd294e30ff1ff8ff9e568c067ff06f332 Mon Sep 17 00:00:00 2001 From: "E. Almqvist" Date: Wed, 10 Aug 2022 18:33:53 +0200 Subject: [PATCH] Fixes --- src/ipv4.rs | 4 ++-- src/main.rs | 16 ++-------------- src/scanner.rs | 30 +++++++++--------------------- 3 files changed, 13 insertions(+), 37 deletions(-) diff --git a/src/ipv4.rs b/src/ipv4.rs index c3755ae..c83ce74 100644 --- a/src/ipv4.rs +++ b/src/ipv4.rs @@ -29,7 +29,7 @@ impl IPv4 { // In case we are missing some digits if ip.len() < 4 { - for i in 0..(4 - ip.len()) { + for _ in 0..(4 - ip.len()) { ip.insert(0, 0); } } @@ -38,7 +38,7 @@ impl IPv4 { ip = ip.into_iter().rev().collect(); // convert to array - let ip: [u8; 4] = ip.try_into().unwrap_or_else(|v: Vec| panic!("Unable to convert Vec to [u8; 4] for IPv4!")); + let ip: [u8; 4] = ip.try_into().unwrap_or_else(|_: Vec| panic!("Unable to convert Vec to [u8; 4] for IPv4!")); Self { id, diff --git a/src/main.rs b/src/main.rs index ea3067d..e7b8009 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,21 +1,9 @@ -#![allow( - dead_code, - unused_variables, - //unused_imports, // TODO: rm -)] - mod ipv4; mod scanner; mod util; -use ipv4::IPv4; +//use ipv4::IPv4; fn main() { - // scanner::start_scan(100); - // permutations::ipv4(None); - - let ip = IPv4::new((u32::max_value()) as u64); - println!("{:?}", ip); - let ip = IPv4::new(256); - println!("{:?}", ip); } + diff --git a/src/scanner.rs b/src/scanner.rs index 25e7fbd..24e6022 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -5,33 +5,31 @@ use std::thread; use std::thread::JoinHandle; use std::net::{SocketAddr, TcpStream}; -fn tcp_scan(dest: &SocketAddr) -> bool { +fn tcp_scan(mut target: ipv4::IPv4, target_port: u16) -> bool { + let dest = target.to_socketaddr(target_port).unwrap(); + if let Ok(res) = TcpStream::connect(dest) { - info!("Got TCP ack from: {:?}", dest); + info!("* Got TCP ack from: {:?} | {:?}", dest, res); return true; } false } -// TODO: do thread optimization - -pub fn scan(target: &ipv4::IPv4) -> bool { - true -} - fn create_scan_thread( ip_list: Vec, thread_id: u32, ips_per_thread: u32, + target_port: u16 ) -> JoinHandle> { thread::spawn(move || { + info!("Starting thread worker #{}", thread_id); let mut results: Vec = Vec::new(); // do the scan thing for i in 0..ips_per_thread { let id = (thread_id * ips_per_thread) + i; let ref target = ip_list[id as usize]; - let result = scan(&target); + let result = tcp_scan(*target, target_port); results.push(result); } @@ -55,24 +53,14 @@ pub fn start_scan(target_port: u16, num_threads: u32, ignorelist: Option 0 { - threads.push(create_scan_thread(ip_list, num_threads, ips_left)); + threads.push(create_scan_thread(ip_list, num_threads, ips_left, target_port)); } Ok(()) } - -/* - -depth: u32 -blacklist_ips: Vec - -pre: - # generate IPs - ALL_IPS: Vec> = ... - -*/