Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions crates/rwalk/src/engine/pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -429,12 +429,14 @@ impl WorkerPool {
} else {
self.pb.inc(1);
}
if self.worker_config.filterer.filter(&response)? {
self.worker_config.handler.handle(response.clone(), self)?;
if self.config.bell {
bell();
if !results.contains_key(&response.url.to_string()) {
if self.worker_config.filterer.filter(&response)? {
results.insert(response.url.to_string(), response.clone());
self.worker_config.handler.handle(response.clone(), self)?;
if self.config.bell {
bell();
}
}
results.insert(response.url.to_string(), response);
}

Ok::<(), crate::error::RwalkError>(())
Expand Down
19 changes: 12 additions & 7 deletions crates/rwalk/src/utils/tree.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ impl Node {
for (key, child) in &self.children {
if child.children.len() == 1 && !child.is_endpoint {
let (grandchild_key, grandchild) = child.children.iter().next().unwrap();
let new_key = format!("{}/{}", key, grandchild_key);
let new_key = format!("{}{}", key, grandchild_key);

keys_to_remove.push(key.clone());
nodes_to_add.insert(new_key, grandchild.clone());
Expand Down Expand Up @@ -76,7 +76,7 @@ impl TreeItem for Node {
if !self.name.is_empty() {
write!(
f,
"{} /{}",
"{} {}",
display_status_code(self.status),
style.paint(&self.name)
)
Expand All @@ -96,7 +96,12 @@ pub fn display_url_tree(base: &Url, urls: &DashMap<String, RwalkResponse>) {
let url = entry.key();
if let Ok(parsed_url) = Url::parse(url) {
let path = parsed_url.path();
let components: Vec<&str> = path.split('/').filter(|s| !s.is_empty()).collect();

let components = path
.split('/')
.filter(|s| !s.is_empty())
.map(|comp| format!("/{}", comp))
.collect::<Vec<String>>();

insert_path(&mut root, &components, entry.value());
}
Expand All @@ -111,19 +116,19 @@ pub fn display_url_tree(base: &Url, urls: &DashMap<String, RwalkResponse>) {
ptree::print_tree(&root).unwrap();
}

fn insert_path(node: &mut Node, components: &[&str], response: &RwalkResponse) {
fn insert_path(node: &mut Node, components: &[String], response: &RwalkResponse) {
if components.is_empty() {
node.is_endpoint = true;
node.status = response.status as u16;
return;
}

let component = components[0];
let component = components[0].clone();
let child = node
.children
.entry(component.to_string())
.entry(component.clone())
.or_insert_with(|| Node {
name: String::new(),
name: component,
status: response.status as u16,
..Default::default()
});
Expand Down
16 changes: 8 additions & 8 deletions crates/rwalk/src/wordlist/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ use crossbeam::deque::Injector;
use rayon::iter::{IntoParallelRefIterator, IntoParallelRefMutIterator, ParallelIterator};
use transformation::Transformer;
use url::Url;
use url::Position;

pub mod filters;
pub mod processor;
Expand Down Expand Up @@ -45,14 +44,15 @@ impl Wordlist {
}

pub fn inject_into(&self, injector: &Injector<Task>, url: &Url, depth: usize) -> Result<()> {
let base_prefix = url[..Position::BeforePath].to_string();

let base_url = url.to_string();
self.words.par_iter().try_for_each(|word| {
let full_url = if base_prefix.ends_with('/') || word.starts_with('/') {
format!("{}{}", base_prefix.trim_end_matches('/'), word)
} else {
format!("{}/{}", base_prefix, word)
};
// Trim slashes to ensure exactly one slash between
let base_trimmed = base_url.trim_end_matches('/');
let word_trimmed = word.strip_prefix('/').unwrap_or(word);

let full_url = format!("{}/{}", base_trimmed, word_trimmed);

injector.push(Task::new_recursive(full_url, depth));
Ok(())
})
Expand Down