dawnscanner 1.5.2 → 1.6.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (54) hide show
  1. checksums.yaml +4 -4
  2. checksums.yaml.gz.sig +0 -0
  3. data.tar.gz.sig +0 -0
  4. data/.travis.yml +8 -1
  5. data/Changelog.md +64 -1
  6. data/KnowledgeBase.md +38 -2
  7. data/README.md +2 -1
  8. data/VERSION +2 -3
  9. data/bin/dawn +2 -0
  10. data/checksum/dawnscanner-1.5.2.gem.sha1 +1 -0
  11. data/lib/dawn/kb/cve_2015_5312.rb +30 -0
  12. data/lib/dawn/kb/cve_2015_7497.rb +32 -0
  13. data/lib/dawn/kb/cve_2015_7498.rb +32 -0
  14. data/lib/dawn/kb/cve_2015_7499.rb +32 -0
  15. data/lib/dawn/kb/cve_2015_7500.rb +32 -0
  16. data/lib/dawn/kb/cve_2015_7519.rb +31 -0
  17. data/lib/dawn/kb/cve_2015_7541.rb +31 -0
  18. data/lib/dawn/kb/cve_2015_7576.rb +35 -0
  19. data/lib/dawn/kb/cve_2015_7577.rb +32 -0
  20. data/lib/dawn/kb/cve_2015_7578.rb +30 -0
  21. data/lib/dawn/kb/cve_2015_7579.rb +30 -0
  22. data/lib/dawn/kb/cve_2015_7581.rb +33 -0
  23. data/lib/dawn/kb/cve_2015_8241.rb +32 -0
  24. data/lib/dawn/kb/cve_2015_8242.rb +32 -0
  25. data/lib/dawn/kb/cve_2015_8317.rb +32 -0
  26. data/lib/dawn/kb/cve_2016_0751.rb +30 -0
  27. data/lib/dawn/kb/cve_2016_0752.rb +35 -0
  28. data/lib/dawn/kb/cve_2016_0753.rb +31 -0
  29. data/lib/dawn/kb/version_check.rb +61 -29
  30. data/lib/dawn/knowledge_base.rb +39 -1
  31. data/lib/dawn/reporter.rb +17 -8
  32. data/lib/dawn/version.rb +4 -4
  33. data/spec/lib/dawn/codesake_knowledgebase_spec.rb +90 -0
  34. data/spec/lib/kb/codesake_version_check_spec.rb +2 -2
  35. data/spec/lib/kb/cve_2015_5312_spec.rb +31 -0
  36. data/spec/lib/kb/cve_2015_7497_spec.rb +31 -0
  37. data/spec/lib/kb/cve_2015_7498_spec.rb +31 -0
  38. data/spec/lib/kb/cve_2015_7499_spec.rb +31 -0
  39. data/spec/lib/kb/cve_2015_7500_spec.rb +31 -0
  40. data/spec/lib/kb/cve_2015_7519_spec.rb +23 -0
  41. data/spec/lib/kb/cve_2015_7541_spec.rb +15 -0
  42. data/spec/lib/kb/cve_2015_7576_spec.rb +51 -0
  43. data/spec/lib/kb/cve_2015_7577_spec.rb +51 -0
  44. data/spec/lib/kb/cve_2015_7578_spec.rb +15 -0
  45. data/spec/lib/kb/cve_2015_7579_spec.rb +23 -0
  46. data/spec/lib/kb/cve_2015_7581_spec.rb +51 -0
  47. data/spec/lib/kb/cve_2015_8241_spec.rb +31 -0
  48. data/spec/lib/kb/cve_2015_8242_spec.rb +31 -0
  49. data/spec/lib/kb/cve_2015_8317_spec.rb +31 -0
  50. data/spec/lib/kb/cve_2016_0751_spec.rb +51 -0
  51. data/spec/lib/kb/cve_2016_0752_spec.rb +51 -0
  52. data/spec/lib/kb/cve_2016_0753_spec.rb +51 -0
  53. metadata +57 -2
  54. metadata.gz.sig +0 -0
@@ -0,0 +1,32 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-01-29
4
+ class CVE_2015_7577
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "There is a vulnerability in how the nested attributes feature in Active Record handles updates in combination with destroy flags when destroying records is disabled."
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-7577",
13
+ :cve=>"2015-7577",
14
+ :osvdb=>"",
15
+ :cvss=>"",
16
+ :release_date => Date.new(2016, 1, 26),
17
+ :cwe=>"",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade activerecord gem to version 3.2.22.1, 4.1.14.1, 4.2.5.1, 5.0.0.beta1.1 or later.",
23
+ :aux_links=>["http://securitytracker.com/id/1034816"]
24
+ })
25
+ self.save_minor=true
26
+ self.save_major=true
27
+ self.safe_dependencies = [{:name=>"activerecord", :version=>['3.2.22.1', '4.1.14.1', '4.2.5.1', '5.0.0.beta1.1']}]
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-01
4
+ class CVE_2015_7578
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "There is a possible XSS vulnerability in rails-html-sanitizer. Certain attributes are not removed from tags when they are sanitized, and these attributes can lead to an XSS attack on target applications."
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-7578",
13
+ :cve=>"2015-7578",
14
+ :osvdb=>"",
15
+ :cvss=>"",
16
+ :release_date => Date.new(2016, 1, 26),
17
+ :cwe=>"",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade rails-html-sanitizer gem to version 1.0.3 or later.",
23
+ :aux_links=>["http://securitytracker.com/id/1034816"]
24
+ })
25
+ self.safe_dependencies = [{:name=>"rails-html-sanitizer", :version=>['1.0.3']}]
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,30 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-01-31
4
+ class CVE_2015_7579
5
+ include DependencyCheck
6
+
7
+ def initialize
8
+ message = "There is a XSS vulnerability in Rails::Html::FullSanitizer used by Action View's strip_tags. Due to the way that Rails::Html::FullSanitizer is implemented, if an attacker passes an already escaped HTML entity to the input of Action View's strip_tags these entities will be unescaped what may cause a XSS attack if used in combination with raw or html_safe."
9
+ super({
10
+ :title=>title,
11
+ :name=> "CVE-2015-7579",
12
+ :cve=>"2015-7579",
13
+ :osvdb=>"",
14
+ :cvss=>"",
15
+ :release_date => Date.new(2016, 1, 26),
16
+ :cwe=>"",
17
+ :owasp=>"A9",
18
+ :applies=>["rails", "sinatra", "padrino"],
19
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
20
+ :message=>message,
21
+ :mitigation=>"Please upgrade rails-html-sanitizer to version 1.0.3 or later.",
22
+ :aux_links=>["http://securitytracker.com/id/1034816"]
23
+ })
24
+ self.safe_dependencies = [{:name=>"rails-html-sanitizer", :version=>['1.0.3']}]
25
+ self.not_affected = {:name=>"rails-html-sanitizer", :version=>['1.0.0', '1.0.1']}
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,33 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-01
4
+ class CVE_2015_7581
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "There is an object leak vulnerability for wildcard controllers in Action Pack. Users that have a route that contains the string \":controller\" are susceptible to objects being leaked globally which can lead to unbounded memory growth. "
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-7581",
13
+ :cve=>"2015-7581",
14
+ :osvdb=>"",
15
+ :cvss=>"",
16
+ :release_date => Date.new(2016, 1, 26),
17
+ :cwe=>"",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade actionpack gem to version 3.2.22.1, 4.1.14.1, 4.2.5.1, 5.0.0.beta1.1 or later.",
23
+ :aux_links=>["http://securitytracker.com/id/1034816"]
24
+ })
25
+ self.save_minor=true
26
+ self.save_major=true
27
+ self.safe_dependencies = [{:name=>"actionpack", :version=>['3.2.22.1', '4.1.14.1', '4.2.5.1', '5.0.0.beta1.1']}]
28
+
29
+
30
+ end
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,32 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-02
4
+ class CVE_2015_8241
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message ="The xmlNextChar function in libxml2 2.9.2 does not properly check the state, which allows context-dependent attackers to cause a denial of service (heap-based buffer over-read and application crash) or obtain sensitive information via crafted XML data."
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-8241",
13
+ :cve=>"2015-8241",
14
+ :osvdb=>"",
15
+ :cvss=>"AV:N/AC:L/Au:N/C:P/I:N/A:P",
16
+ :release_date => Date.new(2015, 12, 15),
17
+ :cwe=>"119",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade nokogiri gem to version 1.6.7.1 or later.",
23
+ :aux_links=>["https://groups.google.com/forum/#!topic/ruby-security-ann/aSbgDiwb24s"]
24
+ })
25
+
26
+ self.safe_dependencies = [{:name=>"nokogiri", :version=>['1.6.7.1']}]
27
+ self.not_affected = {:name=>"nokogiri", :version=>['1.5.x', '1.4.x', '1.3.x', '1.1.x', '1.0.x', '0.x.x']}
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-02
4
+ class CVE_2015_8242
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "The xmlSAX2TextNode function in SAX2.c in the push interface in the HTML parser in libxml2 before 2.9.3 allows context-dependent attackers to cause a denial of service (stack-based buffer over-read and application crash) or obtain sensitive information via crafted XML data."
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-8242",
13
+ :cve=>"2015-8242",
14
+ :osvdb=>"",
15
+ :cvss=>"AV:N/AC:M/Au:N/C:P/I:N/A:P",
16
+ :release_date => Date.new(2015, 12, 15),
17
+ :cwe=>"119",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade nokogiri gem to version 1.6.7.1 or later.",
23
+ :aux_links=>["https://groups.google.com/forum/#!topic/ruby-security-ann/aSbgDiwb24s"]
24
+ })
25
+
26
+ self.safe_dependencies = [{:name=>"nokogiri", :version=>['1.6.7.1']}]
27
+ self.not_affected = {:name=>"nokogiri", :version=>['1.5.x', '1.4.x', '1.3.x', '1.1.x', '1.0.x', '0.x.x']}
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,32 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-02
4
+ class CVE_2015_8317
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "The xmlParseXMLDecl function in parser.c in libxml2 before 2.9.3 allows context-dependent attackers to obtain sensitive information via an (1) unterminated encoding value or (2) incomplete XML declaration in XML data, which triggers an out-of-bounds heap read"
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2015-8317",
13
+ :cve=>"2015-8317",
14
+ :osvdb=>"",
15
+ :cvss=>"AV:N/AC:L/Au:N/C:P/I:N/A:N",
16
+ :release_date => Date.new(2015, 12, 15),
17
+ :cwe=>"119",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade nokogiri gem to version 1.6.7.1 or later.",
23
+ :aux_links=>["https://groups.google.com/forum/#!topic/ruby-security-ann/aSbgDiwb24s"]
24
+ })
25
+
26
+ self.safe_dependencies = [{:name=>"nokogiri", :version=>['1.6.7.1']}]
27
+ self.not_affected = {:name=>"nokogiri", :version=>['1.5.x', '1.4.x', '1.3.x', '1.1.x', '1.0.x', '0.x.x']}
28
+
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,30 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-01-28
4
+ class CVE_2016_0751
5
+ # Include the testing skeleton for this CVE
6
+ include DependencyCheck
7
+
8
+ def initialize
9
+ message = "There is a possible object leak which can lead to a denial of service vulnerability in Action Pack. A carefully crafted accept header can cause a global cache of mime types to grow indefinitely which can lead to a possible denial of service attack in Action Pack."
10
+ super({
11
+ :title=>title,
12
+ :name=> "CVE-2016-0751",
13
+ :cve=>"2016-0751",
14
+ :osvdb=>"",
15
+ :cvss=>"",
16
+ :release_date => Date.new(2016, 1, 26),
17
+ :cwe=>"",
18
+ :owasp=>"A9",
19
+ :applies=>["rails", "sinatra", "padrino"],
20
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
21
+ :message=>message,
22
+ :mitigation=>"Please upgrade actionpack gem to version 3.2.22.1, 4.1.14.1, 4.2.5.1, 5.0.0.beta1.1 or later.",
23
+ :aux_links=>["http://securitytracker.com/id/1034816"]
24
+ })
25
+ self.safe_dependencies = [{:name=>"actionpack", :version=>['3.2.22.1', '4.1.14.1', '4.2.5.1', '5.0.0.beta1.1']}]
26
+
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,35 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-01-31
4
+ class CVE_2016_0752
5
+ # Include the testing skeleton for this CVE
6
+ # include PatternMatchCheck
7
+ include DependencyCheck
8
+ # include RubyVersionCheck
9
+
10
+ def initialize
11
+ message = "There is a possible directory traversal and information leak vulnerability in Action View. Applications that pass unverified user input to the render method in a controller may be vulnerable to an information leak vulnerability."
12
+ super({
13
+ :title=>title,
14
+ :name=> "CVE-2016-0752",
15
+ :cve=>"2016-0752",
16
+ :osvdb=>"",
17
+ :cvss=>"",
18
+ :release_date => Date.new(2016, 1, 26),
19
+ :cwe=>"",
20
+ :owasp=>"A9",
21
+ :applies=>["rails", "sinatra", "padrino"],
22
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
23
+ :message=>message,
24
+ :mitigation=>"Please upgrade actionview gem to version 3.2.22.1, 4.1.14.1, 4.2.5.1, 5.0.0.beta1.1 or later.",
25
+ :aux_links=>["http://securitytracker.com/id/1034816"]
26
+ })
27
+ self.save_minor=true
28
+ self.save_major=true
29
+ self.safe_dependencies = [{:name=>"actionview", :version=>['3.2.22.1', '4.1.14.1', '4.2.5.1', '5.0.0.beta1.1']}]
30
+
31
+
32
+ end
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,31 @@
1
+ module Dawn
2
+ module Kb
3
+ # Automatically created with rake on 2016-02-01
4
+ class CVE_2016_0753
5
+ include DependencyCheck
6
+
7
+ def initialize
8
+ message = "There is a possible input validation circumvention vulnerability in Active Model. Code that uses Active Model based models (including Active Record models) and does not validate user input before passing it to the model can be subject to an attack where specially crafted input will cause the model to skip validations."
9
+ super({
10
+ :title=>title,
11
+ :name=> "CVE-2016-0753",
12
+ :cve=>"2016-0753",
13
+ :osvdb=>"",
14
+ :cvss=>"",
15
+ :release_date => Date.new(2016, 1, 26),
16
+ :cwe=>"",
17
+ :owasp=>"A9",
18
+ :applies=>["rails", "sinatra", "padrino"],
19
+ :kind=>Dawn::KnowledgeBase::DEPENDENCY_CHECK,
20
+ :message=>message,
21
+ :mitigation=>"Please upgrade activemodel gem to version 3.2.22.1, 4.1.14.1, 4.2.5.1, 5.0.0.beta1.1 or later.",
22
+ :aux_links=>["http://securitytracker.com/id/1034816"]
23
+ })
24
+ self.save_minor=true
25
+ self.save_major=true
26
+ self.safe_dependencies = [{:name=>"activemodel", :version=>['3.2.22.1', '4.1.14.1', '4.2.5.1', '5.0.0.beta1.1']}]
27
+
28
+ end
29
+ end
30
+ end
31
+ end
@@ -42,6 +42,7 @@ module Dawn
42
42
  return debug_me_and_return_false("detected version #{@detected} is higher than all version marked safe") if is_detected_highest?
43
43
 
44
44
  @safe.sort.each do |s|
45
+ debug_me "vuln?: evaluating #{@detected} against save version: #{s}"
45
46
 
46
47
  @save_minor_fix = save_minor_fix
47
48
  @save_major_fix = save_major_fix
@@ -49,7 +50,7 @@ module Dawn
49
50
 
50
51
  vuln = is_vulnerable_version?(s, @detected)
51
52
 
52
- debug_me "VULN=#{vuln} SAVE_MINOR=#{@save_minor_fix} SAVE_MAJOR=#{@save_major_fix}"
53
+ debug_me "DETECTED #{@detected} is marked VULN=#{vuln} against #{s} ( SAVE_MINOR_FIX=#{@save_minor_fix} SAVE_MAJOR_FIX=#{@save_major_fix})"
53
54
  return true if vuln
54
55
  end
55
56
 
@@ -102,6 +103,10 @@ module Dawn
102
103
  # patchlevel is 0 for sake of comparison.
103
104
  aa[:version] << 0 if aa[:version].count == 2
104
105
  ba[:version] << 0 if ba[:version].count == 2
106
+
107
+ # Handling a = '1.2.3.4' and b = '1.2.3'
108
+ ba[:version] << 0 if aa[:version].count == 4 and ba[:version].count == 3
109
+
105
110
  ver = true if aa[:version][0] > ba[:version][0]
106
111
  ver = true if aa[:version][0] == ba[:version][0] && aa[:version][1] > ba[:version][1]
107
112
  ver = true if aa[:version].count == 3 && ba[:version].count == 3 && aa[:version][0] == ba[:version][0] && aa[:version][1] == ba[:version][1] && aa[:version][2] > ba[:version][2]
@@ -164,9 +169,12 @@ module Dawn
164
169
  dva = version_string_to_array(@detected)[:version]
165
170
  @safe.sort.each do |s|
166
171
  sva = version_string_to_array(s)[:version]
167
- debug_me("#SVA=#{sva};DVA=#{dva};SM=#{is_same_major?(sva, dva)};sm=#{is_same_minor?(sva, dva)}; ( dva[2] >= sva[2] )=#{(dva[2] >= sva[2])}")
168
- return true if is_same_major?(sva, dva) && is_same_minor?(sva, dva) && dva[2] >= sva[2] && hm
169
- return true if is_same_major?(sva, dva) && hm
172
+ sM = is_same_major?(sva, dva)
173
+ sm = is_same_minor?(sva, dva)
174
+ debug_me("save_minor_fix: SVA=#{sva};DVA=#{dva};SAME_MAJOR? = #{sM}; SAME_MINOR?=#{sm}; ( dva[2] >= sva[2] )=#{(dva[2] >= sva[2])}")
175
+ debug_me("save_minor_fix: is_there_higher_minor_version? = #{hm}")
176
+ return true if sM and sm and dva[2] >= sva[2] && hm
177
+ return true if sM and hm
170
178
  end
171
179
  return false
172
180
  end
@@ -204,6 +212,8 @@ module Dawn
204
212
  return (safe_version[2] > detected_version[2])
205
213
  end
206
214
  def is_vulnerable_aux_patch?(safe_version, detected_version)
215
+ debug_me "is_vulnerable_aux_patch?: SV[3]=#{safe_version[3]}, DV[3]=#{detected_version[3]}"
216
+ return true if detected_version[3].nil? and ! safe_version[3].nil?
207
217
  return false if safe_version[3].nil? || detected_version[3].nil?
208
218
  return (safe_version[3] > detected_version[3])
209
219
  end
@@ -221,7 +231,7 @@ module Dawn
221
231
  # safe version is kinda more complex e.g. 2.3.2
222
232
  # in this case we return the version is vulnerable if the
223
233
  # detected_version major is less or equal the safe one.
224
- return (safe_version[0] <= detected_version[0])
234
+ return (safe_version[0] < detected_version[0])
225
235
  end
226
236
 
227
237
  # support for x as safe minor version
@@ -232,7 +242,7 @@ module Dawn
232
242
  return false if safe_version[1] <= detected_version[1]
233
243
  end
234
244
 
235
- def is_same_version?(safe_version_array, detected_version_array)
245
+ def is_same_version?(safe_version_array, detected_version_array, limit=false)
236
246
  ret = false
237
247
 
238
248
  ret = true if (safe_version_array[0] == detected_version_array[0]) if (safe_version_array[1] == 'x')
@@ -240,6 +250,15 @@ module Dawn
240
250
  ret = true if (safe_version_array[0] == detected_version_array[0]) && (safe_version_array[1] == detected_version_array[1]) && (safe_version_array[2] == detected_version_array[2]) && (safe_version_array.count == 3) && (detected_version_array.count == 3)
241
251
  ret = true if (safe_version_array[0] == detected_version_array[0]) && (safe_version_array[1] == detected_version_array[1]) && (safe_version_array[2] == detected_version_array[2]) && (safe_version_array[3] == detected_version_array[3]) && (safe_version_array.count == 4) && (detected_version_array.count == 4)
242
252
 
253
+ if limit
254
+ # this if handles comparison limited to first 3 items in version arrays
255
+ # eg. in case of a beta release, the array is [5,0,0,1] meaning
256
+ # 5.0.0.beta1. Of course it must be handled in a different way than
257
+ # 5.0.0.1 release that it will result in the same array
258
+ debug_me "is_same_version? with limit=TRUE"
259
+ ret = true if (safe_version_array[0] == detected_version_array[0]) && (safe_version_array[1] == detected_version_array[1]) && (safe_version_array[2] == detected_version_array[2])
260
+ end
261
+
243
262
  debug_me "is_same_version? SVA=#{safe_version_array} DVA=#{detected_version_array} RET=#{ret}"
244
263
 
245
264
  return ret
@@ -250,16 +269,19 @@ module Dawn
250
269
  #########################
251
270
 
252
271
  def is_beta_check?(safe_version_beta, detected_version_beta)
253
- ( safe_version_beta != 0 || detected_version_beta != 0)
272
+ ( safe_version_beta != -1 || detected_version_beta != -1)
254
273
  end
255
274
 
256
275
  def is_vulnerable_beta?(safe_version_beta, detected_version_beta)
257
276
  # if the safe_version_beta is 0 then the detected_version_beta is
258
277
  # vulnerable by design, since the safe version is a stable and we
259
278
  # detected a beta.
260
- return true if safe_version_beta == 0 && detected_version_beta != 0
261
- return false if safe_version_beta <= detected_version_beta
262
- return true if safe_version_beta > detected_version_beta
279
+ debug_me("is_vulnerable_beta?: safe_version_beta=#{safe_version_beta} - detected_version_beta=#{detected_version_beta}")
280
+ return debug_me_and_return_false("is_vulnerable_beta? = FALSE") if safe_version_beta != -1 and detected_version_beta == -1
281
+ return debug_me_and_return_true("is_vulnerable_beta? = TRUE") if safe_version_beta == -1 and detected_version_beta != -1
282
+ return debug_me_and_return_true("is_vulnerable_beta? = TRUE") if safe_version_beta == 0 && detected_version_beta != -1
283
+ return debug_me_and_return_false("is_vulnerable_beta? = FALSE") if safe_version_beta <= detected_version_beta
284
+ return debug_me_and_return_true("is_vulnerable_beta? = TRUE") if safe_version_beta > detected_version_beta
263
285
 
264
286
  # fallback
265
287
  return false
@@ -271,7 +293,7 @@ module Dawn
271
293
  #########################
272
294
 
273
295
  def is_rc_check?(safe_version_rc, detected_version_rc)
274
- ( safe_version_rc != 0 || detected_version_rc != 0)
296
+ ( safe_version_rc != -1 || detected_version_rc != -1 )
275
297
  end
276
298
 
277
299
  def is_vulnerable_rc?(safe_version_rc, detected_version_rc)
@@ -279,10 +301,13 @@ module Dawn
279
301
  # vulnerable by design, since the safe version is a stable and we
280
302
  # detected a rc.
281
303
  debug_me "entering is_vulnerable_rc?: s=#{safe_version_rc}, d=#{detected_version_rc}"
282
- return true if safe_version_rc == 0 && detected_version_rc != 0
283
- return false if safe_version_rc != 0 && detected_version_rc == 0
284
- return false if safe_version_rc <= detected_version_rc
285
- return true if safe_version_rc > detected_version_rc
304
+ return debug_me_and_return_false("is_vulnerable_rc? = FALSE") if detected_version_rc == -1
305
+
306
+ return debug_me_and_return_false("is_vulnerable_rc? = FALSE") if safe_version_rc != -1 and detected_version_rc == -1
307
+ return debug_me_and_return_true("is_vulnerable_rc? = TRUE") if safe_version_rc == -1 and detected_version_rc != -1
308
+ return debug_me_and_return_true("is_vulnerable_rc? = TRUE") if safe_version_rc == 0 && detected_version_rc != -1
309
+ return debug_me_and_return_false("is_vulnerable_rc? = FALSE") if safe_version_rc <= detected_version_rc
310
+ return debug_me_and_return_true("is_vulnerable_rc? = TRUE") if safe_version_rc > detected_version_rc
286
311
 
287
312
  # fallback
288
313
  return false
@@ -294,16 +319,19 @@ module Dawn
294
319
  #########################
295
320
 
296
321
  def is_pre_check?(safe_version_pre, detected_version_pre)
297
- ( safe_version_pre != 0 || detected_version_pre != 0)
322
+ ( safe_version_pre != -1 || detected_version_pre != -1 )
298
323
  end
299
324
 
300
325
  def is_vulnerable_pre?(safe_version_pre, detected_version_pre)
301
326
  # if the safe_version_pre is 0 then the detected_version_pre is
302
327
  # vulnerable by design, since the safe version is a stable and we
303
328
  # detected a pre.
304
- return true if safe_version_pre == 0 && detected_version_pre != 0
305
- return false if safe_version_pre <= detected_version_pre
306
- return true if safe_version_pre > detected_version_pre
329
+ return debug_me_and_return_false("is_vulnerable_pre? = FALSE") if safe_version_pre != -1 and detected_version_pre == -1
330
+ return debug_me_and_return_true("is_vulnerable_pre? = TRUE") if safe_version_pre == -1 and detected_version_pre != -1
331
+ return debug_me_and_return_true("is_vulnerable_pre? = TRUE") if safe_version_pre == 0 && detected_version_pre != -1
332
+ return debug_me_and_return_false("is_vulnerable_pre? = FALSE") if safe_version_pre <= detected_version_pre
333
+ return debug_me_and_return_true("is_vulnerable_pre? = TRUE") if safe_version_pre > detected_version_pre
334
+
307
335
 
308
336
  # fallback
309
337
  return false
@@ -312,6 +340,8 @@ module Dawn
312
340
  def is_vulnerable_version?(safe_version, detected_version)
313
341
  sva = version_string_to_array(safe_version)
314
342
  dva = version_string_to_array(detected_version)
343
+ debug_me("SVA=#{sva.inspect}")
344
+ debug_me("DVA=#{dva.inspect}")
315
345
  safe_version_array = sva[:version]
316
346
  detected_version_array = dva[:version]
317
347
 
@@ -323,11 +353,13 @@ module Dawn
323
353
  patch = is_vulnerable_patch?(safe_version_array, detected_version_array)
324
354
  aux_patch = is_vulnerable_aux_patch?(safe_version_array, detected_version_array)
325
355
 
326
- debug_me "is_vulnerable_version? S=#{safe_version},D=#{detected_version} -> MAJOR=#{major} MINOR=#{minor} PATCH=#{patch} AUX_PATCH=#{aux_patch} SAVE_MINOR=#{@save_minor_fix} SAVE_MAJOR=#{@save_major_fix}"
356
+ debug_me "is_vulnerable_version? SAVE_VERSION=#{safe_version},DETECTED=#{detected_version} -> IS_VULN_MAJOR?=#{major} IS_VULN_MINOR?=#{minor} IS_VULN_PATCH?=#{patch} IS_VULN_AUX_PATCH=#{aux_patch} SAVE_MINOR_FIX=#{@save_minor_fix} SAVE_MAJOR_FIX=#{@save_major_fix}"
357
+
358
+ return debug_me_and_return_false("#{detected_version} doesn't have a vulnerable MAJOR number") if is_higher_major?(detected_version, safe_version) #and minor and patch
327
359
 
328
- return is_vulnerable_beta?(sva[:beta], dva[:beta]) if is_same_version?(safe_version_array, detected_version_array) && is_beta_check?(sva[:beta], dva[:beta])
329
- return is_vulnerable_rc?(sva[:rc], dva[:rc]) if is_same_version?(safe_version_array, detected_version_array) && is_rc_check?(sva[:rc], dva[:rc])
330
- return is_vulnerable_pre?(sva[:pre], dva[:pre]) if is_same_version?(safe_version_array, detected_version_array) && is_pre_check?(sva[:pre], dva[:pre])
360
+ return is_vulnerable_beta?(sva[:beta], dva[:beta]) if is_same_version?(safe_version_array, detected_version_array, true) && is_beta_check?(sva[:beta], dva[:beta])
361
+ return is_vulnerable_rc?(sva[:rc], dva[:rc]) if is_same_version?(safe_version_array, detected_version_array, true) && is_rc_check?(sva[:rc], dva[:rc])
362
+ return is_vulnerable_pre?(sva[:pre], dva[:pre]) if is_same_version?(safe_version_array, detected_version_array, true) && is_pre_check?(sva[:pre], dva[:pre])
331
363
 
332
364
  # we have a non vulnerable major, but the minor is and there is an higher version in array
333
365
  # eg. we detected v1.3.2, safe version is 1.3.3 and there is also a safe 2.x.x
@@ -399,17 +431,17 @@ module Dawn
399
431
  # I can't use this nice onliner... stays here until I finish writing new code.
400
432
  # return string.split(".").map! { |n| (n=='x')? n : n.to_i }
401
433
  ver = []
402
- beta = 0
403
- rc = 0
404
- pre = 0
434
+ beta = -1
435
+ rc = -1
436
+ pre = -1
405
437
 
406
438
  string.split(".").each do |x|
407
439
  ver << x.to_i unless x == 'x' || x.start_with?('beta') || x.start_with?('rc') || x.start_with?('pre')
408
440
  ver << x if x == 'x'
409
441
 
410
- beta = x.split("beta")[1].to_i if x.class == String && x.start_with?('beta') && beta == 0
411
- rc = x.split("rc")[1].to_i if x.class == String && x.start_with?('rc') && rc == 0
412
- pre = x.split("pre")[1].to_i if x.class == String && x.start_with?('pre') && pre == 0
442
+ beta = x.split("beta")[1].to_i if x.class == String && x.start_with?('beta') && beta == -1
443
+ rc = x.split("rc")[1].to_i if x.class == String && x.start_with?('rc') && rc == -1
444
+ pre = x.split("pre")[1].to_i if x.class == String && x.start_with?('pre') && pre == -1
413
445
 
414
446
  end
415
447
  {:version=>ver, :beta=>beta, :rc=>rc, :pre=>pre}