Fixes & tweaks

main
E. Almqvist 2 years ago
parent 18fff8d4af
commit f13269bb24
  1. 1
      Cargo.toml
  2. 16
      src/cli.rs
  3. 11
      src/ipv4.rs
  4. 5
      src/main.rs
  5. 11
      src/scanner.rs

@ -11,3 +11,4 @@ log = "0.4"
convert-base = "1.1.2" convert-base = "1.1.2"
clap = { version = "3.2.16", features = ["derive"] } clap = { version = "3.2.16", features = ["derive"] }
cidr-utils = "0.5.7" cidr-utils = "0.5.7"
env_logger = "0.9.0"

@ -1,5 +1,5 @@
use clap::Parser; use clap::Parser;
use std::path::PathBuf; // use std::path::PathBuf;
#[derive(Parser, Debug)] #[derive(Parser, Debug)]
#[clap(name = "World Wide Mapping", version, about = "Scan the world wide web for a certian port.", long_about = None)] #[clap(name = "World Wide Mapping", version, about = "Scan the world wide web for a certian port.", long_about = None)]
@ -15,13 +15,13 @@ pub struct Args {
)] )]
pub threads: u64, pub threads: u64,
#[clap( // #[clap(
help = "A file containing ignored IPv4 addresses (seperated by linebreaks).", // help = "A file containing ignored IPv4 addresses (seperated by linebreaks).",
short = 'i', // short = 'i',
long = "ignore-ip-list", // long = "ignore-ip-list",
default_value = "ignore-ips-list.txt" // default_value = "ignore-ips-list.txt"
)] // )]
pub ignorelist: PathBuf, // pub ignorelist: PathBuf,
#[clap( #[clap(
help = "Enable verbose (debug) output", help = "Enable verbose (debug) output",

@ -43,7 +43,7 @@ impl IPv4 {
Self { id, ip } Self { id, ip }
} }
pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> { pub fn to_ipaddr(self: &mut Self) -> Result<IpAddr> { // TODO: remove unneeded Result returns
if let [a, b, c, d] = self.ip[0..4] { if let [a, b, c, d] = self.ip[0..4] {
Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d))) Ok(IpAddr::V4(Ipv4Addr::new(a, b, c, d)))
} else { } else {
@ -57,6 +57,7 @@ impl IPv4 {
} }
} }
#[derive(Debug)]
pub struct IPv4Range { pub struct IPv4Range {
pub id_start: u32, pub id_start: u32,
pub id_end: u32, pub id_end: u32,
@ -68,8 +69,8 @@ impl IPv4Range {
let to = to.clamp(0, u32::max_value()); let to = to.clamp(0, u32::max_value());
let id_ignore = id_ignore.unwrap_or(Vec::new()); let id_ignore = id_ignore.unwrap_or(Vec::new());
if from >= to { if from > to {
panic!("Range size must be >= 1! from={} >= to={}", from, to); panic!("Range size must be >= 1! from={} > to={}", from, to);
} }
Self { Self {
@ -81,7 +82,9 @@ impl IPv4Range {
pub fn from_cidr(cidr_string: String, id_ignore: Option<Vec<u32>>) -> Self { pub fn from_cidr(cidr_string: String, id_ignore: Option<Vec<u32>>) -> Self {
let cidr = Ipv4Cidr::from_str(cidr_string).unwrap(); let cidr = Ipv4Cidr::from_str(cidr_string).unwrap();
let (from, to) = (cidr.first(), cidr.last()); let (from, to) = (cidr.first(), cidr.last()); // TODO: fix forgotten "constants"
println!("{:?}", cidr.last_as_u8_array());
Self::new(from, to, id_ignore) Self::new(from, to, id_ignore)
} }

@ -9,7 +9,10 @@ use ipv4::IPv4Range;
use scanner::start_scan; use scanner::start_scan;
fn main() { fn main() {
// Get CLI arguments // Init the logger
env_logger::init();
// Get the CLI arguments
let args = Args::parse(); let args = Args::parse();
// Get the IP range // Get the IP range

@ -1,6 +1,6 @@
use crate::ipv4::{IPv4, IPv4Range}; use crate::ipv4::{IPv4, IPv4Range};
use core::time::Duration; use core::time::Duration;
use log::warn; use log::{warn, debug, info};
use std::net::TcpStream; use std::net::TcpStream;
use std::thread::JoinHandle; use std::thread::JoinHandle;
use std::{panic, thread}; use std::{panic, thread};
@ -13,9 +13,10 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool {
let timeout = Duration::new(1, 0); let timeout = Duration::new(1, 0);
if let Ok(_res) = TcpStream::connect_timeout(&dest, timeout) { if let Ok(_res) = TcpStream::connect_timeout(&dest, timeout) {
println!("* {:?}", dest); println!("{:?}", dest);
true true
} else { } else {
debug!("Timeout * {:?}", dest);
false false
} }
} }
@ -23,6 +24,7 @@ fn tcp_scan(mut target: IPv4, target_port: u16) -> bool {
fn create_scan_thread(ip_range: IPv4Range, target_port: u16) -> JoinHandle<Vec<(u32, bool)>> { fn create_scan_thread(ip_range: IPv4Range, target_port: u16) -> JoinHandle<Vec<(u32, bool)>> {
thread::spawn(move || { thread::spawn(move || {
let mut results: Vec<(u32, bool)> = Vec::new(); let mut results: Vec<(u32, bool)> = Vec::new();
debug!("Created scan worker for IPv4 range: {:?}", ip_range);
// do the scan thing // do the scan thing
ip_range.into_iter().for_each(|id| { ip_range.into_iter().for_each(|id| {
@ -63,6 +65,7 @@ fn get_scan_workers(
let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new(); let mut threads: Vec<JoinHandle<Vec<(u32, bool)>>> = Vec::new();
// TODO: make last thread do the "ips_left" work // TODO: make last thread do the "ips_left" work
debug!("Creating scan workers...");
for thread_id in 0..num_threads { for thread_id in 0..num_threads {
let id_ignorelist = range.id_ignore.clone(); let id_ignorelist = range.id_ignore.clone();
@ -111,7 +114,7 @@ pub fn start_scan(range: IPv4Range, target_port: u16, num_threads: u64) -> Vec<S
// Get the workers // Get the workers
let scan_workers = get_scan_workers(range, target_port, num_threads); let scan_workers = get_scan_workers(range, target_port, num_threads);
println!("Loaded {} scan worker(s).", scan_workers.len()); info!("Loaded {} scan worker(s).", scan_workers.len());
let mut results: Vec<ScanResult> = Vec::new(); let mut results: Vec<ScanResult> = Vec::new();
@ -130,5 +133,7 @@ pub fn start_scan(range: IPv4Range, target_port: u16, num_threads: u64) -> Vec<S
results.append(&mut worker_results); results.append(&mut worker_results);
} }
println!("Scan finished with {} result(s).", results.len());
results results
} }

Loading…
Cancel
Save