wordlist order is now maintained

This commit is contained in:
epi
2021-03-01 16:38:59 -06:00
parent d7cfd8ff60
commit cedb3ccc8d
5 changed files with 12 additions and 19 deletions

2
Cargo.lock generated
View File

@@ -633,7 +633,7 @@ dependencies = [
[[package]]
name = "feroxbuster"
version = "2.2.1"
version = "2.2.2"
dependencies = [
"anyhow",
"assert_cmd",

View File

@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::sync::Arc;
use reqwest::StatusCode;
@@ -53,7 +52,7 @@ pub enum Command {
TryRecursion(Box<FeroxResponse>),
/// Send a pointer to the wordlist to the recursion handler
UpdateWordlist(Arc<HashSet<String>>),
UpdateWordlist(Arc<Vec<String>>),
/// Instruct the ScanHandler to join on all known scans, use sender to notify main when done
JoinTasks(Sender<bool>),

View File

@@ -1,4 +1,3 @@
use std::collections::HashSet;
use std::sync::Arc;
use anyhow::{bail, Result};
@@ -54,7 +53,7 @@ pub struct ScanHandler {
receiver: CommandReceiver,
/// wordlist (re)used for each scan
wordlist: std::sync::Mutex<Option<Arc<HashSet<String>>>>,
wordlist: std::sync::Mutex<Option<Arc<Vec<String>>>>,
/// group of scans that need to be joined
tasks: Vec<Arc<FeroxScan>>,
@@ -105,7 +104,7 @@ impl ScanHandler {
}
/// Set the wordlist
fn wordlist(&self, wordlist: Arc<HashSet<String>>) {
fn wordlist(&self, wordlist: Arc<Vec<String>>) {
if let Ok(mut guard) = self.wordlist.lock() {
if guard.is_none() {
let _ = std::mem::replace(&mut *guard, Some(wordlist));
@@ -175,7 +174,7 @@ impl ScanHandler {
}
/// Helper to easily get the (locked) underlying wordlist
pub fn get_wordlist(&self) -> Result<Arc<HashSet<String>>> {
pub fn get_wordlist(&self) -> Result<Arc<Vec<String>>> {
if let Ok(guard) = self.wordlist.lock().as_ref() {
if let Some(list) = guard.as_ref() {
return Ok(list.clone());

View File

@@ -1,5 +1,4 @@
use std::{
collections::HashSet,
env::args,
fs::File,
io::{stderr, BufRead, BufReader},
@@ -41,14 +40,14 @@ lazy_static! {
}
/// Create a HashSet of Strings from the given wordlist then stores it inside an Arc
fn get_unique_words_from_wordlist(path: &str) -> Result<Arc<HashSet<String>>> {
fn get_unique_words_from_wordlist(path: &str) -> Result<Arc<Vec<String>>> {
log::trace!("enter: get_unique_words_from_wordlist({})", path);
let file = File::open(&path).with_context(|| format!("Could not open {}", path))?;
let reader = BufReader::new(file);
let mut words = HashSet::new();
let mut words = Vec::new();
for line in reader.lines() {
let result = match line {
@@ -60,7 +59,7 @@ fn get_unique_words_from_wordlist(path: &str) -> Result<Arc<HashSet<String>>> {
continue;
}
words.insert(result);
words.push(result);
}
log::trace!(
@@ -78,11 +77,7 @@ async fn scan(targets: Vec<String>, handles: Arc<Handles>) -> Result<()> {
// so that will allow for cheap/safe sharing of a single wordlist across multi-target scans
// as well as additional directories found as part of recursion
let words = {
let words_handles = handles.clone();
tokio::spawn(async move { get_unique_words_from_wordlist(&words_handles.config.wordlist) })
.await??
};
let words = get_unique_words_from_wordlist(&handles.config.wordlist)?;
if words.len() == 0 {
bail!("Did not find any words in {}", handles.config.wordlist);

View File

@@ -1,4 +1,4 @@
use std::{collections::HashSet, ops::Deref, sync::atomic::Ordering, sync::Arc, time::Instant};
use std::{ops::Deref, sync::atomic::Ordering, sync::Arc, time::Instant};
use anyhow::{bail, Result};
use futures::{stream, StreamExt};
@@ -40,7 +40,7 @@ pub struct FeroxScanner {
order: ScanOrder,
/// wordlist that's already been read from disk
wordlist: Arc<HashSet<String>>,
wordlist: Arc<Vec<String>>,
/// limiter that restricts the number of active FeroxScanners
scan_limiter: Arc<Semaphore>,
@@ -52,7 +52,7 @@ impl FeroxScanner {
pub fn new(
target_url: &str,
order: ScanOrder,
wordlist: Arc<HashSet<String>>,
wordlist: Arc<Vec<String>>,
scan_limiter: Arc<Semaphore>,
handles: Arc<Handles>,
) -> Self {