added more to nvd downloader and made a cve reporter that will query it
This commit is contained in:
parent
07ba0f4fc9
commit
1006b33c64
3 changed files with 49 additions and 14 deletions
|
@ -1,4 +1,16 @@
|
|||
class CveInfo
|
||||
def initialize
|
||||
class CveReport
|
||||
|
||||
def cves
|
||||
# return a list of cve data from the given filename in an array.
|
||||
self.from_file(filename)
|
||||
end
|
||||
|
||||
def from_file(filename)
|
||||
# lookup info from the given json.gz filename of cve information.
|
||||
end
|
||||
|
||||
def find(cve_id)
|
||||
# this should look in the returned array of cve information from self.cves
|
||||
# and return the given information for the cve_id
|
||||
end
|
||||
end
|
17
classes/nvd_client.rb
Normal file
17
classes/nvd_client.rb
Normal file
|
@ -0,0 +1,17 @@
|
|||
require '../modules/nvd_tools'
|
||||
require 'rest-client'
|
||||
|
||||
module NvdTools
|
||||
class NvdClient
|
||||
attr_accessor :version, :base_url, :rest_client
|
||||
def initialize(rest_client: RestClient)
|
||||
@version = "1.0"
|
||||
@base_url = "https://nvd.nist.gov/feeds/json/cve/#{version}/"
|
||||
@rest_client = rest_client
|
||||
end
|
||||
|
||||
def get(url)
|
||||
rest_client.get "#{base_url}#{url}"
|
||||
end
|
||||
end
|
||||
end
|
|
@ -5,19 +5,19 @@ require '../modules/nvd_tools'
|
|||
|
||||
module NvdTools
|
||||
class NvdDownloader
|
||||
attr_accessor :version, :base_url, :base_filename, :years, :filenames_json
|
||||
attr_accessor :version, :base_url, :base_filename, :years, :filenames_json, :client
|
||||
|
||||
MIN_YEAR = '2002'
|
||||
MAX_YEAR = '2019'
|
||||
AVAILABLE_YEARS = (MIN_YEAR..MAX_YEAR).to_a
|
||||
JSON = 'json.gz'
|
||||
GZIPPED_JSON_EXTENSION = 'json.gz'
|
||||
|
||||
def initialize
|
||||
@version = "1.0"
|
||||
@base_url = "https://nvd.nist.gov/feeds/json/cve/#{version}/"
|
||||
@base_filename = "nvdcve-#{version}-"
|
||||
def initialize(client: NvdClient.new)
|
||||
|
||||
@base_filename = "nvdcve-#{client.version}-"
|
||||
@years = self.years
|
||||
@filenames_json = self.filenames(JSON)
|
||||
@filenames_json = self.filenames(GZIPPED_JSON_EXTENSION)
|
||||
@client = client
|
||||
end
|
||||
|
||||
def years
|
||||
|
@ -39,11 +39,6 @@ module NvdTools
|
|||
year_filenames + other_filenames
|
||||
end
|
||||
|
||||
def get(url)
|
||||
r = RestClient.get "#{base_url}#{url}"
|
||||
r.body if r.code == 200
|
||||
end
|
||||
|
||||
def read_gzip_stream(gzip_stream)
|
||||
io_stream = StringIO.new(gzip_stream)
|
||||
gz = Zlib::GzipReader.new(io_stream)
|
||||
|
@ -59,6 +54,17 @@ module NvdTools
|
|||
end
|
||||
|
||||
def one_time_import
|
||||
# experimenting with how i want to do this.
|
||||
# right now its a loop through the filenames
|
||||
# and parse all into a json string and store in an array
|
||||
self.filenames_json.map do |filename|
|
||||
r = client.get(filename)
|
||||
sleep(1)
|
||||
|
||||
gzip_stream = r.body
|
||||
json_string = read_gzip_stream(gzip_stream)
|
||||
parse_json(json_string)
|
||||
end
|
||||
# this should be a method that does a one-time import
|
||||
# of all of the json.gz from each year + recent + modified json feeds
|
||||
end
|
||||
|
|
Loading…
Add table
Reference in a new issue