cvss-suite 1.2.0 → 2.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/rspec.yml +23 -0
- data/.github/workflows/rubocop.yml +21 -0
- data/.rubocop.yml +47 -1
- data/.rubocop_todo.yml +59 -0
- data/CHANGES.md +40 -1
- data/README.md +16 -11
- data/_config.yml +1 -0
- data/bin/console +3 -3
- data/cvss_suite.gemspec +14 -14
- data/lib/cvss_suite.rb +10 -14
- data/lib/cvss_suite/cvss.rb +93 -95
- data/lib/cvss_suite/cvss2/cvss2.rb +50 -28
- data/lib/cvss_suite/cvss2/cvss2_base.rb +69 -75
- data/lib/cvss_suite/cvss2/cvss2_environmental.rb +52 -54
- data/lib/cvss_suite/cvss2/cvss2_temporal.rb +40 -41
- data/lib/cvss_suite/cvss3/cvss3.rb +39 -36
- data/lib/cvss_suite/cvss3/cvss3_base.rb +72 -75
- data/lib/cvss_suite/cvss3/cvss3_environmental.rb +159 -109
- data/lib/cvss_suite/cvss3/cvss3_temporal.rb +41 -42
- data/lib/cvss_suite/cvss31/cvss31.rb +36 -28
- data/lib/cvss_suite/cvss31/cvss31_base.rb +66 -68
- data/lib/cvss_suite/cvss31/cvss31_environmental.rb +159 -109
- data/lib/cvss_suite/cvss31/cvss31_temporal.rb +41 -42
- data/lib/cvss_suite/cvss_metric.rb +31 -35
- data/lib/cvss_suite/cvss_property.rb +57 -56
- data/lib/cvss_suite/errors.rb +2 -0
- data/lib/cvss_suite/helpers/cvss31_helper.rb +27 -0
- data/lib/cvss_suite/helpers/cvss3_helper.rb +21 -15
- data/lib/cvss_suite/invalid_cvss.rb +39 -45
- data/lib/cvss_suite/version.rb +2 -2
- metadata +12 -23
- data/.travis.yml +0 -4
- data/lib/cvss_suite/helpers/extensions.rb +0 -56
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f109a2e3d49b66723f39c092692b3cabfa75d829d8ef3f0e07cf9d0d238a3755
|
4
|
+
data.tar.gz: 41660286d0173fa19c37dd49b43f4efc5fc1db025ae6a46741baf0694b5199d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c567e0730cf9e4ef3e2e85a5c1fa35a9b949c59ed278a968bbf336732f1229cbcfbd84c34e67256a91a6de058a71b13275cb4d8eefdbaa2c416b18e106aac7ff
|
7
|
+
data.tar.gz: d883de3fdc12def5106855a221a535751c9846104ee37a6ecbe8a391a9e3f59b752696c7e0fd128b0dcf8fbedf60bdaa6a0c3d1d1a625c71204555133a4e365b
|
@@ -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/.rubocop.yml
CHANGED
@@ -1,2 +1,48 @@
|
|
1
|
+
inherit_from: .rubocop_todo.yml
|
2
|
+
|
3
|
+
AllCops:
|
4
|
+
TargetRubyVersion: 2.4
|
5
|
+
SuggestExtensions: false
|
6
|
+
|
1
7
|
Metrics/LineLength:
|
2
|
-
Max: 120
|
8
|
+
Max: 120
|
9
|
+
Exclude:
|
10
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
11
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
12
|
+
|
13
|
+
Metrics/ClassLength:
|
14
|
+
Exclude:
|
15
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
16
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
17
|
+
|
18
|
+
Metrics/MethodLength:
|
19
|
+
Exclude:
|
20
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
21
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
22
|
+
|
23
|
+
Metrics/BlockLength:
|
24
|
+
Exclude:
|
25
|
+
- 'spec/cvss2/cvss2_spec.rb'
|
26
|
+
- 'spec/cvss3/cvss3_spec.rb'
|
27
|
+
- 'spec/cvss31/cvss31_spec.rb'
|
28
|
+
|
29
|
+
Style/IfUnlessModifier:
|
30
|
+
Exclude:
|
31
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
32
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
33
|
+
|
34
|
+
Style/GuardClause:
|
35
|
+
Exclude:
|
36
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
37
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
38
|
+
|
39
|
+
Style/ConditionalAssignment:
|
40
|
+
Exclude:
|
41
|
+
- 'lib/cvss_suite/cvss3/cvss3_environmental.rb'
|
42
|
+
- 'lib/cvss_suite/cvss31/cvss31_environmental.rb'
|
43
|
+
|
44
|
+
Style/FrozenStringLiteralComment:
|
45
|
+
Enabled: false
|
46
|
+
|
47
|
+
Style/AsciiComments:
|
48
|
+
Enabled: false
|
data/.rubocop_todo.yml
ADDED
@@ -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,45 @@
|
|
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.2] - 2020-12-05
|
6
|
+
|
7
|
+
### Fixes
|
8
|
+
* CVSS v2 now returns the correct severity values based on NVD recommendation
|
9
|
+
* CVSS v2 now supports vectors which are enclosed in parenthesis e.g. (AV:N/AC:L/Au:N/C:P/I:P/A:P)
|
10
|
+
|
11
|
+
## [2.0.1] - 2020-07-19
|
12
|
+
|
13
|
+
### Fixes
|
14
|
+
Fixed an error that resulted in incorrect environmental score if modified attributes were not defined.
|
15
|
+
|
16
|
+
## [2.0.0] - 2020-05-10
|
17
|
+
|
18
|
+
### Breaking Changes
|
19
|
+
* Ruby >= 2.4 is now required
|
20
|
+
* Renamed choice/choices to value/values
|
21
|
+
|
22
|
+
### Improvements
|
23
|
+
* Added CvssSuite module to every class (thanks to @fwininger)
|
24
|
+
* Removed override for integer and float (thanks to @fwininger)
|
25
|
+
* Added rubocop to development environment (thanks to @fwininger)
|
26
|
+
|
27
|
+
### Notes
|
28
|
+
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.
|
29
|
+
|
30
|
+
Still works:
|
31
|
+
|
32
|
+
```ruby
|
33
|
+
cvss = CvssSuite.new('string')
|
34
|
+
```
|
35
|
+
|
36
|
+
Won’t work anymore (without any code change):
|
37
|
+
|
38
|
+
```ruby
|
39
|
+
cvss = Cvss31.new('string')
|
40
|
+
```
|
41
|
+
|
42
|
+
This would need to be CvssSuite::Cvss31.new('string') to work. Or you could include the whole namespace.
|
43
|
+
|
5
44
|
## [1.2.0] - 2019-07-02
|
6
45
|
|
7
46
|
### Notes
|
@@ -71,4 +110,4 @@ Tried to fix an error. It turned out to be a local problem. Due to this I increa
|
|
71
110
|
|
72
111
|
## [1.0.0] - 2016-04-15
|
73
112
|
### Initial release
|
74
|
-
First release of this gem.
|
113
|
+
First release of this gem.
|
data/README.md
CHANGED
@@ -1,10 +1,11 @@
|
|
1
|
-
# CvssSuite
|
1
|
+
# CvssSuite for Ruby
|
2
2
|
|
3
3
|
[](https://rubygems.org/gems/cvss-suite)
|
4
|
-
[](https://rubygems.org/gems/cvss-suite)
|
5
5
|
[](https://www.first.org/cvss/v2/guide)
|
6
6
|
[](https://www.first.org/cvss/v3.0/user-guide)
|
7
7
|
[](https://www.first.org/cvss/v3.1/user-guide)
|
8
|
+
[](https://github.com/siemens/cvss-suite/actions)
|
8
9
|
|
9
10
|
This Ruby gem helps you to process the vector of the [**Common Vulnerability Scoring System**](https://www.first.org/cvss/specification-document).
|
10
11
|
Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.
|
@@ -24,6 +25,10 @@ And then execute:
|
|
24
25
|
Or install it yourself as:
|
25
26
|
|
26
27
|
$ gem install cvss-suite
|
28
|
+
|
29
|
+
## Version 1.x
|
30
|
+
|
31
|
+
If you are still using CvssSuite 1.x please refer to the [specific branch](https://github.com/siemens/cvss-suite/tree/1.x) for documentation and changelog.
|
27
32
|
|
28
33
|
## Usage
|
29
34
|
|
@@ -61,15 +66,15 @@ overall_score = cvss.overall_score # 3.2
|
|
61
66
|
access_vector = cvss.base.access_vector.name # 'Access Vector'
|
62
67
|
remediation_level = cvss.temporal.remediation_level.name # 'Remediation Level'
|
63
68
|
|
64
|
-
access_vector.
|
65
|
-
|
66
|
-
|
67
|
-
|
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
|
68
73
|
end
|
69
74
|
|
70
75
|
# Selected options
|
71
|
-
cvss.base.access_vector.
|
72
|
-
cvss.temporal.remediation_level.
|
76
|
+
cvss.base.access_vector.selected_value[:name] # Adjacent Network
|
77
|
+
cvss.temporal.remediation_level.selected_value[:name] # Temporary Fix
|
73
78
|
|
74
79
|
# Exceptions
|
75
80
|
|
@@ -99,15 +104,15 @@ Properties (Access Vector, Remediation Level, etc) do have a position attribute,
|
|
99
104
|
|
100
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.
|
101
106
|
|
102
|
-
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).
|
103
|
-
|
104
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.
|
105
108
|
|
106
109
|
## Changelog
|
107
110
|
|
108
|
-
[Click here to see all changes.](https://
|
111
|
+
[Click here to see all changes.](https://github.com/siemens/cvss-suite/blob/master/CHANGES.md)
|
109
112
|
|
110
113
|
## Contributing
|
111
114
|
|
112
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.
|
113
116
|
|
117
|
+
## References
|
118
|
+
[CvssSuite for .NET](https://github.com/oliverhamboerger/CvssSuite)
|
data/_config.yml
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
theme: jekyll-theme-cayman
|
data/bin/console
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
#!/usr/bin/env ruby
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
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
|
13
|
+
require 'irb'
|
14
14
|
IRB.start
|
data/cvss_suite.gemspec
CHANGED
@@ -9,7 +9,8 @@
|
|
9
9
|
# See the LICENSE.md file in the top-level directory.
|
10
10
|
|
11
11
|
# coding: utf-8
|
12
|
-
|
12
|
+
|
13
|
+
lib = File.expand_path('lib', __dir__)
|
13
14
|
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
14
15
|
require 'cvss_suite/version'
|
15
16
|
|
@@ -17,24 +18,23 @@ Gem::Specification.new do |spec|
|
|
17
18
|
spec.name = 'cvss-suite'
|
18
19
|
spec.version = CvssSuite::VERSION
|
19
20
|
spec.license = 'MIT'
|
20
|
-
spec.authors = [
|
21
|
-
spec.email = [
|
21
|
+
spec.authors = ['Oliver Hamboerger']
|
22
|
+
spec.email = ['oliver.hamboerger@siemens.com']
|
22
23
|
|
23
|
-
spec.summary =
|
24
|
-
spec.description =
|
25
|
-
Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.
|
26
|
-
spec.homepage =
|
24
|
+
spec.summary = 'Ruby gem for processing cvss vectors.'
|
25
|
+
spec.description = 'This Ruby gem helps you to process the vector of the Common Vulnerability Scoring System (https://www.first.org/cvss/specification-document).
|
26
|
+
Besides calculating the Base, Temporal and Environmental Score, you are able to extract the selected option.'
|
27
|
+
spec.homepage = 'https://siemens.github.io/cvss-suite/'
|
27
28
|
|
28
|
-
spec.required_ruby_version = '>= 2.
|
29
|
+
spec.required_ruby_version = '>= 2.4.0'
|
29
30
|
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
30
31
|
spec.bindir = 'exe'
|
31
32
|
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
32
33
|
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
33
|
-
spec.require_paths = [
|
34
|
+
spec.require_paths = ['lib']
|
34
35
|
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency "simplecov", "~> 0.11.2"
|
36
|
+
spec.add_development_dependency 'bundler', '>= 1.10'
|
37
|
+
spec.add_development_dependency 'rspec', '~> 3.4'
|
38
|
+
spec.add_development_dependency 'rspec-its', '~> 1.2'
|
39
|
+
spec.add_development_dependency 'simplecov', '~> 0.18'
|
40
40
|
end
|
data/lib/cvss_suite.rb
CHANGED
@@ -12,33 +12,32 @@ require 'cvss_suite/cvss2/cvss2'
|
|
12
12
|
require 'cvss_suite/cvss3/cvss3'
|
13
13
|
require 'cvss_suite/cvss31/cvss31'
|
14
14
|
require 'cvss_suite/version'
|
15
|
-
require 'cvss_suite/helpers/extensions'
|
16
15
|
require 'cvss_suite/errors'
|
17
16
|
require 'cvss_suite/invalid_cvss'
|
18
17
|
|
19
18
|
##
|
20
19
|
# Module of this gem.
|
21
|
-
|
22
20
|
module CvssSuite
|
23
21
|
CVSS_VECTOR_BEGINNINGS = [
|
24
|
-
{:
|
25
|
-
{:
|
26
|
-
{:
|
27
|
-
|
22
|
+
{ string: 'AV:', version: 2 },
|
23
|
+
{ string: '(AV:', version: 2 },
|
24
|
+
{ string: 'CVSS:3.0/', version: 3.0 },
|
25
|
+
{ string: 'CVSS:3.1/', version: 3.1 }
|
26
|
+
].freeze
|
28
27
|
|
29
28
|
##
|
30
29
|
# Returns a CVSS class by a +vector+.
|
31
|
-
|
32
30
|
def self.new(vector)
|
33
31
|
return InvalidCvss.new unless vector.is_a? String
|
32
|
+
|
34
33
|
@vector_string = vector
|
35
34
|
case version
|
36
35
|
when 2
|
37
|
-
Cvss2.new(@vector_string
|
36
|
+
Cvss2.new(@vector_string)
|
38
37
|
when 3.0
|
39
|
-
Cvss3.new(@vector_string
|
38
|
+
Cvss3.new(@vector_string)
|
40
39
|
when 3.1
|
41
|
-
Cvss31.new(@vector_string
|
40
|
+
Cvss31.new(@vector_string)
|
42
41
|
else
|
43
42
|
InvalidCvss.new
|
44
43
|
end
|
@@ -48,10 +47,7 @@ module CvssSuite
|
|
48
47
|
|
49
48
|
def self.version
|
50
49
|
CVSS_VECTOR_BEGINNINGS.each do |beginning|
|
51
|
-
if @vector_string.start_with? beginning[:string]
|
52
|
-
return beginning[:version]
|
53
|
-
end
|
50
|
+
return beginning[:version] if @vector_string.start_with? beginning[:string]
|
54
51
|
end
|
55
52
|
end
|
56
|
-
|
57
53
|
end
|
data/lib/cvss_suite/cvss.rb
CHANGED
@@ -8,118 +8,116 @@
|
|
8
8
|
# This work is licensed under the terms of the MIT license.
|
9
9
|
# See the LICENSE.md file in the top-level directory.
|
10
10
|
|
11
|
-
|
12
|
-
# This class represents any CVSS vector. Do not instantiate this class!
|
13
|
-
|
14
|
-
class Cvss
|
15
|
-
|
16
|
-
##
|
17
|
-
# Metric of a CVSS vector.
|
18
|
-
|
19
|
-
attr_reader :base, :temporal, :environmental
|
20
|
-
|
21
|
-
##
|
22
|
-
# Returns version of current CVSS vector.
|
23
|
-
|
24
|
-
attr_reader :version
|
25
|
-
|
26
|
-
##
|
27
|
-
# Returns the vector itself.
|
28
|
-
|
29
|
-
attr_reader :vector
|
30
|
-
|
31
|
-
##
|
32
|
-
# Creates a new CVSS vector by a +vector+ and a +version+.
|
33
|
-
#
|
34
|
-
# Raises an exception if it is called on Cvss class.
|
35
|
-
|
36
|
-
def initialize(vector, version)
|
37
|
-
raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if self.class == Cvss
|
38
|
-
@version = version
|
39
|
-
@vector = vector
|
40
|
-
@properties = []
|
41
|
-
extract_metrics
|
42
|
-
init_metrics
|
43
|
-
end
|
44
|
-
|
11
|
+
module CvssSuite
|
45
12
|
##
|
46
|
-
#
|
13
|
+
# This class represents any CVSS vector. Do not instantiate this class!
|
14
|
+
class Cvss
|
15
|
+
##
|
16
|
+
# Metric of a CVSS vector.
|
17
|
+
attr_reader :base, :temporal, :environmental
|
18
|
+
|
19
|
+
##
|
20
|
+
# Returns the vector itself.
|
21
|
+
attr_reader :vector
|
22
|
+
|
23
|
+
##
|
24
|
+
# Creates a new CVSS vector by a +vector+.
|
25
|
+
#
|
26
|
+
# Raises an exception if it is called on Cvss class.
|
27
|
+
def initialize(vector)
|
28
|
+
raise CvssSuite::Errors::InvalidParentClass, 'Do not instantiate this class!' if instance_of? Cvss
|
29
|
+
|
30
|
+
@vector = vector
|
31
|
+
@properties = []
|
32
|
+
extract_metrics
|
33
|
+
init_metrics
|
34
|
+
end
|
47
35
|
|
48
|
-
|
49
|
-
if
|
36
|
+
##
|
37
|
+
# Returns if CVSS vector is valid.
|
38
|
+
def valid?
|
39
|
+
if @amount_of_properties == required_amount_of_properties
|
50
40
|
base = @base.valid?
|
51
41
|
temporal = @base.valid? && @temporal.valid?
|
52
42
|
environmental = @base.valid? && @environmental.valid?
|
53
43
|
full = @base.valid? && @temporal.valid? && @environmental.valid?
|
54
44
|
base || temporal || environmental || full
|
55
|
-
|
56
|
-
|
45
|
+
else
|
46
|
+
false
|
47
|
+
end
|
57
48
|
end
|
58
|
-
end
|
59
49
|
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
50
|
+
##
|
51
|
+
# Returns the severity of the CVSS vector.
|
52
|
+
def severity
|
53
|
+
check_validity
|
54
|
+
|
55
|
+
score = overall_score
|
56
|
+
|
57
|
+
if score <= 0.0
|
58
|
+
'None'
|
59
|
+
elsif (0.1..3.9).cover? score
|
60
|
+
'Low'
|
61
|
+
elsif (4.0..6.9).cover? score
|
62
|
+
'Medium'
|
63
|
+
elsif (7.0..8.9).cover? score
|
64
|
+
'High'
|
65
|
+
elsif (9.0..10.0).cover? score
|
66
|
+
'Critical'
|
67
|
+
else
|
68
|
+
'None'
|
69
|
+
end
|
80
70
|
end
|
81
|
-
end
|
82
71
|
|
83
|
-
|
84
|
-
|
72
|
+
##
|
73
|
+
# Returns the Overall Score of the CVSS vector.
|
74
|
+
def overall_score
|
75
|
+
check_validity
|
76
|
+
return temporal_score if @temporal.valid? && !@environmental.valid?
|
77
|
+
return environmental_score if @environmental.valid?
|
85
78
|
|
86
|
-
|
87
|
-
|
88
|
-
return temporal_score if @temporal.valid? && !@environmental.valid?
|
89
|
-
return environmental_score if @environmental.valid?
|
90
|
-
base_score
|
91
|
-
end
|
79
|
+
base_score
|
80
|
+
end
|
92
81
|
|
93
|
-
|
82
|
+
private
|
94
83
|
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
84
|
+
def extract_metrics
|
85
|
+
properties = prepared_vector.split('/')
|
86
|
+
@amount_of_properties = properties.size
|
87
|
+
properties.each_with_index do |property, index|
|
88
|
+
property = property.split(':')
|
89
|
+
@properties.push({ name: property[0], selected: property[1], position: index })
|
90
|
+
end
|
101
91
|
end
|
102
|
-
end
|
103
|
-
|
104
|
-
def check_validity
|
105
|
-
raise CvssSuite::Errors::InvalidVector, 'Vector is not valid!' unless valid?
|
106
|
-
end
|
107
92
|
|
108
|
-
|
109
|
-
|
93
|
+
def check_validity
|
94
|
+
raise CvssSuite::Errors::InvalidVector, 'Vector is not valid!' unless valid?
|
95
|
+
end
|
110
96
|
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
97
|
+
def prepared_vector
|
98
|
+
start_of_vector = @vector.index('AV')
|
99
|
+
|
100
|
+
if start_of_vector.nil?
|
101
|
+
''
|
102
|
+
elsif start_of_vector == 1
|
103
|
+
match_array = @vector.scan(/\((?>[^)(]+|\g<0>)*\)/)
|
104
|
+
if match_array.length == 1 && match_array[0] == @vector
|
105
|
+
@vector.slice!(0)
|
106
|
+
@vector.slice!(@vector.length - 1)
|
107
|
+
@vector
|
108
|
+
else
|
109
|
+
''
|
110
|
+
end
|
111
|
+
else
|
112
|
+
@vector[start_of_vector..-1]
|
113
|
+
end
|
115
114
|
end
|
116
|
-
end
|
117
115
|
|
118
|
-
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
|
116
|
+
def required_amount_of_properties
|
117
|
+
total = @base.count if @base.valid?
|
118
|
+
total += @temporal.count if @temporal.valid?
|
119
|
+
total += @environmental.count if @environmental.valid?
|
120
|
+
total || 0
|
121
|
+
end
|
123
122
|
end
|
124
|
-
|
125
|
-
end
|
123
|
+
end
|