vulnerability helper + change to vagrant base

This commit is contained in:
thomashaw
2016-02-26 18:27:33 +00:00
parent c000404a3a
commit ea573072c8
4 changed files with 39 additions and 17 deletions

View File

@@ -0,0 +1,19 @@
require_relative '../objects/vulnerability.rb'
require_relative '../constants.rb'
class VulnerabilityHelper
def getVulnerabilityObject(vulnerability_hash)
return Vulnerability.new(
vulnerability_hash['type'],
vulnerability_hash['privilege'],
vulnerability_hash['access'],
vulnerability_hash['puppets'],
vulnerability_hash['details'],
vulnerability_hash['ports'],
vulnerability_hash['platform'],
vulnerability_hash['name'],
vulnerability_hash['cve'],
vulnerability_hash['files'],
vulnerability_hash['scripts'])
end
end

View File

@@ -1,9 +1,13 @@
require_relative '../../lib/constants' #CW - Could this only be included in secgen.rb and have the constants initialized at runtime?
require_relative '../../lib/objects/vulnerability'
require_relative 'vulnerability_helper'
require 'nokogiri'
require 'xmlsimple'
class VulnerabilityProcessor
def initialize()
@vulnerability_helper = VulnerabilityHelper.new
end
# returns a hash of compatible vulnerabilities based on what is provided in scenario.xml (scenario_vulns)
# based on the attributes optionally specified in scenario.xml (scenario_vulns)
def process(scenario_vulns)
@@ -56,23 +60,10 @@ class VulnerabilityProcessor
vulnerabilities = []
Dir.glob("#{ROOT_DIR}/modules/vulnerabilities/**/**/secgen_metadata.xml").each do |file|
vulnerability_hash = XmlSimple.xml_in(file, {})
vulnerability = convert_vulnerability_hash_to_vulnerability_object(vulnerability_hash)
vulnerability = @vulnerability_helper.getVulnerabilityObject(vulnerability_hash)
vulnerabilities.push(vulnerability)
end
return vulnerabilities
end
def convert_vulnerability_hash_to_vulnerability_object(vulnerability_hash)
return Vulnerability.new(
vulnerability_hash['type'],
vulnerability_hash['privilege'],
vulnerability_hash['access'],
vulnerability_hash['puppets'],
vulnerability_hash['details'],
vulnerability_hash['ports'],
vulnerability_hash['cve'],
vulnerability_hash['files'],
vulnerability_hash['scripts'])
end
end

View File

@@ -1,3 +1,5 @@
require_relative('../constants.rb')
class Vulnerability
attr_accessor :type, :privilege, :access ,:puppets, :details, :ports, :cve, :files, :scripts
@@ -6,13 +8,15 @@ class Vulnerability
other.kind_of?(self.class) && @type == other.type
end
def initialize(type="", privilege="", access="", puppets=[], details="", ports=[], cve="", files=[], scripts=[])
def initialize(type='', privilege='', access='', puppets=[], details='', ports=[], platform ='', name='', cve='', files=[], scripts=[])
@type = type
@privilege = privilege
@access = access
@puppets = puppets
@details = details
@ports = ports
@platform = platform
@name = name
@cve = cve
@files = files
@scripts = scripts
@@ -22,4 +26,12 @@ class Vulnerability
return @type + @privilege + @access
end
def vulnerability_path
return ROOT_DIR + '/modules/' + @type + @name
end
def puppet_path
return vulnerability_path + '/puppet/'
end
end

View File

@@ -35,8 +35,8 @@ Vagrant.configure(VAGRANTFILE_API_VERSION) do |config|
<%s.vulns.each do |v|%>
<%v.puppets.each do |p|%>
config.vm.provision "puppet" do |<%=p%>|
<%=p%>.module_path = "<%=ROOT_DIR%>/mount/puppet/modules"
<%=p%>.manifests_path = "<%=ROOT_DIR%>/mount/puppet/manifests"
<%=p%>.module_path = <%=v%>.pupet_path/modules
<%=p%>.manifests_path = <%=v%>.puppet_path/manifests"
<%=p%>.manifest_file = "<%=p%>.pp"
end
<% end %>