Files
SecGen/lib/objects/vulnerability.rb

71 lines
2.3 KiB
Ruby

require_relative('../constants.rb')
class Vulnerability
attr_accessor :type, :privilege, :access ,:puppets, :details, :ports, :name, :cve, :files, :scripts, :platform, :difficulty, :cvss_rating, :cvss_score, :vector_string
def initialize(type='', privilege='', access='', puppets=[], details='', ports=[], platform ='', name='', cve='', files=[], scripts=[], difficulty ='', cvss_rating='', cvss_score='',vector_string='')
@type = type
@privilege = privilege
@access = access
@puppets = puppets
@details = details
@ports = ports
@platform = platform
@name = name
@cve = cve
@files = files
@scripts = scripts
@difficulty = difficulty
@cvss_rating = cvss_rating
@cvss_score = cvss_score
@vector_string = vector_string
# Base Vector String:
# Example 1: 'AV:L/AC:H/Au:N/C:N/I:P/A:C'
# Access Vector: L = Local access, A = adjacent access, N = network access
# Access Complexity: H = High, M = Medium, L = Low
# Authentication: N = None required, S = Single instance, M = Multi instance
# Confidentiality Impact: N = None, P = Partial, C = Complete
# Integrity Impact: N = None, P = Partial, C = Complete
# Availabiliy Impact: N = None, P = Partial, C = Complete
end
def eql? other
# checks if type matches vulns.xml from scenario.xml
other.kind_of?(self.class) && @type == other.type
end
def id
return @type + @privilege + @access
end
def vulnerability_path
return "#{ROOT_DIR}/modules/vulnerabilities/#{@platform}/#{@type}/#{@name}"
end
def puppet_path
return vulnerability_path + '/puppet'
end
def is_vector_populated
return vector_string.length > 0
end
#
def get_vector_hash
base_vector_string = vector_string # for example: "AV:L/AC:H/Au:N/C:N/I:P/A:C"
base_vector_array = base_vector_string.split('/') # split to get: ['AV:L', 'AC:H', 'Au:N','C:N', 'I:P', 'A:C']
# convert this into a hash map
base_vector_hash = {}
for vector_element_string in base_vector_array
vector_element_array = vector_element_string.split(':')
if vector_element_array[1] != nil
base_vector_hash.store(vector_element_array[0], vector_element_array[1])
end
end
return base_vector_hash
end
end