fixed up build/tests

This commit is contained in:
epi
2020-12-26 19:44:00 -06:00
parent 9680e36f9d
commit 059ba24b68
3 changed files with 34 additions and 29 deletions

View File

@@ -1,11 +1,9 @@
use crate::config::CONFIGURATION;
use crate::utils::get_url_path_length;
use crate::FeroxResponse;
use crate::{FeroxResponse, FeroxSerialize};
use regex::Regex;
use ssdeep;
use std::any::Any;
use std::fmt::Debug;
use strsim::{jaro, normalized_levenshtein};
// references:
// https://dev.to/magnusstrale/rust-trait-objects-in-a-vector-non-trivial-4co5
@@ -300,10 +298,15 @@ impl FeroxFilter for SimilarityFilter {
/// Check `FeroxResponse::text` against what was requested from the site passed in via
/// --filter-similar-to
fn should_filter_response(&self, response: &FeroxResponse) -> bool {
// normalized_levenshtein(&self.text, &response.text).abs() >= self.threshold
// jaro(&self.text, &response.text).abs() >= self.threshold
let other = ssdeep::hash(response.text.as_ref()).unwrap();
ssdeep::compare(self.text.as_ref(), &other.as_ref()).unwrap() >= self.threshold
if let Some(other) = ssdeep::hash(response.text.as_ref()) {
if let Some(result) = ssdeep::compare(self.text.as_ref(), &other.as_ref()) {
return result >= self.threshold;
}
};
// couldn't hash the response, don't filter
log::warn!("Could not hash body from {}", response.as_str());
false
}
/// Compare one SizeFilter to another
@@ -471,7 +474,7 @@ mod tests {
let mut filter = SimilarityFilter {
text: String::from("kitten"),
threshold: 0.95,
threshold: 95,
};
// assert!((normalized_levenshtein("kitten", "sitting") - 0.57142).abs() < 0.00001)
@@ -480,23 +483,26 @@ mod tests {
resp.text = String::new();
filter.text = String::new();
filter.threshold = 1.0;
filter.threshold = 100;
// assert!((normalized_levenshtein("", "") - 1.0).abs() < 0.00001)
// two empty strings are the same
assert!(filter.should_filter_response(&resp));
// assert!(normalized_levenshtein("", "second").abs() < 0.00001)
// completely dissimilar; should not pass the similarity test
resp.text = String::from("second");
filter.threshold = 0.95;
// two empty strings are the same, however ssdeep doesn't accept empty strings, expect false
assert!(!filter.should_filter_response(&resp));
// assert!((normalized_levenshtein("string", "string") - 1.0).abs() < 0.00001);
// same should pass
filter.text = String::from("second");
filter.threshold = 0.99999;
assert!(filter.should_filter_response(&resp));
// let lorem =
// "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor";
//
// // assert!(normalized_levenshtein("", "second").abs() < 0.00001)
// // completely dissimilar; should not pass the similarity test
// resp.text = String::from(lorem);
// filter.threshold = 95;
//
// assert!(!filter.should_filter_response(&resp));
//
// // assert!((normalized_levenshtein("string", "string") - 1.0).abs() < 0.00001);
// // same should pass
// filter.text = String::from(lorem);
// filter.threshold = 95;
// assert!(filter.should_filter_response(&resp));
}
}

View File

@@ -1035,10 +1035,10 @@ mod tests {
let json_state = ferox_state.as_json();
let expected = format!(
r#"{{"scans":[{{"id":"{}","url":"https://spiritanimal.com","scan_type":"Directory","complete":false}}],"config":{{"type":"configuration","wordlist":"/usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt","config":"","proxy":"","replay_proxy":"","target_url":"","status_codes":[200,204,301,302,307,308,401,403,405],"replay_codes":[200,204,301,302,307,308,401,403,405],"filter_status":[],"threads":50,"timeout":7,"verbosity":0,"quiet":false,"json":false,"output":"","debug_log":"","user_agent":"feroxbuster/{}","redirects":false,"insecure":false,"extensions":[],"headers":{{}},"queries":[],"no_recursion":false,"extract_links":false,"add_slash":false,"stdin":false,"depth":4,"scan_limit":0,"filter_size":[],"filter_line_count":[],"filter_word_count":[],"filter_regex":[],"dont_filter":false,"resumed":false,"save_state":false,"time_limit":""}},"responses":[{{"type":"response","url":"https://nerdcore.com/css","path":"/css","wildcard":true,"status":301,"content_length":173,"line_count":10,"word_count":16,"headers":{{"server":"nginx/1.16.1"}}}}]}}"#,
r#"{{"scans":[{{"id":"{}","url":"https://spiritanimal.com","scan_type":"Directory","complete":false}}],"config":{{"type":"configuration","wordlist":"/usr/share/seclists/Discovery/Web-Content/raft-medium-directories.txt","config":"","proxy":"","replay_proxy":"","target_url":"","status_codes":[200,204,301,302,307,308,401,403,405],"replay_codes":[200,204,301,302,307,308,401,403,405],"filter_status":[],"threads":50,"timeout":7,"verbosity":0,"quiet":false,"json":false,"output":"","debug_log":"","user_agent":"feroxbuster/{}","redirects":false,"insecure":false,"extensions":[],"headers":{{}},"queries":[],"no_recursion":false,"extract_links":false,"add_slash":false,"stdin":false,"depth":4,"scan_limit":0,"filter_size":[],"filter_line_count":[],"filter_word_count":[],"filter_regex":[],"dont_filter":false,"resumed":false,"save_state":false,"time_limit":"","filter_similar":[]}},"responses":[{{"type":"response","url":"https://nerdcore.com/css","path":"/css","wildcard":true,"status":301,"content_length":173,"line_count":10,"word_count":16,"headers":{{"server":"nginx/1.16.1"}}}}]}}"#,
saved_id, VERSION
);
println!("{}\n{}", expected, json_state);
assert!(predicates::str::similar(expected).eval(&json_state));
}

View File

@@ -17,7 +17,6 @@ use futures::{
use lazy_static::lazy_static;
use regex::Regex;
use reqwest::Url;
use ssdeep;
#[cfg(not(test))]
use std::process::exit;
use std::{
@@ -670,7 +669,7 @@ pub async fn initialize(num_words: usize, config: &Configuration) {
// add any similarity filters to `FILTERS` (--filter-similar-to)
for similarity_filter in &config.filter_similar {
// url as-is based on input, ignores user-specified url manipulation options (add-slash etc)
if let Some(url) = format_url(&similarity_filter, &"", false, &Vec::new(), None) {
if let Ok(url) = format_url(&similarity_filter, &"", false, &Vec::new(), None) {
// attempt to request the given url
if let Ok(resp) = make_request(&CONFIGURATION.client, &url).await {
// if successful, create a filter based on the response's body
@@ -798,12 +797,12 @@ mod tests {
assert!(result);
}
#[test]
#[tokio::test(core_threads = 1)]
#[should_panic]
/// call initialize with a bad regex, triggering a panic
fn initialize_panics_on_bad_regex() {
async fn initialize_panics_on_bad_regex() {
let mut config = Configuration::default();
config.filter_regex = vec![r"(".to_string()];
initialize(1, &config);
initialize(1, &config).await;
}
}