From d645052391a17e5e942cb51fced2f59cbc4dacc9 Mon Sep 17 00:00:00 2001 From: Stuart Morgan Date: Sat, 5 Dec 2015 15:02:31 +0000 Subject: [PATCH] Moved the 'add_delay_jitter' function to scanner.rb so that all modules can benefit from it if needed --- lib/msf/core/auxiliary/scanner.rb | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/lib/msf/core/auxiliary/scanner.rb b/lib/msf/core/auxiliary/scanner.rb index ac4991cbf0..3a802839a4 100644 --- a/lib/msf/core/auxiliary/scanner.rb +++ b/lib/msf/core/auxiliary/scanner.rb @@ -299,6 +299,36 @@ def scanner_show_progress end end +def add_delay_jitter(_delay, _jitter) + # Introduce the delay + delay_value = _delay.to_i + original_value = delay_value + jitter_value = _jitter.to_i + + # Retrieve the jitter value and delay value + # Delay = number of milliseconds to wait between each request + # Jitter = percentage modifier. For example: + # Delay is 1000ms (i.e. 1 second), Jitter is 50. + # 50/100 = 0.5; 0.5*1000 = 500. Therefore, the per-request + # delay will be 1000 +/- a maximum of 500ms. + if delay_value>0 + if jitter_value>0 + rnd = Random.new + if (rnd.rand(2)==0) + delay_value += rnd.rand(jitter_value) + else + delay_value -= rnd.rand(jitter_value) + end + if delay_value<0 + delay_value = 0 + end + end + final_delay = delay_value.to_f/1000.0 + vprint_status("Delaying for #{final_delay} second(s) (#{original_value}ms +/- #{jitter_value}ms)") + sleep final_delay + end +end + end end