From 39539478b7f778f90956e75a68929067453d7812 Mon Sep 17 00:00:00 2001 From: Michael Mikovsky <77305074+Astatin3@users.noreply.github.com> Date: Sat, 19 Apr 2025 13:23:30 -0600 Subject: [PATCH] Add docs and fix search include problem --- src/database.rs | 15 ++++--- src/main.rs | 110 ++++++++++++++++++++++++++++++++---------------- src/query.rs | 6 +-- 3 files changed, 86 insertions(+), 45 deletions(-) diff --git a/src/database.rs b/src/database.rs index 30ff284..78719e2 100644 --- a/src/database.rs +++ b/src/database.rs @@ -752,7 +752,7 @@ pub fn search_parallel( || if let (Some(services_value), Some(responses_value)) = (services_data.get(key), responses_data.get(key)) { - if let (Ok(services_str), Ok(responses_str)) = ( + if let (Ok(_), Ok(responses_str)) = ( std::str::from_utf8(services_value), std::str::from_utf8(responses_value), ) { @@ -763,20 +763,25 @@ pub fn search_parallel( if let QueryDataType::Service(query_type, service_name, data_str) = *query { + let data_str = &data_str.to_lowercase(); responses_map .values() .any(|(service, data)| match query_type { QueryType::Equals => { - service == service_name && data == data_str + &service.to_lowercase() == service_name + && data == data_str } QueryType::NotEquals => { - service != service_name || data != data_str + &service.to_lowercase() != service_name + || data != data_str } QueryType::Includes => { - service == service_name && data.contains(data_str) + &service.to_lowercase() == service_name + && data.to_lowercase().contains(data_str) } QueryType::NotIncludes => { - service != service_name || !data.contains(data_str) + &service.to_lowercase() != service_name + || !data.to_lowercase().contains(data_str) } }) } else { diff --git a/src/main.rs b/src/main.rs index 5338eb2..57ed493 100644 --- a/src/main.rs +++ b/src/main.rs @@ -20,6 +20,7 @@ fn main() -> Result<(), Box> { if args.len() <= 1 { println!("You must specify a command!"); print_help(None); + return Ok(()); } match args[1].to_lowercase().as_str() { @@ -46,7 +47,7 @@ fn main() -> Result<(), Box> { } print_help(Some(args[2].as_str())); } - "test" => { + "search" => { let start = Instant::now(); if let Ok(query) = query::search(args[2..].join(" ")) { let results = database.search(query); @@ -201,7 +202,7 @@ fn scan( let _ = database.add_tcp_results(&tcp_results); let service_results = - scan_services(tcp_results, min(100, up_len), Duration::from_secs(1)); + scan_services(tcp_results, min(50, up_len), Duration::from_secs(1)); println!("Finished service scan"); let _ = database.add_service_results(&service_results); } @@ -214,37 +215,37 @@ fn scan( Ok(()) } -fn search(database: ResultDatabase, search_type: String, arg: String) { - match search_type.as_str() { - "host" => { - let row = database.get_row_by_host(&arg); - if let Some(row) = row { - println!("{}", row.to_string()); - } else { - println!("Could not find host by argument {}", arg.as_str()); - } - } +// fn search(database: ResultDatabase, search_type: String, arg: String) { +// match search_type.as_str() { +// "host" => { +// let row = database.get_row_by_host(&arg); +// if let Some(row) = row { +// println!("{}", row.to_string()); +// } else { +// println!("Could not find host by argument {}", arg.as_str()); +// } +// } - "port" => { - let rows = database.get_rows_by_port(&arg); +// "port" => { +// let rows = database.get_rows_by_port(&arg); - for row in rows { - println!("{}", row.to_string()); - } - } +// for row in rows { +// println!("{}", row.to_string()); +// } +// } - "service" => { - let rows = database.get_rows_by_service(&arg); +// "service" => { +// let rows = database.get_rows_by_service(&arg); - for row in rows { - println!("{}", row.to_string()); - } - } - _ => { - println!("Invalid search type!"); - } - } -} +// for row in rows { +// println!("{}", row.to_string()); +// } +// } +// _ => { +// println!("Invalid search type!"); +// } +// } +// } fn print_help(arg: Option<&str>) { println!( @@ -253,15 +254,50 @@ fn print_help(arg: Option<&str>) { None => { "rust-scan help menu Commands: - scan (arguments) - scan a block of addresses and check for online using icmp echo - search - Search database - help (command) - Print help" + scan - scan a block of addresses and check for online using icmp echo + search - Search database + help (command) - Print help" + } + Some("scan") => { + "Usage scan (type) + +Example: scan ping 127.0.0.0/8 +Example: scan 12.34.0.0-12.34.56.78,127.0.0.1 + +scan a block of addresses using diffrent methods + +- scan ping +Scan a block of addresses and check if their online + +- scan tcp +Scan a block of addresses and check if their online, then scan and check what ports are open + +- scan service +Scan a block of addresses and check if their online, then scan to check what ports are open, then scan to check what services are running and record responses + +- scan +Same as scan service" + } + + Some("search") => { + "Usage: search +Example: search ssh:raspbian +Example: search port:80,443 http-nginx https-nginx +Example: search port-8081 https:favicon +Example: search google +Example: search port=22,80,443 + +The format of the search is a list of tags that include the service or port followed by an equator, or a plain text search + +There are four types of equators + +\":\" or \"+\" - If the result contains an item +\"-\" - If the result does not contain an item +\"=\" - If the result is exactly equal to an item +\"!=\" - If the result is exactly not equal to an item + +" } - // Some("scan") => { - // "pingscan - // scan a block of addresses and check for online using icmp echo - // Usage: pingscan 10.42.0.1,12.34.0.0-12.34.56.78,127.0.0.0/8" - // } Some(_) => { print_help(None); "Invalid Command!" diff --git a/src/query.rs b/src/query.rs index 04b1099..68b366a 100644 --- a/src/query.rs +++ b/src/query.rs @@ -11,7 +11,7 @@ pub fn search(query: String) -> Result, Box Result, Box QueryType { match delim { - ":" => Some(QueryType::Includes), - ";" => Some(QueryType::NotIncludes), + ":" | "+" => Some(QueryType::Includes), + "-" => Some(QueryType::NotIncludes), "=" => Some(QueryType::Equals), "!=" => Some(QueryType::NotEquals), _ => None,