reorganize directory structure
This commit is contained in:
parent
588ffa593b
commit
04ce52f2cf
49 changed files with 0 additions and 1311053 deletions
|
@ -1,64 +0,0 @@
|
|||
# frozen_string_literal: true
|
||||
|
||||
require 'json'
|
||||
require 'rest-client'
|
||||
|
||||
class OvalStreamDataParser
|
||||
attr_accessor :index_data, :api_url
|
||||
|
||||
def initialize
|
||||
@api_url = 'https://access.redhat.com/hydra/rest/securitydata/oval'
|
||||
@index_data = refresh_index
|
||||
end
|
||||
|
||||
def refresh_index
|
||||
response = RestClient::Request.execute(
|
||||
method: :get,
|
||||
url: "#{api_url}/ovalstreams.json",
|
||||
content_type: 'application/json'
|
||||
)
|
||||
if response.code == 200
|
||||
parse_index(response)
|
||||
else
|
||||
puts "Error: HTTP Response code #{response.code} received."
|
||||
end
|
||||
end
|
||||
|
||||
def parse_index(response)
|
||||
JSON.parse(response.body)
|
||||
end
|
||||
|
||||
def list_stream_names
|
||||
index_data.map do |entry|
|
||||
entry['stream']
|
||||
end.sort
|
||||
end
|
||||
|
||||
def list_stream_urls
|
||||
index_data.map do |entry|
|
||||
entry['resourceUrl']
|
||||
end.sort
|
||||
end
|
||||
|
||||
def list_stream_labels
|
||||
index_data.map do |entry|
|
||||
entry['label']
|
||||
end.sort
|
||||
end
|
||||
|
||||
def select_stream_by_label(label)
|
||||
index_data.select { |json| json['label'] == label }
|
||||
end
|
||||
|
||||
def verify_shasum
|
||||
# method that will check the sha256sum of a downloaded file from resourceUrl and ensure they match
|
||||
# step 1:
|
||||
# get original shasum
|
||||
# step 2:
|
||||
# download file
|
||||
# step 3:
|
||||
# run sha256sum against file download
|
||||
# step 4:
|
||||
# run == logic against both sums and return true/false
|
||||
end
|
||||
end
|
File diff suppressed because one or more lines are too long
|
@ -1,5 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# do a fresh pull of the data
|
||||
# the class should also do this when initialized but if you want a seperate script to run quick just to pull you can use this
|
||||
|
||||
wget https://access.redhat.com/hydra/rest/securitydata/oval/ovalstreams.json
|
|
@ -1,50 +0,0 @@
|
|||
require 'ox'
|
||||
|
||||
class RhelRpmToCve
|
||||
# filepath == /path/to/rpm-to-cve.xml
|
||||
attr_accessor :filepath, :file, :xml
|
||||
|
||||
def initialize(filepath)
|
||||
@filepath = filepath
|
||||
@file = File.read(filepath)
|
||||
@xml = Ox.parse(file)
|
||||
end
|
||||
|
||||
def list_pkg_names
|
||||
xml.rpms.locate("?/@rpm")
|
||||
end
|
||||
|
||||
def pkg_exists?(pkg_name)
|
||||
list_pkg_names.include? pkg_name
|
||||
end
|
||||
|
||||
def cves_per_pkg_name(pkg_name)
|
||||
if pkg_exists? pkg_name
|
||||
results = find_pkg(pkg_name).locate('*/cve').map do |r|
|
||||
r.text
|
||||
end.compact
|
||||
|
||||
cves = results.map {|cve| cve}
|
||||
|
||||
{
|
||||
:rhel_package_name => pkg_name,
|
||||
:cves => cves,
|
||||
:cve_count => cves.count
|
||||
}
|
||||
else
|
||||
'Package not found.'
|
||||
end
|
||||
end
|
||||
|
||||
def find_pkg(pkg_name)
|
||||
xml.rpms.locate("rpm[@rpm=#{pkg_name}]").first
|
||||
end
|
||||
|
||||
def convert_to_json
|
||||
pkgs = list_pkg_names
|
||||
pkgs_and_cves = pkgs.map do |pkg_name|
|
||||
cves_per_pkg_name(pkg_name)
|
||||
end
|
||||
pkgs_and_cves.to_json
|
||||
end
|
||||
end
|
File diff suppressed because it is too large
Load diff
|
@ -1,32 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
# frozen_string_literal: true
|
||||
|
||||
require 'optparse'
|
||||
require 'json'
|
||||
require './rhel_rpm_to_cve'
|
||||
|
||||
data_file = './rpm-to-cve.xml'
|
||||
|
||||
options = {}
|
||||
|
||||
parser = OptionParser.new do |parser|
|
||||
parser.banner = 'Usage: rpm_pkg_audit.rb [options]'
|
||||
parser.on('-p', '--pkg PKGNAME', 'The pkg name you want to audit.') do |pkg|
|
||||
options[:pkg] = pkg
|
||||
end
|
||||
parser.on('-l', '--list', 'List packages in the XML datafile.') do |list|
|
||||
options[:list] = list
|
||||
end
|
||||
end
|
||||
|
||||
parser.parse!
|
||||
|
||||
pkg_name = options[:pkg]
|
||||
rpm_auditer = RhelRpmToCve.new(data_file)
|
||||
|
||||
if pkg_name
|
||||
json = rpm_auditer.cves_per_pkg_name(pkg_name).to_json
|
||||
puts JSON.pretty_generate(JSON.parse(json))
|
||||
else options.key?(:list)
|
||||
puts rpm_auditer.list_pkg_names.sort
|
||||
end
|
|
@ -1,36 +0,0 @@
|
|||
#!/usr/bin/env ruby
|
||||
|
||||
require 'ox'
|
||||
|
||||
class SaxParser < Ox::Sax
|
||||
|
||||
def initialize
|
||||
@elements = []
|
||||
end
|
||||
|
||||
def start_element(name)
|
||||
#puts "start: #{name}"
|
||||
end
|
||||
|
||||
def current_element
|
||||
@elements.last
|
||||
end
|
||||
|
||||
def end_element(name)
|
||||
#puts "end: #{name}"
|
||||
end
|
||||
|
||||
def attr(name, value)
|
||||
#puts " #{name} => #{value}"
|
||||
end
|
||||
|
||||
def text(value)
|
||||
#puts "text: #{value}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
file = File.read('./rpm-to-cve.xml')
|
||||
handler = SaxParser.new()
|
||||
|
||||
Ox.sax_parse(handler, file)
|
|
@ -1,4 +0,0 @@
|
|||
#!/usr/bin/env bash
|
||||
# refresh the latest rpm to cve xml mapping file from redhat security page
|
||||
|
||||
wget https://www.redhat.com/security/data/metrics/rpm-to-cve.xml .
|
Loading…
Add table
Reference in a new issue