Skip to content

Commit

Permalink
Merge pull request #823 from epi052/819-fix-resume-with-offset
Browse files Browse the repository at this point in the history
fix resume with offset
  • Loading branch information
epi052 authored Mar 12, 2023
2 parents c04bf4a + 8a72e49 commit 04a43a0
Show file tree
Hide file tree
Showing 5 changed files with 74 additions and 60 deletions.
83 changes: 38 additions & 45 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 10 additions & 6 deletions src/event_handlers/container.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,13 +160,17 @@ impl Handles {
/// number of extensions plus the number of request method types plus any dynamically collected
/// extensions
pub fn expected_num_requests_multiplier(&self) -> usize {
let multiplier = self.config.extensions.len()
+ self.config.methods.len()
+ self.num_collected_extensions();
let mut multiplier = self.config.extensions.len().max(1);

// methods should always have at least 1 member, likely making this .max call unneeded
// but leaving it for 'just in case' reasons
multiplier.max(1)
if multiplier > 1 {
// when we have more than one extension, we need to account for the fact that we'll
// be making a request for each extension and the base word (e.g. /foo.html and /foo)
multiplier += 1;
}

multiplier *= self.config.methods.len().max(1) * self.num_collected_extensions().max(1);

multiplier
}

/// Helper to easily get the (locked) underlying FeroxScans object
Expand Down
20 changes: 13 additions & 7 deletions src/event_handlers/scans.rs
Original file line number Diff line number Diff line change
Expand Up @@ -294,12 +294,7 @@ impl ScanHandler {
if let Ok(guard) = self.wordlist.lock().as_ref() {
if let Some(list) = guard.as_ref() {
return if offset > 0 {
// the offset could be off a bit, so we'll adjust it backwards by 10%
// of the overall wordlist size to ensure we don't miss any words
// (hopefully)
let adjusted_offset = offset - ((offset as f64 * 0.10) as usize);

Ok(Arc::new(list[adjusted_offset..].to_vec()))
Ok(Arc::new(list[offset..].to_vec()))
} else {
Ok(list.clone())
};
Expand Down Expand Up @@ -337,7 +332,18 @@ impl ScanHandler {
continue;
}

let list = self.get_wordlist(scan.requests() as usize)?;
let divisor = self.handles.expected_num_requests_multiplier();

let list = if divisor > 1 && scan.requests() > 0 {
// if there were extensions provided and/or more than a single method used, and some
// number of requests have already been sent, we need to adjust the offset into the
// wordlist to ensure we don't index out of bounds

let adjusted = scan.requests_made_so_far() as f64 / divisor as f64 - 1.0;
self.get_wordlist(adjusted as usize)?
} else {
self.get_wordlist(scan.requests_made_so_far() as usize)?
};

log::info!("scan handler received {} - beginning scan", target);

Expand Down
7 changes: 6 additions & 1 deletion src/event_handlers/statistics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,12 @@ impl StatsHandler {
);

self.bar.set_message(&msg);
self.bar.inc(1);

if self.bar.position() < self.stats.total_expected() as u64 {
// don't run off the end when we're a few requests over the expected total
// due to the heuristics tests
self.bar.inc(1);
}
}

/// Initialize new `Stats` object and the sc side of an mpsc channel that is responsible for
Expand Down
8 changes: 7 additions & 1 deletion src/scan_manager/scan.rs
Original file line number Diff line number Diff line change
Expand Up @@ -154,7 +154,13 @@ impl FeroxScan {
pub(super) fn stop_progress_bar(&self) {
if let Ok(guard) = self.progress_bar.lock() {
if guard.is_some() {
(*guard).as_ref().unwrap().finish_at_current_pos()
let pb = (*guard).as_ref().unwrap();

if pb.position() > self.num_requests {
pb.finish()
} else {
pb.finish_at_current_pos()
}
}
}
}
Expand Down

0 comments on commit 04a43a0

Please sign in to comment.