cvss-suite 1.1.1 → 2.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (38) hide show
  1. checksums.yaml +5 -5
  2. data/.github/ISSUE_TEMPLATE/bug_report.md +21 -0
  3. data/.github/ISSUE_TEMPLATE/custom.md +7 -0
  4. data/.github/ISSUE_TEMPLATE/feature_request.md +17 -0
  5. data/.github/workflows/rspec.yml +23 -0
  6. data/.github/workflows/rubocop.yml +21 -0
  7. data/.gitignore +1 -0
  8. data/.rubocop.yml +45 -1
  9. data/.rubocop_todo.yml +59 -0
  10. data/CHANGES.md +61 -1
  11. data/PULL_REQUEST_TEMPLATE.md +24 -0
  12. data/README.md +43 -16
  13. data/_config.yml +1 -0
  14. data/bin/console +3 -3
  15. data/cvss_suite.gemspec +14 -13
  16. data/lib/cvss_suite.rb +13 -11
  17. data/lib/cvss_suite/cvss.rb +85 -73
  18. data/lib/cvss_suite/cvss2/cvss2.rb +39 -36
  19. data/lib/cvss_suite/cvss2/cvss2_base.rb +69 -75
  20. data/lib/cvss_suite/cvss2/cvss2_environmental.rb +52 -54
  21. data/lib/cvss_suite/cvss2/cvss2_temporal.rb +40 -41
  22. data/lib/cvss_suite/cvss3/cvss3.rb +39 -36
  23. data/lib/cvss_suite/cvss3/cvss3_base.rb +72 -75
  24. data/lib/cvss_suite/cvss3/cvss3_environmental.rb +159 -109
  25. data/lib/cvss_suite/cvss3/cvss3_temporal.rb +41 -42
  26. data/lib/cvss_suite/cvss31/cvss31.rb +60 -0
  27. data/lib/cvss_suite/cvss31/cvss31_base.rb +93 -0
  28. data/lib/cvss_suite/cvss31/cvss31_environmental.rb +194 -0
  29. data/lib/cvss_suite/cvss31/cvss31_temporal.rb +56 -0
  30. data/lib/cvss_suite/cvss_metric.rb +31 -35
  31. data/lib/cvss_suite/cvss_property.rb +57 -56
  32. data/lib/cvss_suite/helpers/cvss31_helper.rb +27 -0
  33. data/lib/cvss_suite/helpers/cvss3_helper.rb +21 -15
  34. data/lib/cvss_suite/invalid_cvss.rb +37 -45
  35. data/lib/cvss_suite/version.rb +2 -2
  36. metadata +21 -25
  37. data/.travis.yml +0 -4
  38. data/lib/cvss_suite/helpers/extensions.rb +0 -32
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
- SHA1:
3
- metadata.gz: 67b9524624c103f1410747cc5601fc6c51bdaeb3
4
- data.tar.gz: 92eb12a5d7266cdfcef91ee3d6090d59d493b8c8
2
+ SHA256:
3
+ metadata.gz: d4f32e67e6919d58fbd35bc9af64a0af838e484ecfc28d17f83ebc623df9cff5
4
+ data.tar.gz: fc758c191bfbbd12e24e15d8b2d4fe1e012e4597ea0fcc28972bbe4bb9d8f66d
5
5
  SHA512:
6
- metadata.gz: c575ffb21ee0c1742911641921e3d661bbe421e77cb073080281b98bc2133fe8aaab4ac5ab521455a9253794a91a58d71ebdeddaa7ce70127e718856f0cfa0b3
7
- data.tar.gz: af23d1944795b0eb5eb4172ad742199f9f8aefc22cf17563c61e22ac6883848aa38d7564896ed84d2360e4becec28ca9abe84c71cb714ac933e511e2e302c392
6
+ metadata.gz: e6af1a297fb42858352914040f4d7d75923e3d6e88ed0ae14b85243252d58d169a8eddc900fd0ad1f5506a86bfc24f576e8d321fd7f2b4a01afa040ac9861ebc
7
+ data.tar.gz: fcb7590bd3fbe1eef4c8d5ea4f72e1cf04db96005034f74f9e764cb3853f1e0d39d73a6ba3c77416be69853f01a3c248d880997ae474534f5c8f2e7724a86ff6
@@ -0,0 +1,21 @@
1
+ ---
2
+ name: Bug report
3
+ about: Create a report to help us improve
4
+
5
+ ---
6
+
7
+ ### Subject of the issue
8
+ Describe your issue here.
9
+
10
+ ### Your environment
11
+ * version of cvss-suite gem
12
+ * version of ruby
13
+
14
+ ### Steps to reproduce
15
+ Tell us how to reproduce this issue. Please provide a working demo.
16
+
17
+ ### Expected behaviour
18
+ Tell us what should happen.
19
+
20
+ ### Actual behaviour
21
+ Tell us what happens instead.
@@ -0,0 +1,7 @@
1
+ ---
2
+ name: Custom issue template
3
+ about: Describe this issue template's purpose here.
4
+
5
+ ---
6
+
7
+
@@ -0,0 +1,17 @@
1
+ ---
2
+ name: Feature request
3
+ about: Suggest an idea for this project
4
+
5
+ ---
6
+
7
+ **Is your feature request related to a problem? Please describe.**
8
+ A clear and concise description of what the problem is. Ex. I'm always frustrated when [...]
9
+
10
+ **Describe the solution you'd like**
11
+ A clear and concise description of what you want to happen.
12
+
13
+ **Describe alternatives you've considered**
14
+ A clear and concise description of any alternative solutions or features you've considered.
15
+
16
+ **Additional context**
17
+ Add any other context or screenshots about the feature request here.
@@ -0,0 +1,23 @@
1
+ name: RSpec
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+ strategy:
10
+ matrix:
11
+ ruby: [ '2.4', '2.5', '2.6', '2.7' ]
12
+ steps:
13
+ - uses: actions/checkout@v2
14
+ - name: Set up ${{ matrix.ruby }}
15
+ uses: actions/setup-ruby@v1
16
+ with:
17
+ ruby-version: ${{ matrix.ruby }}
18
+ - name: Install gems
19
+ run: |
20
+ gem install bundler -v ">= 1.10"
21
+ bundle install --jobs 4 --retry 3
22
+ - name: Run tests
23
+ run: bundle exec rspec spec
@@ -0,0 +1,21 @@
1
+ name: Rubocop
2
+
3
+ on: [push,pull_request]
4
+
5
+ jobs:
6
+ build:
7
+
8
+ runs-on: ubuntu-latest
9
+
10
+ steps:
11
+ - uses: actions/checkout@v2
12
+ - name: Set up Ruby 2.7
13
+ uses: actions/setup-ruby@v1
14
+ with:
15
+ ruby-version: 2.7
16
+ - name: Install gems
17
+ run: |
18
+ gem install bundler -v ">= 1.10"
19
+ gem install rubocop
20
+ - name: Run checks
21
+ run: rubocop -F --fail-level C -f s
data/.gitignore CHANGED
@@ -10,3 +10,4 @@
10
10
  /tmp/
11
11
  .idea/
12
12
  /*.gem
13
+ .ruby-version
@@ -1,2 +1,46 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ AllCops:
4
+ TargetRubyVersion: 2.4
5
+
1
6
  Metrics/LineLength:
2
- Max: 120
7
+ Max: 120
8
+ Exclude:
9
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
10
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
11
+
12
+ Metrics/ClassLength:
13
+ Exclude:
14
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
15
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
16
+
17
+ Metrics/MethodLength:
18
+ Exclude:
19
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
20
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
21
+
22
+ Metrics/BlockLength:
23
+ Exclude:
24
+ - 'spec/cvss3/cvss3_spec.rb'
25
+ - 'spec/cvss31/cvss31_spec.rb'
26
+
27
+ Style/IfUnlessModifier:
28
+ Exclude:
29
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
30
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
31
+
32
+ Style/GuardClause:
33
+ Exclude:
34
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
35
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
36
+
37
+ Style/ConditionalAssignment:
38
+ Exclude:
39
+ - 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
40
+ - 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
41
+
42
+ Style/FrozenStringLiteralComment:
43
+ Enabled: false
44
+
45
+ Style/AsciiComments:
46
+ Enabled: false
@@ -0,0 +1,59 @@
1
+ # This configuration was generated by
2
+ # `rubocop --auto-gen-config`
3
+ # on 2020-05-05 17:47:10 +0200 using RuboCop version 0.82.0.
4
+ # The point is for the user to remove these configuration records
5
+ # one by one as the offenses are removed from the code base.
6
+ # Note that changes in the inspected code, or installation of new
7
+ # versions of RuboCop, may require this file to be generated again.
8
+
9
+ # Offense count: 1
10
+ Lint/IneffectiveAccessModifier:
11
+ Exclude:
12
+ - 'lib/cvss_suite.rb'
13
+
14
+ # Offense count: 1
15
+ # Configuration parameters: ContextCreatingMethods, MethodCreatingMethods.
16
+ Lint/UselessAccessModifier:
17
+ Exclude:
18
+ - 'lib/cvss_suite.rb'
19
+
20
+ # Offense count: 8
21
+ # Configuration parameters: IgnoredMethods.
22
+ Metrics/AbcSize:
23
+ Max: 35
24
+
25
+ # Offense count: 5
26
+ # Configuration parameters: CountComments, ExcludedMethods.
27
+ # ExcludedMethods: refine
28
+ Metrics/BlockLength:
29
+ Max: 58
30
+
31
+ # Offense count: 2
32
+ # Configuration parameters: CountComments.
33
+ Metrics/ClassLength:
34
+ Max: 101
35
+
36
+ # Offense count: 1
37
+ # Configuration parameters: IgnoredMethods.
38
+ Metrics/CyclomaticComplexity:
39
+ Max: 9
40
+
41
+ # Offense count: 13
42
+ # Configuration parameters: CountComments, ExcludedMethods.
43
+ Metrics/MethodLength:
44
+ Max: 63
45
+
46
+ # Offense count: 1
47
+ # Configuration parameters: CountKeywordArgs.
48
+ Metrics/ParameterLists:
49
+ Max: 6
50
+
51
+ # Offense count: 1
52
+ # Configuration parameters: IgnoredMethods.
53
+ Metrics/PerceivedComplexity:
54
+ Max: 10
55
+
56
+ # Offense count: 1
57
+ Naming/AccessorMethodName:
58
+ Exclude:
59
+ - 'lib/cvss_suite/cvss_property.rb'
data/CHANGES.md CHANGED
@@ -2,6 +2,66 @@
2
2
  All notable changes to this project will be documented in this file.
3
3
  This project adheres to [Semantic Versioning](http://semver.org/).
4
4
 
5
+ ## [2.0.1] - 2020-07-19
6
+
7
+ ### Fixes
8
+ Fixed an error that resulted in incorrect environmental score if modified attributes were not defined.
9
+
10
+ ## [2.0.0] - 2020-05-10
11
+
12
+ ### Breaking Changes
13
+ * Ruby >= 2.4 is now required
14
+ * Renamed choice/choices to value/values
15
+
16
+ ### Improvements
17
+ * Added CvssSuite module to every class (thanks to @fwininger)
18
+ * Removed override for integer and float (thanks to @fwininger)
19
+ * Added rubocop to development environment (thanks to @fwininger)
20
+
21
+ ### Notes
22
+ Adding CvssSuite module everywhere means it’s no longer possible to access a class without it. Since this only affects the undocumented and ‚internal‘ classes this should not affect you. If you’re using them, stop it.
23
+
24
+ Still works:
25
+
26
+ ```ruby
27
+ cvss = CvssSuite.new('string')
28
+ ```
29
+
30
+ Won’t work anymore (without any code change):
31
+
32
+ ```ruby
33
+ cvss = Cvss31.new('string')
34
+ ```
35
+
36
+ This would need to be CvssSuite::Cvss31.new('string') to work. Or you could include the whole namespace.
37
+
38
+ ## [1.2.0] - 2019-07-02
39
+
40
+ ### Notes
41
+ Because version 2.0 of this gem will include breaking changes, please make sure to include this gem in your gemfile as shown below to not automatically update to version 2.0.
42
+
43
+ ```ruby
44
+ gem 'cvss-suite', '~> 1.2'
45
+ ```
46
+
47
+ ### Improvements
48
+ * Added Severity
49
+ * Added CVSS 3.1
50
+ * CVSS 3.0 vectors now return 3.0 instead of 3 as version
51
+
52
+ ### Changes in CVSS 3.1 [Source] (https://www.first.org/cvss/v3.1/user-guide)
53
+ * The Temporal Score for all vulnerabilities which have a Base Score of 2.5, 5.0 or 10.0, Exploit Code Maturity (E) of High (H), Remediation Level (RL) of Unavailable (U) and Report Confidence (RC) of Unknown (U) is 0.1 lower in CVSS v3.1 than for 3.0.
54
+ * Some combinations of metrics have Environmental Scores that differ when scored with CVSS v3.1 rather than v3.0. This is due to a combination of the redefinition of Roundup and the change to the ModifiedImpact sub-formula. Less than 7% of metric combinations are 0.1 higher in CVSS v3.1 than v3.0, and less than 1% are 0.1 lower. No Environmental Scores differ by more than 0.1.
55
+ * Other implementations of the CVSS formulas may see different scoring changes between CVSS v3.0 and v3.1 if they previously generated different CVSS v3.0 scores due to the problems that the CVSS v3.1 formula changes are intended to fix.
56
+
57
+ ## [1.1.2] - 2018-12-28
58
+
59
+ ### Fixes
60
+ Replaced Fixnum by Integer to improve compatibility with newer versions of Ruby.
61
+
62
+ ### Improvements
63
+ Added example for CVSS v3 to README.
64
+
5
65
  ## [1.1.1] - 2018-10-18
6
66
 
7
67
  ### Fixes
@@ -44,4 +104,4 @@ Tried to fix an error. It turned out to be a local problem. Due to this I increa
44
104
 
45
105
  ## [1.0.0] - 2016-04-15
46
106
  ### Initial release
47
- First release of this gem.
107
+ First release of this gem.
@@ -0,0 +1,24 @@
1
+ ## Proposed changes
2
+
3
+ Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue.
4
+
5
+ ## Types of changes
6
+
7
+ What types of changes does your code introduce to CvssSuite?
8
+ _Put an `x` in the boxes that apply_
9
+
10
+ - [ ] Bugfix (non-breaking change which fixes an issue)
11
+ - [ ] New feature (non-breaking change which adds functionality)
12
+ - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected)
13
+
14
+ ## Checklist
15
+
16
+ _Put an `x` in the boxes that apply. You can also fill these out after creating the PR._
17
+
18
+ - [ ] Unit tests pass locally with my changes
19
+ - [ ] I have added tests that prove my fix is effective or that my feature works
20
+ - [ ] I have added necessary documentation (if appropriate)
21
+
22
+ ## Further comments
23
+
24
+ If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc...
data/README.md CHANGED
@@ -1,9 +1,11 @@
1
- # CvssSuite
1
+ # CvssSuite for Ruby
2
2
 
3
3
  [![Gem Version](http://img.shields.io/gem/v/cvss-suite.svg)](https://rubygems.org/gems/cvss-suite)
4
- [![Ruby Version](https://img.shields.io/badge/Ruby-2.x-brightgreen.svg)](https://rubygems.org/gems/cvss-suite)
5
- [![Cvss Support](https://img.shields.io/badge/CVSS-v2-brightgreen.svg)](https://www.first.org/cvss/cvss-v2-guide.pdf)
6
- [![Cvss Support](https://img.shields.io/badge/CVSS-v3.0-brightgreen.svg)](https://www.first.org/cvss/cvss-v3-guide.pdf)
4
+ [![Ruby Version](https://img.shields.io/badge/Ruby-2.4-brightgreen.svg)](https://rubygems.org/gems/cvss-suite)
5
+ [![Cvss Support](https://img.shields.io/badge/CVSS-v2-brightgreen.svg)](https://www.first.org/cvss/v2/guide)
6
+ [![Cvss Support](https://img.shields.io/badge/CVSS-v3.0-brightgreen.svg)](https://www.first.org/cvss/v3.0/user-guide)
7
+ [![Cvss Support](https://img.shields.io/badge/CVSS-v3.1-brightgreen.svg)](https://www.first.org/cvss/v3.1/user-guide)
8
+ [![RSpec](https://github.com/siemens/cvss-suite/workflows/RSpec/badge.svg)](https://github.com/siemens/cvss-suite/actions)
7
9
 
8
10
  This Ruby gem helps you to process the vector of the [**Common Vulnerability Scoring System**](https://www.first.org/cvss/specification-document).
9
11
  Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.
@@ -23,17 +25,36 @@ And then execute:
23
25
  Or install it yourself as:
24
26
 
25
27
  $ gem install cvss-suite
28
+
29
+ ## Version 1.x
30
+
31
+ If your still using CvssSuite 1.x please refer to the [specific branch](https://github.com/siemens/cvss-suite/tree/1.x) for documentation and changelog.
26
32
 
27
33
  ## Usage
28
34
 
29
35
  ```ruby
30
36
  require 'cvss_suite'
31
37
 
38
+ cvss3 = CvssSuite.new('CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H')
39
+
40
+ vector = cvss3.vector # 'CVSS:3.0/AV:L/AC:H/PR:L/UI:R/S:C/C:L/I:L/A:L/CR:L/IR:M/AR:H/MAV:N/MAC:H/MPR:N/MUI:R/MS:U/MC:N/MI:L/MA:H'
41
+ version = cvss3.version # 3.0
42
+ valid = cvss3.valid? # true
43
+ severity = cvss3.severity # 'High'
44
+
45
+ cvss31 = CvssSuite.new('CVSS:3.1/AV:P/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:H/E:H/RL:U/RC:U')
46
+
47
+ vector = cvss31.vector # 'CVSS:3.1/AV:P/AC:H/PR:L/UI:R/S:U/C:L/I:L/A:H/E:H/RL:U/RC:U'
48
+ version = cvss31.version # 3.1
49
+ valid = cvss31.valid? # true
50
+ severity = cvss31.severity # 'Medium'
51
+
32
52
  cvss = CvssSuite.new('AV:A/AC:M/Au:S/C:P/I:P/A:P/E:POC/RL:TF/RC:UC/CDP:L/TD:M/CR:M/IR:M/AR:M')
33
53
 
34
- vector = cvss.vector # 'AV:A/AC:M/Au:S/C:P/I:P/A:P/E:POC/RL:TF/RC:UC/CDP:L/TD:M/CR:M/IR:M/AR:M'
35
- version = cvss.version # 2
36
- valid = cvss.valid? # true
54
+ vector = cvss.vector # 'AV:A/AC:M/Au:S/C:P/I:P/A:P/E:POC/RL:TF/RC:UC/CDP:L/TD:M/CR:M/IR:M/AR:M'
55
+ version = cvss.version # 2
56
+ valid = cvss.valid? # true
57
+ severity = cvss.severity # 'Low'
37
58
 
38
59
  # Scores
39
60
  base_score = cvss.base_score # 4.9
@@ -45,15 +66,15 @@ overall_score = cvss.overall_score # 3.2
45
66
  access_vector = cvss.base.access_vector.name # 'Access Vector'
46
67
  remediation_level = cvss.temporal.remediation_level.name # 'Remediation Level'
47
68
 
48
- access_vector.choices.each do |choice|
49
- choice[:name] # 'Local', 'Adjacent Network', 'Network'
50
- choice[:abbreviation] # 'L', 'A', 'N'
51
- choice[:selected] # false, true, false
69
+ access_vector.values.each do |value|
70
+ value[:name] # 'Local', 'Adjacent Network', 'Network'
71
+ value[:abbreviation] # 'L', 'A', 'N'
72
+ value[:selected] # false, true, false
52
73
  end
53
74
 
54
75
  # Selected options
55
- cvss.base.access_vector.selected_choice[:name] # Adjacent Network
56
- cvss.temporal.remediation_level.selected_choice[:name] # Temporary Fix
76
+ cvss.base.access_vector.selected_value[:name] # Adjacent Network
77
+ cvss.temporal.remediation_level.selected_value[:name] # Temporary Fix
57
78
 
58
79
  # Exceptions
59
80
 
@@ -67,7 +88,7 @@ valid = cvss.valid? # false
67
88
  version = cvss.version # will throw CvssSuite::Errors::InvalidVector: Vector is not valid!
68
89
  cvss.base_score # will throw CvssSuite::Errors::InvalidVector: Vector is not valid!
69
90
 
70
- CvssSuite.new() # will throw a ArgumentError
91
+ CvssSuite.new() # will throw a ArgumentError
71
92
 
72
93
  cvss = CvssSuite.new('AV:N/AC:P/C:P/AV:U/RL:OF/RC:C') # invalid vector, authentication is missing
73
94
  version = cvss.version # 2
@@ -81,11 +102,17 @@ Properties (Access Vector, Remediation Level, etc) do have a position attribute,
81
102
 
82
103
  ## Known Issues
83
104
 
84
- Currently it is not possible to leave a attribute blank instead of ND/X. If you don't have a value for a attribute, please use ND/X instead.
105
+ Currently it is not possible to leave an attribute blank instead of ND/X. If you don't have a value for an attribute, please use ND/X instead.
106
+
107
+ There is a possibility of implementations generating different scores (+/- 0,1) due to small floating-point inaccuracies. This can happen due to differences in floating point arithmetic between different languages and hardware platforms.
108
+
109
+ ## Changelog
85
110
 
86
- Because the documentation isn't clear on how to calculate the score if Modified Scope (CVSS 3.0 Environmental) is not defined, Modified Scope has to have a valid value (S/U).
111
+ [Click here to see all changes.](https://github.com/siemens/cvss-suite/blob/master/CHANGES.md)
87
112
 
88
113
  ## Contributing
89
114
 
90
115
  Bug reports and pull requests are welcome on GitHub at https://github.com/siemens/cvss-suite. This project is intended to be a safe, welcoming space for collaboration.
91
116
 
117
+ ## References
118
+ [CvssSuite for .NET](https://github.com/oliverhamboerger/CvssSuite)
@@ -0,0 +1 @@
1
+ theme: jekyll-theme-cayman
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "cvss_suite"
3
+ require 'bundler/setup'
4
+ require 'cvss_suite'
5
5
 
6
6
  # You can add fixtures and/or initialization code here to make experimenting
7
7
  # with your gem easier. You can also use a different console, if you like.
@@ -10,5 +10,5 @@ require "cvss_suite"
10
10
  # require "pry"
11
11
  # Pry.start
12
12
 
13
- require "irb"
13
+ require 'irb'
14
14
  IRB.start