mirror of
https://github.com/Astatin3/rust-scan.git
synced 2026-06-09 00:28:06 -06:00
Add docs and fix search include problem
This commit is contained in:
+10
-5
@@ -752,7 +752,7 @@ pub fn search_parallel(
|
|||||||
|| if let (Some(services_value), Some(responses_value)) =
|
|| if let (Some(services_value), Some(responses_value)) =
|
||||||
(services_data.get(key), responses_data.get(key))
|
(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(services_value),
|
||||||
std::str::from_utf8(responses_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) =
|
if let QueryDataType::Service(query_type, service_name, data_str) =
|
||||||
*query
|
*query
|
||||||
{
|
{
|
||||||
|
let data_str = &data_str.to_lowercase();
|
||||||
responses_map
|
responses_map
|
||||||
.values()
|
.values()
|
||||||
.any(|(service, data)| match query_type {
|
.any(|(service, data)| match query_type {
|
||||||
QueryType::Equals => {
|
QueryType::Equals => {
|
||||||
service == service_name && data == data_str
|
&service.to_lowercase() == service_name
|
||||||
|
&& data == data_str
|
||||||
}
|
}
|
||||||
QueryType::NotEquals => {
|
QueryType::NotEquals => {
|
||||||
service != service_name || data != data_str
|
&service.to_lowercase() != service_name
|
||||||
|
|| data != data_str
|
||||||
}
|
}
|
||||||
QueryType::Includes => {
|
QueryType::Includes => {
|
||||||
service == service_name && data.contains(data_str)
|
&service.to_lowercase() == service_name
|
||||||
|
&& data.to_lowercase().contains(data_str)
|
||||||
}
|
}
|
||||||
QueryType::NotIncludes => {
|
QueryType::NotIncludes => {
|
||||||
service != service_name || !data.contains(data_str)
|
&service.to_lowercase() != service_name
|
||||||
|
|| !data.to_lowercase().contains(data_str)
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
} else {
|
} else {
|
||||||
|
|||||||
+73
-37
@@ -20,6 +20,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
if args.len() <= 1 {
|
if args.len() <= 1 {
|
||||||
println!("You must specify a command!");
|
println!("You must specify a command!");
|
||||||
print_help(None);
|
print_help(None);
|
||||||
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
match args[1].to_lowercase().as_str() {
|
match args[1].to_lowercase().as_str() {
|
||||||
@@ -46,7 +47,7 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
}
|
}
|
||||||
print_help(Some(args[2].as_str()));
|
print_help(Some(args[2].as_str()));
|
||||||
}
|
}
|
||||||
"test" => {
|
"search" => {
|
||||||
let start = Instant::now();
|
let start = Instant::now();
|
||||||
if let Ok(query) = query::search(args[2..].join(" ")) {
|
if let Ok(query) = query::search(args[2..].join(" ")) {
|
||||||
let results = database.search(query);
|
let results = database.search(query);
|
||||||
@@ -201,7 +202,7 @@ fn scan(
|
|||||||
let _ = database.add_tcp_results(&tcp_results);
|
let _ = database.add_tcp_results(&tcp_results);
|
||||||
|
|
||||||
let service_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");
|
println!("Finished service scan");
|
||||||
let _ = database.add_service_results(&service_results);
|
let _ = database.add_service_results(&service_results);
|
||||||
}
|
}
|
||||||
@@ -214,37 +215,37 @@ fn scan(
|
|||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
fn search(database: ResultDatabase, search_type: String, arg: String) {
|
// fn search(database: ResultDatabase, search_type: String, arg: String) {
|
||||||
match search_type.as_str() {
|
// match search_type.as_str() {
|
||||||
"host" => {
|
// "host" => {
|
||||||
let row = database.get_row_by_host(&arg);
|
// let row = database.get_row_by_host(&arg);
|
||||||
if let Some(row) = row {
|
// if let Some(row) = row {
|
||||||
println!("{}", row.to_string());
|
// println!("{}", row.to_string());
|
||||||
} else {
|
// } else {
|
||||||
println!("Could not find host by argument {}", arg.as_str());
|
// println!("Could not find host by argument {}", arg.as_str());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
"port" => {
|
// "port" => {
|
||||||
let rows = database.get_rows_by_port(&arg);
|
// let rows = database.get_rows_by_port(&arg);
|
||||||
|
|
||||||
for row in rows {
|
// for row in rows {
|
||||||
println!("{}", row.to_string());
|
// println!("{}", row.to_string());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
"service" => {
|
// "service" => {
|
||||||
let rows = database.get_rows_by_service(&arg);
|
// let rows = database.get_rows_by_service(&arg);
|
||||||
|
|
||||||
for row in rows {
|
// for row in rows {
|
||||||
println!("{}", row.to_string());
|
// println!("{}", row.to_string());
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
_ => {
|
// _ => {
|
||||||
println!("Invalid search type!");
|
// println!("Invalid search type!");
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
}
|
// }
|
||||||
|
|
||||||
fn print_help(arg: Option<&str>) {
|
fn print_help(arg: Option<&str>) {
|
||||||
println!(
|
println!(
|
||||||
@@ -253,15 +254,50 @@ fn print_help(arg: Option<&str>) {
|
|||||||
None => {
|
None => {
|
||||||
"rust-scan help menu
|
"rust-scan help menu
|
||||||
Commands:
|
Commands:
|
||||||
scan <type> <hosts> (arguments) - scan a block of addresses and check for online using icmp echo
|
scan <type> <hosts> - scan a block of addresses and check for online using icmp echo
|
||||||
search <type> <arguments> - Search database
|
search <arguments> - Search database
|
||||||
help (command) - Print help"
|
help (command) - Print help"
|
||||||
|
}
|
||||||
|
Some("scan") => {
|
||||||
|
"Usage scan (type) <addresses>
|
||||||
|
|
||||||
|
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 <addresses>
|
||||||
|
Scan a block of addresses and check if their online
|
||||||
|
|
||||||
|
- scan tcp <addresses>
|
||||||
|
Scan a block of addresses and check if their online, then scan and check what ports are open
|
||||||
|
|
||||||
|
- scan service <addresses>
|
||||||
|
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 <addresses>
|
||||||
|
Same as scan service"
|
||||||
|
}
|
||||||
|
|
||||||
|
Some("search") => {
|
||||||
|
"Usage: search <arguments>
|
||||||
|
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 <addresses>
|
|
||||||
// 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(_) => {
|
Some(_) => {
|
||||||
print_help(None);
|
print_help(None);
|
||||||
"Invalid Command!"
|
"Invalid Command!"
|
||||||
|
|||||||
+3
-3
@@ -11,7 +11,7 @@ pub fn search(query: String) -> Result<Vec<QueryDataType>, Box<dyn std::error::E
|
|||||||
|
|
||||||
let split = query.split(" ");
|
let split = query.split(" ");
|
||||||
|
|
||||||
let delim = Regex::new("(?:!=|[=:;])")?;
|
let delim = Regex::new("(?:!=|[=:+-])")?;
|
||||||
|
|
||||||
let mut results = Vec::new();
|
let mut results = Vec::new();
|
||||||
|
|
||||||
@@ -27,8 +27,8 @@ pub fn search(query: String) -> Result<Vec<QueryDataType>, Box<dyn std::error::E
|
|||||||
|
|
||||||
fn get_equals_type(delim: &str) -> QueryType {
|
fn get_equals_type(delim: &str) -> QueryType {
|
||||||
match delim {
|
match delim {
|
||||||
":" => Some(QueryType::Includes),
|
":" | "+" => Some(QueryType::Includes),
|
||||||
";" => Some(QueryType::NotIncludes),
|
"-" => Some(QueryType::NotIncludes),
|
||||||
"=" => Some(QueryType::Equals),
|
"=" => Some(QueryType::Equals),
|
||||||
"!=" => Some(QueryType::NotEquals),
|
"!=" => Some(QueryType::NotEquals),
|
||||||
_ => None,
|
_ => None,
|
||||||
|
|||||||
Reference in New Issue
Block a user