From 7d4f962848d9497a2e0469a8568e70f6a32217c4 Mon Sep 17 00:00:00 2001 From: AlexanderMaxRanabel <93342430+AlexanderMaxRanabel@users.noreply.github.com> Date: Fri, 21 Jul 2023 12:01:33 +0300 Subject: [PATCH] Sharded the project --- src/discover.rs | 30 ++++++++++ src/discover_filter.rs | 99 +++++++++++++++++++++++++++++++ src/main.rs | 129 ++--------------------------------------- 3 files changed, 134 insertions(+), 124 deletions(-) create mode 100644 src/discover.rs create mode 100644 src/discover_filter.rs diff --git a/src/discover.rs b/src/discover.rs new file mode 100644 index 0000000..7fee6ca --- /dev/null +++ b/src/discover.rs @@ -0,0 +1,30 @@ +//discover.rs +use std::fs::File; +use std::io::{BufRead, BufReader}; +use reqwest; +use colored::*; + +pub async fn discover(url: String, wordlist: String) -> Result<(), Box> { + let file = File::open(wordlist).expect("Failed to open the file."); + + // Create a BufReader to read the file efficiently + let reader = BufReader::new(file); + + // Iterate over each line in the wordlist + for line in reader.lines() { + if let Ok(word) = line { + let target = url.clone().to_string() + &word.to_string(); + let response = reqwest::get(target.clone()).await?; + let status = response.status().to_string(); + //let resp = response.json::>().await?; + + let code:Option<&str> = status.split_whitespace().nth(0); + let result = match code { + Some(code) => code.to_string(), + None => String::from("Unknown"), + }; + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + } + Ok(()) +} \ No newline at end of file diff --git a/src/discover_filter.rs b/src/discover_filter.rs new file mode 100644 index 0000000..59a551a --- /dev/null +++ b/src/discover_filter.rs @@ -0,0 +1,99 @@ +//discover_filter.rs +use std::env; +use std::fs::File; +use std::io::{BufRead, BufReader}; +use reqwest; +use colored::*; + +pub async fn discover_filter(url: String, wordlist: String, filteree: String, type_fiter: String) -> Result<(), Box> { + let file = File::open(wordlist).expect("Failed to open the file."); + + // Create a BufReader to read the file efficiently + let reader = BufReader::new(file); + + // Iterate over each line in the wordlist + for line in reader.lines() { + if let Ok(word) = line { + match type_fiter.as_str() { + "--bycode" => { + let target = url.clone().to_string() + &*word.to_string(); + let response = reqwest::get(target.clone()).await?; + let status = response.status().to_string(); + //let resp = response.json::>().await?; + + let code:Option<&str> = status.split_whitespace().nth(0); + let result = match code { + Some(code) => code.to_string(), + None => String::from("Unknown"), + }; + match filteree.as_str() { + "200" => { + if response.status().is_success() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + "404" | "401" | "402" | "403" => { + if response.status().is_client_error() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + + "301" | "307" | "302" => { + if response.status().is_redirection() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + + "500" | "502" => { + if response.status().is_server_error() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + _ => println!("Unknown Status code") + } + }, + + "--bytype" => { + let target = url.clone().to_string() + &*word.to_string(); + let response = reqwest::get(target.clone()).await?; + let status = response.status().to_string(); + //let resp = response.json::>().await?; + + let code:Option<&str> = status.split_whitespace().nth(0); + let result = match code { + Some(code) => code.to_string(), + None => String::from("Unknown"), + }; + match filteree.as_str() { + "success" => { + if response.status().is_success() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + + "client_error" => { + if response.status().is_client_error() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + + "redirection" => { + if response.status().is_redirection() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + + "server_error" => { + if response.status().is_server_error() { + println!("{} {} {}", result.green(), word, target.clone().magenta()); + } + }, + _ => println!("Unknown Type") + } + }, + _ => println!("Unknown Type") + } + } + } + Ok(()) +} \ No newline at end of file diff --git a/src/main.rs b/src/main.rs index 13cd599..e7a42d6 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,130 +1,11 @@ +mod discover; +mod discover_filter; + use std::env; use std::fs::File; use std::io::{BufRead, BufReader}; -use reqwest; - -use colored::*; - -async fn discover(url: String, wordlist: String) -> Result<(), Box> { - let file = File::open(wordlist).expect("Failed to open the file."); - - // Create a BufReader to read the file efficiently - let reader = BufReader::new(file); - - // Iterate over each line in the wordlist - for line in reader.lines() { - if let Ok(word) = line { - let target = url.clone().to_string() + &word.to_string(); - let response = reqwest::get(target.clone()).await?; - let status = response.status().to_string(); - //let resp = response.json::>().await?; - - let code:Option<&str> = status.split_whitespace().nth(0); - let result = match code { - Some(code) => code.to_string(), - None => String::from("Unknown"), - }; - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - } - Ok(()) -} - -async fn discover_filter(url: String, wordlist: String, filteree: String, type_fiter: String) -> Result<(), Box> { - let file = File::open(wordlist).expect("Failed to open the file."); - - // Create a BufReader to read the file efficiently - let reader = BufReader::new(file); - - // Iterate over each line in the wordlist - for line in reader.lines() { - if let Ok(word) = line { - match type_fiter.as_str() { - "--bycode" => { - let target = url.clone().to_string() + &*word.to_string(); - let response = reqwest::get(target.clone()).await?; - let status = response.status().to_string(); - //let resp = response.json::>().await?; - - let code:Option<&str> = status.split_whitespace().nth(0); - let result = match code { - Some(code) => code.to_string(), - None => String::from("Unknown"), - }; - match filteree.as_str() { - "200" => { - if response.status().is_success() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - "404" | "401" | "402" | "403" => { - if response.status().is_client_error() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - - "301" | "307" | "302" => { - if response.status().is_redirection() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - - "500" | "502" => { - if response.status().is_server_error() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - _ => println!("Unknown Status code") - } - }, - - "--bytype" => { - let target = url.clone().to_string() + &*word.to_string(); - let response = reqwest::get(target.clone()).await?; - let status = response.status().to_string(); - //let resp = response.json::>().await?; - - let code:Option<&str> = status.split_whitespace().nth(0); - let result = match code { - Some(code) => code.to_string(), - None => String::from("Unknown"), - }; - match filteree.as_str() { - "success" => { - if response.status().is_success() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - - "client_error" => { - if response.status().is_client_error() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - - "redirection" => { - if response.status().is_redirection() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - - "server_error" => { - if response.status().is_server_error() { - println!("{} {} {}", result.green(), word, target.clone().magenta()); - } - }, - _ => println!("Unknown Type") - } - }, - _ => println!("Unknown Type") - } - } - } - Ok(()) -} - #[tokio::main] async fn main() { let args: Vec = env::args().collect(); @@ -138,12 +19,12 @@ async fn main() { let mode = &args[5].to_string(); match mode.as_str() { "--normal" => { - let _ = tokio::task::spawn(discover(url.clone(), wordlist.clone())).await; + let _ = tokio::task::spawn(discover::discover(url.clone(), wordlist.clone())).await; }, "--filter" => { let filteree = &args[7].to_string(); let type_filter = &args[6].to_string(); - let _ = tokio::task::spawn(discover_filter(url.clone(),wordlist.clone(), filteree.clone(), type_filter.clone())).await; + let _ = tokio::task::spawn(discover_filter::discover_filter(url.clone(),wordlist.clone(), filteree.clone(), type_filter.clone())).await; }, _ => println!("Unknown mode") }