This repository has been archived by the owner on Jun 22, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
e84e32e
commit 831b5ab
Showing
1 changed file
with
77 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,38 +1,93 @@ | ||
//discover.rs | ||
//discovery.rs | ||
use std::fs::File; | ||
use std::io::{BufRead, BufReader}; | ||
use reqwest; | ||
use colored::*; | ||
|
||
pub async fn discover(url: String, wordlist: String, depth: u8) -> Result<(), Box<dyn std::error::Error + Send + Sync>> { | ||
let file = File::open(wordlist).expect("Failed to open the file."); | ||
let reader = BufReader::new(file); | ||
|
||
let mut targets: Vec<String> = vec![url]; | ||
|
||
// 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 mut successful: Vec<String> = Vec::new(); | ||
|
||
for target in &targets { | ||
let new_target = format!("{}/{}", target, word); | ||
let response = reqwest::get(&new_target).await?; | ||
let status = response.status().to_string(); | ||
let code = status.split_whitespace().next().unwrap_or("Unknown"); | ||
let result = code.to_string(); | ||
let target = url.clone().to_string() + &word.to_string(); | ||
let response = reqwest::get(target.clone()).await?; | ||
let status = response.status().to_string(); | ||
let code:Option<&str> = status.split_whitespace().nth(0); | ||
let result = match code { | ||
Some(code) => code.to_string(), | ||
None => String::from("Unknown"), | ||
}; | ||
match depth { | ||
0 => { | ||
println!("{} {} {}", result.clone().cyan(), word, target.clone().magenta()); | ||
}, | ||
1 => { | ||
println!("{} {} {}", result.clone().red(), word, target.clone().magenta()); | ||
let mut indicator: i32 = -1; | ||
//let resp = response.json::<HashMap<String, String>>().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.clone().green(), word, target.clone().magenta()); | ||
let mut successful: Vec<String> = vec![]; | ||
if response.status().is_success() { | ||
successful.push(target.clone()); | ||
indicator += 1; | ||
let new_target = successful[indicator as usize].clone() + "/" + &word; | ||
let new_response = reqwest::get(new_target.clone()).await?; | ||
let new_status = new_response.status().to_string(); | ||
let new_code:Option<&str> = new_status.split_whitespace().nth(0); | ||
let new_result = match new_code { | ||
Some(new_code) => new_code.to_string(), | ||
None => String::from("Unknown"), | ||
}; | ||
println!("{} {} {} {}",depth.to_string().purple().italic() ,new_result.cyan(), word, new_target.magenta()); | ||
} else { | ||
continue; | ||
} | ||
}, | ||
|
||
println!("{} {} {}", result.cyan(), word, new_target.magenta()); | ||
2 => { | ||
println!("{} {} {}", result.clone().red(), word, target.clone().magenta()); | ||
let mut indicator: i32 = -1; | ||
//let resp = response.json::<HashMap<String, String>>().await?; | ||
let mut successful: Vec<String> = vec![]; | ||
if response.status().is_success() { | ||
successful.push(target.clone()); | ||
indicator += 1; | ||
let new_target = successful[indicator as usize].clone() + "/" + &word; | ||
let new_response = reqwest::get(new_target.clone()).await?; | ||
|
||
if response.status().is_success() && depth >= 1 { | ||
successful.push(new_target.clone()); | ||
let mut new_successful: Vec<String> = vec![]; | ||
let mut new_indicator = -1; | ||
if new_response.status().is_success() { | ||
new_indicator += 1; | ||
new_successful.push(new_target.clone()); | ||
let newest_target = new_successful[new_indicator as usize].clone() + "/" + &word; | ||
let newest_response = reqwest::get(newest_target.clone()).await?; | ||
let newest_status = newest_response.status().to_string(); | ||
let newest_code:Option<&str> = newest_status.split_whitespace().nth(0); | ||
let newest_result = match newest_code { | ||
Some(newest_code) => newest_code.to_string(), | ||
None => String::from("Unknown"), | ||
}; | ||
println!("{} {} {} {}", depth.to_string().purple().italic() ,newest_result.cyan(), word, newest_target.magenta()); | ||
} | ||
} else { | ||
continue; | ||
} | ||
}, | ||
_ => { | ||
println!("Unknown Depth"); | ||
std::process::exit(1) | ||
} | ||
} | ||
|
||
if depth >= 1 { | ||
targets = successful; | ||
} | ||
} | ||
} | ||
|
||
}; | ||
Ok(()) | ||
} | ||
}//will be optimized. deal with it lmao |