Skip to content

Commit

Permalink
wrap things in tons of Arcs
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaylor89 committed Aug 31, 2024
1 parent 116121f commit 3afa57c
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 38 deletions.
39 changes: 20 additions & 19 deletions src/checker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,13 @@ use crate::{
waf::waf_hit,
};
use color_eyre::eyre;
use std::collections::HashMap;
use std::{collections::HashMap, sync::Arc};
use tokio::sync::mpsc::channel;

#[derive(Debug, Clone)]
pub struct CheckOptions {
pub timeout: u64,
pub proxy: Option<String>,
pub proxy: Arc<Option<String>>,
pub print_all: bool,
pub print_found: bool,
pub dump_response: bool,
Expand All @@ -21,7 +21,7 @@ pub struct CheckOptions {

pub async fn check_username(
username: &str,
site_data: HashMap<String, TargetInfo>,
site_data: Arc<HashMap<String, Arc<TargetInfo>>>,
options: &CheckOptions,
) -> color_eyre::Result<Vec<QueryResult>> {
let CheckOptions {
Expand All @@ -41,14 +41,15 @@ pub async fn check_username(
let (tx, mut rx) = channel::<RequestResult>(num_of_sites);

// ping sites for username matches
for (site, info) in site_data.into_iter() {
let username = Arc::new(username.to_string());
for (site, info) in site_data.iter() {
add_result_to_channel(
tx.clone(),
username.to_owned(),
site,
info,
Arc::clone(&username),
Arc::new(site.to_string()),
Arc::clone(&info),
*timeout,
proxy.clone(),
Arc::clone(proxy),
)?;
}

Expand All @@ -66,19 +67,19 @@ pub async fn check_username(
let query_result: QueryResult = match result.response {
Err(e) => match e {
QueryError::InvalidUsernameError => QueryResult {
username: username.clone(),
site_name: site,
url_main: info.url_main,
username: Arc::clone(&username),
site_name: Arc::clone(&site),
info: Arc::clone(&info),
site_url_user: url,
status: QueryStatus::Illegal,
http_status: None,
query_time: result.query_time,
context: Some(e.to_string()),
},
QueryError::RequestError => QueryResult {
username: username.clone(),
site_name: site,
url_main: info.url_main,
username: Arc::clone(&username),
site_name: Arc::clone(&site),
info: Arc::clone(&info),
site_url_user: url,
status: QueryStatus::Unknown,
http_status: None,
Expand All @@ -91,8 +92,8 @@ pub async fn check_username(
let resp_text = response.text().await?;
let wfthit = waf_hit(&resp_text);

let error_type = info.error_type;
let error_code = info.error_code;
let error_type = &info.error_type;
let error_code = &info.error_code;
let status = match (wfthit, &error_type) {
(true, _) => QueryStatus::Waf,
(false, ErrorType::Message) => {
Expand Down Expand Up @@ -152,9 +153,9 @@ pub async fn check_username(
}

QueryResult {
username: username.clone(),
site_name: site,
url_main: info.url_main,
username: Arc::clone(&username),
site_name: Arc::clone(&site),
info: Arc::clone(&info),
site_url_user: url,
status,
http_status: Some(status_code),
Expand Down
14 changes: 11 additions & 3 deletions src/main.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
use std::{collections::HashMap, sync::Arc};

use clap::Parser;
use color_eyre::Result;
use sherlock::{
checker::{check_username, CheckOptions},
get_data::{get_default_data, get_json_data},
output::{save_results, SaveOptions},
sherlock_target_manifest::SherlockTargetManifest,
sherlock_target_manifest::{SherlockTargetManifest, TargetInfo},
utils::create_username_variants,
};

Expand Down Expand Up @@ -119,11 +121,17 @@ async fn main() -> Result<()> {
.collect(),
};

let arc_targets = filtered_targets
.into_iter()
.map(|(site, info)| (site, Arc::new(info)))
.collect::<HashMap<String, Arc<TargetInfo>>>();
let arc_targets = Arc::new(arc_targets);

let username_variants = create_username_variants(&cli.usernames);

let check_options = CheckOptions {
timeout: cli.timeout,
proxy: cli.proxy.clone(),
proxy: Arc::new(cli.proxy),
print_all: cli.print_all,
print_found: cli.print_found,
dump_response: cli.dump_response,
Expand All @@ -140,7 +148,7 @@ async fn main() -> Result<()> {
};

for username in username_variants {
let results = check_username(&username, filtered_targets.clone(), &check_options).await?;
let results = check_username(&username, Arc::clone(&arc_targets), &check_options).await?;
save_results(&username, results, &save_options)?;
}

Expand Down
2 changes: 1 addition & 1 deletion src/output.rs
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ pub fn write_csv(
"{},{},{},{},{:?},{},{}",
username,
result.site_name,
result.url_main,
result.info.url_main,
result.site_url_user,
result.status,
result.http_status.as_ref().unwrap_or(&0),
Expand Down
23 changes: 12 additions & 11 deletions src/query.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
use fancy_regex::Regex;
use std::sync::Arc;
use std::time::Duration;
use std::{fmt, time::Instant};
use thiserror::Error;
Expand Down Expand Up @@ -32,9 +33,9 @@ pub enum QueryStatus {

#[derive(Debug)]
pub struct QueryResult {
pub username: String,
pub site_name: String,
pub url_main: String,
pub username: Arc<String>,
pub site_name: Arc<String>,
pub info: Arc<TargetInfo>,
pub site_url_user: String,
pub status: QueryStatus,
pub http_status: Option<u16>,
Expand All @@ -53,11 +54,11 @@ impl fmt::Display for QueryResult {

pub fn add_result_to_channel(
sender: Sender<RequestResult>,
username: String,
site: String,
info: TargetInfo,
username: Arc<String>,
site: Arc<String>,
info: Arc<TargetInfo>,
timeout: u64,
proxy: Option<String>,
proxy: Arc<Option<String>>,
) -> color_eyre::Result<()> {
let encoded_username = &username.replace(" ", "%20");
let profile_url = info.url.interpolate(encoded_username);
Expand All @@ -81,8 +82,8 @@ pub fn add_result_to_channel(
if !is_match {
// No need to do the check at the site: this username is not allowed.
let request_result = RequestResult {
username: username.clone(),
site,
username: Arc::clone(&username),
site: Arc::clone(&site),
info,
url: profile_url,
url_probe,
Expand Down Expand Up @@ -123,8 +124,8 @@ pub fn add_result_to_channel(
let duration = start.elapsed();

let request_result = RequestResult {
username: username.clone(),
site,
username: Arc::clone(&username),
site: Arc::clone(&site),
info,
url: profile_url.clone(),
url_probe,
Expand Down
8 changes: 4 additions & 4 deletions src/requests.rs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
use once_cell::sync::Lazy;
use rand::seq::SliceRandom;
use std::{collections::HashMap, time::Duration};
use std::{collections::HashMap, sync::Arc, time::Duration};

use reqwest::{
header::{HeaderMap, HeaderName, HeaderValue},
Expand Down Expand Up @@ -28,9 +28,9 @@ static USER_AGENTS: Lazy<[&str; 8]> = Lazy::new(|| {

#[derive(Debug)]
pub struct RequestResult {
pub username: String,
pub site: String,
pub info: TargetInfo,
pub username: Arc<String>,
pub site: Arc<String>,
pub info: Arc<TargetInfo>,
pub url: String,
pub url_probe: String,
pub response: Result<Response, QueryError>,
Expand Down

0 comments on commit 3afa57c

Please sign in to comment.