diff --git a/src/filters.rs b/src/filters.rs index 89c4bc2..b97da65 100644 --- a/src/filters.rs +++ b/src/filters.rs @@ -47,6 +47,7 @@ pub struct WildcardFilter { pub size: u64, } +/// implementation of FeroxFilter for WildcardFilter impl FeroxFilter for WildcardFilter { /// Examine size, dynamic, and content_len to determine whether or not the response received /// is a wildcard response and therefore should be filtered out @@ -86,7 +87,46 @@ impl FeroxFilter for WildcardFilter { other.downcast_ref::().map_or(false, |a| self == a) } - /// Return seld as Any for dynamic dispatch purposes + /// Return self as Any for dynamic dispatch purposes + fn as_any(&self) -> &dyn Any { + self + } +} + +/// Simple implementor of FeroxFilter; used to filter out status codes specified using +/// -C|--filter-status +#[derive(Default, Debug, PartialEq)] +pub struct StatusCodeFilter { + /// Status code that should not be displayed to the user + pub filter_code: u16, +} + +/// implementation of FeroxFilter for StatusCodeFilter +impl FeroxFilter for StatusCodeFilter { + /// Check `filter_code` against what was passed in via -C|--filter-status + fn should_filter_response(&self, response: &FeroxResponse) -> bool { + log::trace!("enter: should_filter_response({:?} {:?})", self, response); + + if response.status().as_u16() == self.filter_code { + log::debug!( + "filtered out {} based on --filter-status of {}", + response.url(), + self.filter_code + ); + log::trace!("exit: should_filter_response -> true"); + return true; + } + + log::trace!("exit: should_filter_response -> false"); + false + } + + /// Compare one StatusCodeFilter to another + fn box_eq(&self, other: &dyn Any) -> bool { + other.downcast_ref::().map_or(false, |a| self == a) + } + + /// Return self as Any for dynamic dispatch purposes fn as_any(&self) -> &dyn Any { self } diff --git a/src/scanner.rs b/src/scanner.rs index ec71255..d2f7f95 100644 --- a/src/scanner.rs +++ b/src/scanner.rs @@ -1,6 +1,6 @@ use crate::config::{CONFIGURATION, PROGRESS_BAR}; use crate::extractor::get_links; -use crate::filters::{FeroxFilter, WildcardFilter}; +use crate::filters::{FeroxFilter, StatusCodeFilter, WildcardFilter}; use crate::utils::{format_url, get_current_depth, make_request}; use crate::{heuristics, progress, FeroxChannel, FeroxResponse}; use futures::future::{BoxFuture, FutureExt}; @@ -70,34 +70,34 @@ fn add_url_to_list_of_scanned_urls(resp: &str, scanned_urls: &RwLock, - wildcard_filters: Arc>>>, + ferox_filters: Arc>>>, ) -> bool { log::trace!( - "enter: add_filter_to_list_of_wildcard_filters({:?}, {:?})", + "enter: add_filter_to_list_of_ferox_filters({:?}, {:?})", filter, - wildcard_filters + ferox_filters ); - match wildcard_filters.write() { + match ferox_filters.write() { Ok(mut filters) => { // If the set did not contain the assigned filter, true is returned. // If the set did contain the assigned filter, false is returned. if filters.contains(&filter) { - log::trace!("exit: add_filter_to_list_of_wildcard_filters -> false"); + log::trace!("exit: add_filter_to_list_of_ferox_filters -> false"); return false; } filters.push(filter); - log::trace!("exit: add_filter_to_list_of_wildcard_filters -> true"); + log::trace!("exit: add_filter_to_list_of_ferox_filters -> true"); true } Err(e) => { // poisoned lock log::error!("Set of wildcard filters poisoned: {}", e); - log::trace!("exit: add_filter_to_list_of_wildcard_filters -> false"); + log::trace!("exit: add_filter_to_list_of_ferox_filters -> false"); false } } @@ -578,13 +578,23 @@ pub async fn scan_url( .await }); + // add any wildcard filters to `FILTERS` let filter = match heuristics::wildcard_test(&target_url, wildcard_bar, heuristics_file_clone).await { Some(f) => Box::new(f), None => Box::new(WildcardFilter::default()), }; - add_filter_to_list_of_wildcard_filters(filter, FILTERS.clone()); + add_filter_to_list_of_ferox_filters(filter, FILTERS.clone()); + + // add any status code filters to `FILTERS` + for code_filter in &CONFIGURATION.filter_status { + let filter = StatusCodeFilter { + filter_code: *code_filter, + }; + let boxed_filter = Box::new(filter); + add_filter_to_list_of_ferox_filters(boxed_filter, FILTERS.clone()); + } // producer tasks (mp of mpsc); responsible for making requests let producers = stream::iter(looping_words.deref().to_owned())