cve 0.1.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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 0f70a573dcb61f792c4dc6b8c7a381393c10bbc7e4c32cede0cf8b51ec8992ea
4
+ data.tar.gz: 13b7641c5dd0383ad258711c3dd8f2c6b0a22fd30ff8d06a4ec521d4aab2ae30
5
+ SHA512:
6
+ metadata.gz: 9e2731047003d100271d2059820c5d8bde6332ddf23794a67a0019a6150eb982ae2f4bddda18cbc96477b9af36f8ef6e6a0d85433e821bb715d47845292abb8c
7
+ data.tar.gz: 8185220576d82f7be99e6e787787870a2c58cfb52c2bdbdf3dd1ba3814a71611578dafc811be47d11a5164637703cea658fca9e092d2987c0f88395194e35f03
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem 'gems'
4
+
5
+ gem 'color_pound_spec_reporter'
6
+ gem 'httparty', '~> 0.22'
7
+ gem 'minitest', '~> 5.18'
8
+ gem 'minitest-reporters', '~> 1.6'
data/README.md ADDED
@@ -0,0 +1,18 @@
1
+ # Book & Owl CVE Lookup Utility
2
+
3
+ ## Overview
4
+
5
+ A simple utility to lookup CVE entries in the NIST database for a specific product and version ("cpe").
6
+
7
+ ## Usage
8
+
9
+ `cve <search|help|legal> [product] [version]`
10
+
11
+ Commands
12
+ - search: search NIST vulnerabilty database for [product] and [version]
13
+ - help: display usage information (i.e. this message)
14
+ - legal: display license and related information for CVE Lookup Utility and NIST NVD data
15
+
16
+ ## License
17
+
18
+ The CVE Lookup Utility is licensed under the MIT License. See LICENSE file or `cve legal` for details.
data/Rakefile ADDED
@@ -0,0 +1,53 @@
1
+ require "rake/testtask"
2
+
3
+ namespace :test do
4
+ Rake::TestTask.new(:all) do |task|
5
+ task.description = "Run all unit and integration tests"
6
+ task.libs << ["test", "test/unit" "lib"]
7
+ task.test_files = FileList["test/unit/*_test.rb", "test/integration/*_test.rb"]
8
+ end
9
+
10
+ Rake::TestTask.new(:unit) do |task|
11
+ task.description = "Run unit tests"
12
+ task.libs << ["test", "test/unit" "lib"]
13
+ task.test_files = FileList["test/unit/*_test.rb"]
14
+ end
15
+
16
+ Rake::TestTask.new(:integration) do |task|
17
+ task.description = "Run integration tests"
18
+ task.libs << ["test", "test/unit" "lib"]
19
+ task.test_files = FileList["test/integration/*_test.rb"]
20
+ end
21
+
22
+ desc "Run all benchmark evaluations"
23
+ task :benchmark do
24
+ Dir.glob("test/benchmarks/*_bench.rb") do |benchmark|
25
+ puts "\nRunning..."
26
+ ruby "-I lib -I test/benchmarks #{benchmark}"
27
+ puts "\n\n#{"-" * 8}\n"
28
+ end
29
+ end
30
+ end
31
+
32
+ desc "Print the specs"
33
+ task :print_specs do
34
+ puts "\n"
35
+ FileList["test/unit/*_test.rb", "test/integration/*_test.rb"].each do |f|
36
+ puts "\n#{f}\n"
37
+ indent = 2
38
+ File.readlines(f).each do |line|
39
+ indent += 1 if /\bdo\b/ =~ line
40
+ case
41
+ when /describe\s*\'(.*)\'/ =~ line
42
+ puts "#{" " * indent}#{$1}"
43
+ when /it\s*\'(.*)\'/ =~ line
44
+ puts "#{" " * indent}#{$1}"
45
+ when /^\s*end/ =~ line
46
+ indent = [indent -= 1, 0].max
47
+ end
48
+ end
49
+ end
50
+ end
51
+
52
+ task :default => "test:unit"
53
+ task :test => "test:unit"
data/bin/cve ADDED
@@ -0,0 +1,41 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ ##
4
+ # Copyright (c) 2024 Gerald Hilts
5
+ # License: MIT (https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)
6
+ #
7
+ # This file is the entry-point to app.
8
+ # It is a executable shell script that accepts
9
+ # and parses command line arguments then hands
10
+ # things of off to an appropriate class-based
11
+ # object.
12
+ ##
13
+
14
+ $LOAD_PATH.unshift File.join(File.expand_path(File.join(File.realpath(__FILE__), "../..")), "lib")
15
+
16
+ require 'legal_helper'
17
+ require 'search'
18
+
19
+ @help = <<~END_QUOTE
20
+ Usage: cve <search|help|legal> [product] [version]
21
+
22
+ Commands
23
+ - search: search NIST vulnerabilty database for [product] and [version]
24
+ - help: display this message
25
+ - legal: display license and related information for CVE Lookup Utility and NIST NVD data
26
+
27
+ END_QUOTE
28
+
29
+ case ARGV[0]
30
+ when 'help'
31
+ puts @help
32
+ when 'legal'
33
+ LegalHelper.print_info
34
+ when 'search'
35
+ Search.new(ARGV[1], ARGV[2]).run
36
+ else
37
+ puts 'Error: unknown or missing command'
38
+ puts @help
39
+ end
40
+
41
+ exit 0
data/lib/io_helper.rb ADDED
@@ -0,0 +1,31 @@
1
+ # (c) 2024 Gerald Hilts
2
+ # License: MIT (https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)
3
+
4
+ class IOHelper
5
+ require "io/console"
6
+
7
+ def initialize(test_mode = false)
8
+ @test = test_mode
9
+ end
10
+
11
+ def request(prompt, test_val = "TEST")
12
+ unless @test
13
+ print "#{prompt} "
14
+ $stdin.gets.chomp
15
+ else
16
+ test_val
17
+ end
18
+ end
19
+
20
+ def request_from_range(range, test_val = 0)
21
+ unless @test
22
+ response = ""
23
+ until (response.match /^(\d+|X)/) && (range.include? response.to_i) do
24
+ response = request("#{range.first} - #{range.last}: ")
25
+ end
26
+ response
27
+ else
28
+ test_val
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,70 @@
1
+ # (c) 2024 Gerald Hilts
2
+ # License: MIT (https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)
3
+
4
+ class LegalHelper
5
+ def self.license
6
+ File.read(File.join(File.expand_path(File.join(File.realpath(__FILE__), "../..")), "LICENSE"))
7
+ end
8
+
9
+ def self.nvd_info
10
+ <<~END_QUOTE
11
+ NIST NVD
12
+ ========
13
+
14
+ The CVE Lookup Utility uses application programming interfaces (APIs) to
15
+ retreive information from the National Vulnerability Database (NVD), a U.S.
16
+ government repository of standards based vulnerability management data.
17
+
18
+ This data is made available by the National Institute of Standards and
19
+ Technology (NIST) as a "as a public service" with the following legal
20
+ disclaimer:
21
+
22
+ The National Vulnerability Database (NVD) is a repository of standards based
23
+ vulnerability data. The Database is maintained by the National Institute of
24
+ Standards and Technology (NIST), an agency of the Federal Government, and is
25
+ being provided as a public service. Much of the data in NVD records is derived
26
+ from publicly available data sources, including product information and
27
+ manufacturer/developer information. NIST does not evaluate, review, or test
28
+ software or code contained within the NVD. The NVD is expressly provided
29
+ “AS IS.” NIST MAKES NO WARRANTY OF ANY KIND, EXPRESS, IMPLIED OR STATUTORY,
30
+ INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS
31
+ FOR A PARTICULAR PURPOSE, NON-INFRINGEMENT, AND DATA ACCURACY. NIST does not
32
+ warrant or make any representations regarding the use of the NVD, its contents,
33
+ or the results obtained therefrom, including but not limited to the correctness,
34
+ accuracy, reliability, or usefulness of the NVD. You are solely responsible for
35
+ determining the appropriateness of your use of the NVD and its contents and you
36
+ assume all risks associated with its use.
37
+
38
+ (see https://nvd.nist.gov/general/legal-disclaimer)
39
+
40
+ The CVE Lookup Utility is not endorsed or certified by the NVD.
41
+ END_QUOTE
42
+ end
43
+
44
+ def self.third_party_info
45
+ <<~END_QUOTE
46
+ Ruby Gems
47
+ =========
48
+
49
+ Although not present in the code itself, various Ruby Gem libraries
50
+ that CVE Lookup Utility rely upon may be installed along with it
51
+ if they are not already present in the user's environment.
52
+
53
+ These libraries are released under various licenses. See
54
+
55
+ https://github.com/gwhilts/cve_lookup/blob/main/THIRD_PARTY.md
56
+
57
+ for more details.
58
+ END_QUOTE
59
+ end
60
+
61
+ def self.print_info
62
+ puts "\n"
63
+ puts license
64
+ puts "\n(https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)\n\n"
65
+ puts nvd_info
66
+ puts "\n\n"
67
+ puts third_party_info
68
+ end
69
+
70
+ end
data/lib/nvd_helper.rb ADDED
@@ -0,0 +1,41 @@
1
+ # (c) 2024 Gerald Hilts
2
+ # License: MIT (https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)
3
+
4
+ class NVDHelper
5
+ require 'httparty'
6
+ require 'cgi'
7
+
8
+ NIST_API_SERVER = "https://services.nvd.nist.gov"
9
+ NIST_CVE_URL_BASE = "https://nvd.nist.gov/vuln/detail/"
10
+
11
+ def self.cpe_list_for(name, version)
12
+ begin
13
+ HTTParty.get(cpe_uri(name, version))['products'].map do |p|
14
+ { title: p['cpe']['titles'][0]['title'], cpe_name: p['cpe']['cpeName'] }
15
+ end
16
+ rescue
17
+ []
18
+ end
19
+ end
20
+
21
+ def self.cpe_uri(name, version)
22
+ "#{NIST_API_SERVER}/rest/json/cpes/2.0?cpeMatchString=cpe:2.3:*:*:#{CGI.escape(name)}:#{CGI.escape(version)}"
23
+ end
24
+
25
+ def self.cve_list_for(cpe_name)
26
+ # begin
27
+ HTTParty.get(cve_uri(cpe_name))["vulnerabilities"].map { |v| v["cve"]["id"] }
28
+ # rescue
29
+ # []
30
+ # end
31
+ end
32
+
33
+ def self.cve_uri(cpe_name)
34
+ "#{NIST_API_SERVER}/rest/json/cves/2.0?cpeName=#{cpe_name}"
35
+ end
36
+
37
+ def self.detail_urls_for(cve_list)
38
+ cve_list.map { |cve| NIST_CVE_URL_BASE + cve }
39
+ end
40
+
41
+ end
data/lib/search.rb ADDED
@@ -0,0 +1,73 @@
1
+ # (c) 2024 Gerald Hilts
2
+ # License: MIT (https://github.com/gwhilts/cve_lookup/blob/main/LICENSE)
3
+
4
+ class Search
5
+ require 'io_helper'
6
+ require 'nvd_helper'
7
+
8
+ def initialize(product, version, test_mode = false)
9
+ @cpe_name = ""
10
+ @cpe_title = ""
11
+ @product = product
12
+ @version = version
13
+ @io = IOHelper.new(test_mode)
14
+ end
15
+
16
+ def run()
17
+ set_product_name
18
+ set_version
19
+ select_cpe
20
+ present_cve_list
21
+ end
22
+
23
+ def set_product_name
24
+ @product = @product || @io.request('Product name:')
25
+ end
26
+
27
+ def set_version
28
+ @version = @version || @io.request('Version number:')
29
+ end
30
+
31
+ def select_cpe
32
+ puts "Searching CPE Dictionary for : #{@product} v#{@version} ...\n--\n"
33
+
34
+ cpe_list = NVDHelper.cpe_list_for(@product, @version)
35
+
36
+ if cpe_list.count > 0
37
+ puts "Please select a product:\n\n"
38
+ cpe_list.each_with_index do |cve, i|
39
+ puts "#{i}: #{cve[:title]} (#{cve[:cpe_name]}"
40
+ end
41
+ puts "X: eXit and try again.\n\n"
42
+ else
43
+ puts "Unable to locate any entries for #{@product} v#{@version} in the CPE Dictionary."
44
+ puts 'Please try again.'
45
+ exit 0
46
+ end
47
+
48
+ case index = @io.request_from_range(0..(cpe_list.count - 1))
49
+ when "X"
50
+ exit 0
51
+ else
52
+ @cpe_title = cpe_list[index.to_i][:title]
53
+ @cpe_name = cpe_list[index.to_i][:cpe_name]
54
+ end
55
+
56
+ end
57
+
58
+ def present_cve_list
59
+ cve_list = NVDHelper.cve_list_for(@cpe_name)
60
+
61
+ puts "\n--\nSearching Nist National Vulnerability Database for #{@cpe_title}\n\n"
62
+ case cve_list.count
63
+ when 0
64
+ puts "Unable to located any CVEs for #{@product} v#{@version}."
65
+ when 1
66
+ puts "The following CVE is associated with #{@product} v#{@version}:\n\n"
67
+ puts cve_list.map { |cve| "https://nvd.nist.gov/vuln/detail/#{cve}" }
68
+ else
69
+ puts "The following CVEs are associated with #{@product} v#{@version}:\n\n"
70
+ puts cve_list.map { |cve| "https://nvd.nist.gov/vuln/detail/#{cve}" }
71
+ end
72
+ end
73
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cve
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.2
5
+ platform: ruby
6
+ authors:
7
+ - Gerald Hilts
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2024-10-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gems
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.2'
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.2.0
23
+ type: :runtime
24
+ prerelease: false
25
+ version_requirements: !ruby/object:Gem::Requirement
26
+ requirements:
27
+ - - "~>"
28
+ - !ruby/object:Gem::Version
29
+ version: '1.2'
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: 1.2.0
33
+ - !ruby/object:Gem::Dependency
34
+ name: httparty
35
+ requirement: !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - "~>"
38
+ - !ruby/object:Gem::Version
39
+ version: '0.22'
40
+ - - ">="
41
+ - !ruby/object:Gem::Version
42
+ version: 0.22.0
43
+ type: :runtime
44
+ prerelease: false
45
+ version_requirements: !ruby/object:Gem::Requirement
46
+ requirements:
47
+ - - "~>"
48
+ - !ruby/object:Gem::Version
49
+ version: '0.22'
50
+ - - ">="
51
+ - !ruby/object:Gem::Version
52
+ version: 0.22.0
53
+ description: Command-line tool to search the NIST National Vulnerability Database
54
+ for CVE reports associated with a specific product and version.
55
+ email:
56
+ - gwhilts@booknowl.com
57
+ executables:
58
+ - cve
59
+ extensions: []
60
+ extra_rdoc_files: []
61
+ files:
62
+ - Gemfile
63
+ - README.md
64
+ - Rakefile
65
+ - bin/cve
66
+ - lib/io_helper.rb
67
+ - lib/legal_helper.rb
68
+ - lib/nvd_helper.rb
69
+ - lib/search.rb
70
+ homepage: https://github.com/gwhilts/cve
71
+ licenses:
72
+ - MIT
73
+ metadata: {}
74
+ post_install_message:
75
+ rdoc_options: []
76
+ require_paths:
77
+ - lib
78
+ required_ruby_version: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - ">="
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ required_rubygems_version: !ruby/object:Gem::Requirement
84
+ requirements:
85
+ - - ">="
86
+ - !ruby/object:Gem::Version
87
+ version: '0'
88
+ requirements: []
89
+ rubygems_version: 3.5.20
90
+ signing_key:
91
+ specification_version: 4
92
+ summary: CVE Lookup Utility
93
+ test_files: []