From ea573072c8a8c4e03c90d7df2ea0504bb8d4fc55 Mon Sep 17 00:00:00 2001 From: thomashaw Date: Fri, 26 Feb 2016 18:27:33 +0000 Subject: [PATCH] vulnerability helper + change to vagrant base --- lib/helpers/vulnerability_helper.rb | 19 +++++++++++++++++++ lib/helpers/vulnerability_processor.rb | 19 +++++-------------- lib/objects/vulnerability.rb | 14 +++++++++++++- lib/templates/vagrantbase.erb | 4 ++-- 4 files changed, 39 insertions(+), 17 deletions(-) create mode 100644 lib/helpers/vulnerability_helper.rb diff --git a/lib/helpers/vulnerability_helper.rb b/lib/helpers/vulnerability_helper.rb new file mode 100644 index 000000000..71f6514c6 --- /dev/null +++ b/lib/helpers/vulnerability_helper.rb @@ -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 \ No newline at end of file diff --git a/lib/helpers/vulnerability_processor.rb b/lib/helpers/vulnerability_processor.rb index 09509e123..73affc24e 100644 --- a/lib/helpers/vulnerability_processor.rb +++ b/lib/helpers/vulnerability_processor.rb @@ -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 \ No newline at end of file diff --git a/lib/objects/vulnerability.rb b/lib/objects/vulnerability.rb index 372066e0c..d518fb348 100644 --- a/lib/objects/vulnerability.rb +++ b/lib/objects/vulnerability.rb @@ -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 diff --git a/lib/templates/vagrantbase.erb b/lib/templates/vagrantbase.erb index 3f5fdcb47..6e9dbbe61 100644 --- a/lib/templates/vagrantbase.erb +++ b/lib/templates/vagrantbase.erb @@ -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 %>