class TimingAttack::BruteForcer
Constants
- POTENTIAL_BYTES
Attributes
known[R]
Public Class Methods
new(options: {})
click to toggle source
Calls superclass method
TimingAttack::Attacker::new
# File lib/timing_attack/brute_forcer.rb, line 5 def initialize(options: {}) super(options: options) @known = "" end
Private Instance Methods
attack!()
click to toggle source
# File lib/timing_attack/brute_forcer.rb, line 14 def attack! begin while(true) attack_byte! end rescue Errors::BruteForcerError => e puts "\n#{e.message}" exit(1) end end
attack_byte!()
click to toggle source
# File lib/timing_attack/brute_forcer.rb, line 25 def attack_byte! @attacks = POTENTIAL_BYTES.map do |byte| TimingAttack::TestCase.new(input: "#{known}#{byte}", options: options) end run_attacks_for_single_byte! process_attacks_for_single_byte! end
output()
click to toggle source
# File lib/timing_attack/brute_forcer.rb, line 62 def output @output ||= TimingAttack::Spinner.new end
process_attacks_for_single_byte!()
click to toggle source
# File lib/timing_attack/brute_forcer.rb, line 50 def process_attacks_for_single_byte! attacks.each(&:process!) grouper = Grouper.new(attacks: attacks, group_by: { percentile: options.fetch(:percentile) }) results = grouper.long_tests.map(&:input) if grouper.long_tests.count > 1 msg = "Got too many possibilities to continue brute force:\n\t" msg << results.join("\t") raise Errors::BruteForcerError.new(msg) end @known = results.first end
run_attacks_for_single_byte!()
click to toggle source
# File lib/timing_attack/brute_forcer.rb, line 34 def run_attacks_for_single_byte! hydra = Typhoeus::Hydra.new(max_concurrency: concurrency) iterations.times do attacks.each do |attack| req = attack.generate_hydra_request! req.on_complete do |response| print "\r#{' ' * (known.length + 4)}" output.increment print " '#{known}'" end hydra.queue req end end hydra.run end