cvss-suite 1.2.0 → 1.2.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -14,44 +14,46 @@ require_relative '../cvss_metric'
14
14
  ##
15
15
  # This class represents a CVSS Temporal metric in version 3.1.
16
16
 
17
- class Cvss31Temporal < CvssMetric
18
-
19
- ##
20
- # Property of this metric
21
-
22
- attr_reader :exploit_code_maturity, :remediation_level, :report_confidence
23
-
24
- ##
25
- # Returns score of this metric
26
-
27
- def score
28
- return 1.0 unless valid?
29
- @exploit_code_maturity.score * @remediation_level.score * @report_confidence.score
30
- end
31
-
32
- private
33
-
34
- def init_properties
35
- @properties.push(@exploit_code_maturity =
36
- CvssProperty.new(name: 'Exploit Code Maturity', abbreviation: 'E', position: [8],
37
- choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
38
- { name: 'Unproven', abbreviation: 'U', weight: 0.91 },
39
- { name: 'Proof-of-Concept', abbreviation: 'P', weight: 0.94 },
40
- { name: 'Functional', abbreviation: 'F', weight: 0.97 },
41
- { name: 'High', abbreviation: 'H', weight: 1.0 }]))
42
- @properties.push(@remediation_level =
43
- CvssProperty.new(name: 'Remediation Level', abbreviation: 'RL', position: [9],
44
- choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
45
- { name: 'Official Fix', abbreviation: 'O', weight: 0.95 },
46
- { name: 'Temporary Fix', abbreviation: 'T', weight: 0.96 },
47
- { name: 'Workaround', abbreviation: 'W', weight: 0.97 },
48
- { name: 'Unavailable', abbreviation: 'U', weight: 1.0 }]))
49
-
50
- @properties.push(@report_confidence =
51
- CvssProperty.new(name: 'Report Confidence', abbreviation: 'RC', position: [10],
52
- choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
53
- { name: 'Unknown', abbreviation: 'U', weight: 0.92 },
54
- { name: 'Reasonable', abbreviation: 'R', weight: 0.96 },
55
- { name: 'Confirmed', abbreviation: 'C', weight: 1.0 }]))
17
+ module CvssSuite
18
+ class Cvss31Temporal < CvssMetric
19
+ ##
20
+ # Property of this metric
21
+
22
+ attr_reader :exploit_code_maturity, :remediation_level, :report_confidence
23
+
24
+ ##
25
+ # Returns score of this metric
26
+
27
+ def score
28
+ return 1.0 unless valid?
29
+
30
+ @exploit_code_maturity.score * @remediation_level.score * @report_confidence.score
31
+ end
32
+
33
+ private
34
+
35
+ def init_properties
36
+ @properties.push(@exploit_code_maturity =
37
+ CvssProperty.new(name: 'Exploit Code Maturity', abbreviation: 'E', position: [8],
38
+ choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
39
+ { name: 'Unproven', abbreviation: 'U', weight: 0.91 },
40
+ { name: 'Proof-of-Concept', abbreviation: 'P', weight: 0.94 },
41
+ { name: 'Functional', abbreviation: 'F', weight: 0.97 },
42
+ { name: 'High', abbreviation: 'H', weight: 1.0 }]))
43
+ @properties.push(@remediation_level =
44
+ CvssProperty.new(name: 'Remediation Level', abbreviation: 'RL', position: [9],
45
+ choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
46
+ { name: 'Official Fix', abbreviation: 'O', weight: 0.95 },
47
+ { name: 'Temporary Fix', abbreviation: 'T', weight: 0.96 },
48
+ { name: 'Workaround', abbreviation: 'W', weight: 0.97 },
49
+ { name: 'Unavailable', abbreviation: 'U', weight: 1.0 }]))
50
+
51
+ @properties.push(@report_confidence =
52
+ CvssProperty.new(name: 'Report Confidence', abbreviation: 'RC', position: [10],
53
+ choices: [{ name: 'Not Defined', abbreviation: 'X', weight: 1.0 },
54
+ { name: 'Unknown', abbreviation: 'U', weight: 0.92 },
55
+ { name: 'Reasonable', abbreviation: 'R', weight: 0.96 },
56
+ { name: 'Confirmed', abbreviation: 'C', weight: 1.0 }]))
57
+ end
56
58
  end
57
- end
59
+ end
@@ -11,43 +11,43 @@
11
11
  ##
12
12
  # This class represents any CVSS metric.
13
13
 
14
- class CvssMetric
15
-
16
- ##
17
- # Creates a new CVSS metric by +properties+
18
-
19
- def initialize(selected_properties)
20
- @properties = []
21
- init_properties
22
- extract_selected_choices_from selected_properties
23
- end
14
+ module CvssSuite
15
+ class CvssMetric
16
+ ##
17
+ # Creates a new CVSS metric by +properties+
18
+
19
+ def initialize(selected_properties)
20
+ @properties = []
21
+ init_properties
22
+ extract_selected_choices_from selected_properties
23
+ end
24
24
 
25
- ##
26
- # Returns if the metric is valid.
25
+ ##
26
+ # Returns if the metric is valid.
27
27
 
28
- def valid?
29
- @properties.each do |property|
30
- return false unless property.valid?
28
+ def valid?
29
+ @properties.each do |property|
30
+ return false unless property.valid?
31
+ end
32
+ true
31
33
  end
32
- true
33
- end
34
34
 
35
- ##
36
- # Returns number of properties for this metric.
35
+ ##
36
+ # Returns number of properties for this metric.
37
37
 
38
- def count
39
- @properties.count
40
- end
38
+ def count
39
+ @properties.count
40
+ end
41
41
 
42
- private
42
+ private
43
43
 
44
- def extract_selected_choices_from(selected_properties)
45
- selected_properties.each do |selected_property|
46
- property = @properties.detect {
47
- |p| p.abbreviation == selected_property[:name] && p.position.include?(selected_property[:position])
48
- }
49
- property.set_selected_choice selected_property[:selected] unless property.nil?
44
+ def extract_selected_choices_from(selected_properties)
45
+ selected_properties.each do |selected_property|
46
+ property = @properties.detect do |p|
47
+ p.abbreviation == selected_property[:name] && p.position.include?(selected_property[:position])
48
+ end
49
+ property.set_selected_choice selected_property[:selected] unless property.nil?
50
+ end
50
51
  end
51
52
  end
52
-
53
- end
53
+ end
@@ -11,75 +11,77 @@
11
11
  ##
12
12
  # This class represents a CVSS property of a CVSS metric.
13
13
 
14
- class CvssProperty
15
-
16
- ##
17
- # Creates a new CVSS property by a +property+.
18
- #
19
- # +Property+ needs to consist of a name, a abbreviation, the possible positions in the CVSS vector, a weight, and the
20
- # available choices for the property.
21
-
22
- def initialize(property)
23
- @property = property
24
- @property[:default_choice] ||= 'Not Available'
25
- end
14
+ module CvssSuite
15
+ class CvssProperty
16
+ ##
17
+ # Creates a new CVSS property by a +property+.
18
+ #
19
+ # +Property+ needs to consist of a name, a abbreviation,
20
+ # the possible positions in the CVSS vector, a weight, and the
21
+ # available choices for the property.
22
+
23
+ def initialize(property)
24
+ @property = property
25
+ @property[:default_choice] ||= 'Not Available'
26
+ end
26
27
 
27
- ##
28
- # Returns the full name of the property.
28
+ ##
29
+ # Returns the full name of the property.
29
30
 
30
- def name
31
- @property[:name]
32
- end
31
+ def name
32
+ @property[:name]
33
+ end
33
34
 
34
- ##
35
- # Returns the abbreviation of the property.
35
+ ##
36
+ # Returns the abbreviation of the property.
36
37
 
37
- def abbreviation
38
- @property[:abbreviation]
39
- end
38
+ def abbreviation
39
+ @property[:abbreviation]
40
+ end
40
41
 
41
- ##
42
- # Returns all available choices of the property.
42
+ ##
43
+ # Returns all available choices of the property.
43
44
 
44
- def choices
45
- @property[:choices]
46
- end
45
+ def choices
46
+ @property[:choices]
47
+ end
47
48
 
48
- ##
49
- # Returns the possible positions in the CVSS vector of the property.
49
+ ##
50
+ # Returns the possible positions in the CVSS vector of the property.
50
51
 
51
- def position
52
- @property[:position]
53
- end
52
+ def position
53
+ @property[:position]
54
+ end
54
55
 
55
- ##
56
- # Returns the selected choice of the property.
56
+ ##
57
+ # Returns the selected choice of the property.
57
58
 
58
- def selected_choice
59
- @selected_choice || @property[:default_choice]
60
- end
59
+ def selected_choice
60
+ @selected_choice || @property[:default_choice]
61
+ end
61
62
 
62
- ##
63
- # Returns true if the property is valid.
63
+ ##
64
+ # Returns true if the property is valid.
64
65
 
65
- def valid?
66
- !@selected_choice.nil?
67
- end
66
+ def valid?
67
+ !@selected_choice.nil?
68
+ end
68
69
 
69
- ##
70
- # Returns the score of the selected choice.
70
+ ##
71
+ # Returns the score of the selected choice.
71
72
 
72
- def score
73
- @selected_choice[:weight]
74
- end
73
+ def score
74
+ @selected_choice[:weight]
75
+ end
75
76
 
76
- ##
77
- # Sets the selected choice by a +choice+.
77
+ ##
78
+ # Sets the selected choice by a +choice+.
78
79
 
79
- def set_selected_choice(selected_choice)
80
- choices.each do |choice|
81
- choice[:selected] = selected_choice.eql?(choice[:abbreviation])
80
+ def set_selected_choice(selected_choice)
81
+ choices.each do |choice|
82
+ choice[:selected] = selected_choice.eql?(choice[:abbreviation])
83
+ end
84
+ @selected_choice = choices.detect { |choice| choice[:selected] }
82
85
  end
83
- @selected_choice = choices.detect { |choice| choice[:selected] }
84
86
  end
85
- end
87
+ end
@@ -0,0 +1,27 @@
1
+ # CVSS-Suite, a Ruby gem to manage the CVSS vector
2
+ #
3
+ # Copyright (c) Siemens AG, 2016
4
+ #
5
+ # Authors:
6
+ # Oliver Hambörger <oliver.hamboerger@siemens.com>
7
+ #
8
+ # This work is licensed under the terms of the MIT license.
9
+ # See the LICENSE.md file in the top-level directory.
10
+
11
+ module CvssSuite
12
+ ##
13
+ # This module includes methods which are used by the CVSS 3 classes.
14
+ module Cvss31Helper
15
+ ##
16
+ # Since CVSS 3 all float values are rounded up, therefore this method is used
17
+ # instead of the mathematically correct method round().
18
+ def self.round_up(float)
19
+ output = (float * 100_000).round
20
+ if (output % 10_000).zero?
21
+ output / 100_000.0
22
+ else
23
+ ((output / 10_000).floor + 1) / 10.0
24
+ end
25
+ end
26
+ end
27
+ end
@@ -11,19 +11,26 @@
11
11
  ##
12
12
  # This module includes methods which are used by the CVSS 3 classes.
13
13
 
14
- module Cvss3Helper
15
-
16
- ##
17
- # Since CVSS 3 the Privilege Required score depends on the selected choice of the Scope metric.
18
- # This method takes a +Privilege+ +Required+ and a +Scope+ metric and returns the newly calculated score.
14
+ module CvssSuite
15
+ module Cvss3Helper
16
+ ##
17
+ # Since CVSS 3 all float values are rounded up, therefore this method is used
18
+ # instead of the mathematically correct method round().
19
+ def self.round_up(float)
20
+ float.ceil(1).to_f
21
+ end
19
22
 
20
- def self.privileges_required_score(privileges_required, scope)
21
- changed = scope.selected_choice[:name] == 'Changed'
22
- privilege_score = privileges_required.score
23
- if changed
24
- privilege_score = 0.68 if privileges_required.selected_choice[:name] == 'Low'
25
- privilege_score = 0.50 if privileges_required.selected_choice[:name] == 'High'
23
+ ##
24
+ # Since CVSS 3 the Privilege Required score depends on the selected choice of the Scope metric.
25
+ # This method takes a +Privilege+ +Required+ and a +Scope+ metric and returns the newly calculated score.
26
+ def self.privileges_required_score(privileges_required, scope)
27
+ changed = scope.selected_choice[:name] == 'Changed'
28
+ privilege_score = privileges_required.score
29
+ if changed
30
+ privilege_score = 0.68 if privileges_required.selected_choice[:name] == 'Low'
31
+ privilege_score = 0.50 if privileges_required.selected_choice[:name] == 'High'
32
+ end
33
+ privilege_score
26
34
  end
27
- privilege_score
28
35
  end
29
- end
36
+ end
@@ -11,47 +11,46 @@
11
11
  # ##
12
12
  # # This class represents a invalid CVSS vector.
13
13
 
14
- class InvalidCvss < Cvss
14
+ module CvssSuite
15
+ class InvalidCvss < Cvss
16
+ ##
17
+ # Creates a new invalid CVSS vector.
15
18
 
16
- ##
17
- # Creates a new invalid CVSS vector.
19
+ def initialize; end
18
20
 
19
- def initialize
20
- end
21
+ ##
22
+ # Since this is an invalid CVSS vector, it always returns false.
21
23
 
22
- ##
23
- # Since this is an invalid CVSS vector, it always returns false.
24
+ def valid?
25
+ false
26
+ end
24
27
 
25
- def valid?
26
- false
27
- end
28
+ ##
29
+ # Since this is an invalid CVSS vector, it always throws an exception.
28
30
 
29
- ##
30
- # Since this is an invalid CVSS vector, it always throws an exception.
31
+ def version
32
+ check_validity
33
+ end
31
34
 
32
- def version
33
- check_validity
34
- end
35
+ ##
36
+ # Since this is an invalid CVSS vector, it always throws an exception.
35
37
 
36
- ##
37
- # Since this is an invalid CVSS vector, it always throws an exception.
38
+ def base_score
39
+ check_validity
40
+ end
38
41
 
39
- def base_score
40
- check_validity
41
- end
42
+ ##
43
+ # Since this is an invalid CVSS vector, it always throws an exception.
42
44
 
43
- ##
44
- # Since this is an invalid CVSS vector, it always throws an exception.
45
+ def temporal_score
46
+ check_validity
47
+ end
45
48
 
46
- def temporal_score
47
- check_validity
48
- end
49
-
50
- ##
51
- # Since this is an invalid CVSS vector, it always throws an exception.
49
+ ##
50
+ # Since this is an invalid CVSS vector, it always throws an exception.
52
51
 
53
- def environmental_score
54
- check_validity
52
+ def environmental_score
53
+ check_validity
54
+ end
55
55
  end
56
-
57
- end
56
+ end
@@ -9,5 +9,5 @@
9
9
  # See the LICENSE.md file in the top-level directory.
10
10
 
11
11
  module CvssSuite
12
- VERSION = "1.2.0"
12
+ VERSION = '1.2.1'
13
13
  end