Class: Brakeman::CheckWeakHash
- Inherits:
-
BaseCheck
- Object
- BaseCheck
- Brakeman::CheckWeakHash
- Defined in:
- lib/brakeman/checks/check_weak_hash.rb
Constant Summary collapse
- DIGEST_CALLS =
[:base64digest, :digest, :hexdigest, :new]
Instance Method Summary collapse
- #hashing_password?(call) ⇒ Boolean
- #process_call(exp) ⇒ Object
- #process_hash_result(result) ⇒ Object
- #process_hmac_result(result) ⇒ Object
- #process_ivar(exp) ⇒ Object
- #process_lvar(exp) ⇒ Object
- #process_openssl_result(result) ⇒ Object
- #run_check ⇒ Object
- #user_input_as_arg?(call) ⇒ Boolean
Instance Method Details
#hashing_password?(call) ⇒ Boolean
111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 111 def hashing_password? call call.each_arg do |arg| @has_password = false process arg if @has_password return @has_password end end nil end |
#process_call(exp) ⇒ Object
125 126 127 128 129 130 131 132 133 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 125 def process_call exp if exp.method == :password @has_password = exp else process_default exp end exp end |
#process_hash_result(result) ⇒ Object
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 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 24 def process_hash_result result return unless original? result input = nil call = result[:call] if DIGEST_CALLS.include? call.method if input = user_input_as_arg?(call) confidence = :high elsif input = hashing_password?(call) confidence = :high else confidence = :medium end else confidence = :medium end = msg("Weak hashing algorithm used") case call.target.last when :MD5 << ": " << msg_lit("MD5") when :SHA1 << ": " << msg_lit("SHA1") end warn :result => result, :warning_type => "Weak Hash", :warning_code => :weak_hash_digest, :message => , :confidence => confidence, :user_input => input, :cwe_id => [328] end |
#process_hmac_result(result) ⇒ Object
60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 60 def process_hmac_result result return unless original? result call = result[:call] = msg("Weak hashing algorithm used in HMAC") case call.third_arg.last when :MD5 << ": " << msg_lit("MD5") when :SHA1 << ": " << msg_lit("SHA1") end warn :result => result, :warning_type => "Weak Hash", :warning_code => :weak_hash_hmac, :message => , :confidence => :medium, :cwe_id => [328] end |
#process_ivar(exp) ⇒ Object
135 136 137 138 139 140 141 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 135 def process_ivar exp if exp.value == :@password @has_password = exp end exp end |
#process_lvar(exp) ⇒ Object
143 144 145 146 147 148 149 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 143 def process_lvar exp if exp.value == :password @has_password = exp end exp end |
#process_openssl_result(result) ⇒ Object
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 82 def process_openssl_result result return unless original? result arg = result[:call].first_arg if string? arg alg = arg.value.upcase if alg == 'MD5' or alg == 'SHA1' warn :result => result, :warning_type => "Weak Hash", :warning_code => :weak_hash_digest, :message => msg("Weak hashing algorithm used: ", msg_lit(alg)), :confidence => :medium, :cwe_id => [328] end end end |
#run_check ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 10 def run_check tracker.find_call(:targets => [:'Digest::MD5', :'Digest::SHA1', :'OpenSSL::Digest::MD5', :'OpenSSL::Digest::SHA1'], :nested => true).each do |result| process_hash_result result end tracker.find_call(:target => :'Digest::HMAC', :methods => [:new, :hexdigest], :nested => true).each do |result| process_hmac_result result end tracker.find_call(:targets => [:'OpenSSL::Digest::Digest', :'OpenSSL::Digest'], :method => :new).each do |result| process_openssl_result result end end |
#user_input_as_arg?(call) ⇒ Boolean
101 102 103 104 105 106 107 108 109 |
# File 'lib/brakeman/checks/check_weak_hash.rb', line 101 def user_input_as_arg? call call.each_arg do |arg| if input = include_user_input?(arg) return input end end nil end |