Class: Memorandom::Plugins::RSA
- Inherits:
-
Memorandom::PluginTemplate
- Object
- Memorandom::PluginTemplate
- Memorandom::Plugins::RSA
- Defined in:
- lib/memorandom/plugins/rsa.rb
Constant Summary collapse
- @@description =
"This plugin looks for RSA keys by finding Bignum-encoded p-values"- @@confidence =
0.90
Instance Attribute Summary
Attributes inherited from Memorandom::PluginTemplate
Instance Method Summary collapse
-
#scan(buffer, source_offset) ⇒ Object
Scan takes a buffer and an offset of where this buffer starts in the source.
Methods inherited from Memorandom::PluginTemplate
#confidence, confidence, #description, description, #initialize, #report_hit, #reset
Constructor Details
This class inherits a constructor from Memorandom::PluginTemplate
Instance Method Details
#scan(buffer, source_offset) ⇒ Object
Scan takes a buffer and an offset of where this buffer starts in the source
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/memorandom/plugins/rsa.rb', line 11 def scan(buffer, source_offset) key_lengths = [1024, 2048] key_lengths.each do |bits| p_size = bits / 16 n_size = bits / 8 found = [] 0.upto(buffer.length - (p_size + n_size)) do |p_offset| # Look for a prime of the right size (p or q) found_p = OpenSSL::BN.new( buffer[p_offset, p_size].unpack("H*").first.to_i(16).to_s ) next unless found_p.prime? next unless found_p > 0x1000000000000000000000 # Look for a modulus that matches the found p/q value 0.upto(buffer.length - (p_size + n_size) ) do |n_offset| next if (n_offset < p_offset and (n_offset + n_size) > p_offset) next if (p_offset < n_offset and (p_offset + p_size) > n_offset) found_n = OpenSSL::BN.new(buffer[n_offset, n_size].unpack("H*").first.to_i(16).to_s ) next if found_n == 0 next if found_n == found_p next unless found_n > 0x1000000000000000000000 next unless (found_n % found_p == 0) found << [found_p, found_n, p_offset] end end found = found.uniq next unless found.length > 0 mods = {} # Track the last unique p/q value for a potential modulus found.each do |info| mods[ info[1] ] ||= {} mods[ info[1] ][ info[0] ] = info[2] end p mods next mods.keys.each do |n| uniq_pees = mods[n].keys.select do |k| mods[n].keys.reject {|x| x == k}.select{|x| n == (x * k) } end end end end |