heimdall_tools 1.3.29 → 1.3.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -53,9 +53,10 @@ module HeimdallTools
53
53
  def nessus_mapper
54
54
  hdfs = HeimdallTools::NessusMapper.new(File.read(options[:xml])).to_hdf
55
55
 
56
+ puts "\nHDF Generated:"
56
57
  hdfs.keys.each do | host |
57
58
  File.write("#{options[:output_prefix]}-#{host}.json", hdfs[host])
58
- puts "HDF Generated: #{options[:output_prefix]}-#{host}.json"
59
+ puts "#{options[:output_prefix]}-#{host}.json"
59
60
  end
60
61
 
61
62
  end
@@ -2,10 +2,13 @@ require 'json'
2
2
  require 'csv'
3
3
  require 'heimdall_tools/hdf'
4
4
  require 'utilities/xml_to_hash'
5
+ require 'nokogiri'
6
+ require 'pp'
5
7
 
6
8
  RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
7
9
 
8
10
  NESSUS_PLUGINS_NIST_MAPPING_FILE = File.join(RESOURCE_DIR, 'nessus-plugins-nist-mapping.csv')
11
+ U_CCI_LIST = File.join(RESOURCE_DIR, 'U_CCI_List.xml')
9
12
 
10
13
  IMPACT_MAPPING = {
11
14
  Info: 0.0,
@@ -25,12 +28,22 @@ NA_PLUGIN_OUTPUT = "This Nessus Plugin does not provide output message.".freeze
25
28
 
26
29
  # rubocop:disable Metrics/AbcSize
27
30
 
31
+ # Loading spinner sign
32
+ $spinner = Enumerator.new do |e|
33
+ loop do
34
+ e.yield '|'
35
+ e.yield '/'
36
+ e.yield '-'
37
+ e.yield '\\'
38
+ end
39
+ end
40
+
28
41
  module HeimdallTools
29
42
  class NessusMapper
30
43
  def initialize(nessus_xml, verbose = false)
31
44
  @nessus_xml = nessus_xml
32
45
  @verbose = verbose
33
-
46
+ read_cci_xml
34
47
  begin
35
48
  @cwe_nist_mapping = parse_mapper
36
49
  @data = xml_to_hash(nessus_xml)
@@ -53,6 +66,7 @@ module HeimdallTools
53
66
  raise "Invalid Nessus XML file provided Exception: #{e}"
54
67
  end
55
68
  end
69
+
56
70
  def parse_refs(refs, key)
57
71
  refs.split(',').map { |x| x.split('|')[1] if x.include?(key) }.compact
58
72
  end
@@ -107,7 +121,29 @@ module HeimdallTools
107
121
  [finding]
108
122
  end
109
123
 
110
- def nist_tag(pluginfamily, pluginid)
124
+ def read_cci_xml
125
+ cci_list_path = File.join(File.dirname(__FILE__), '../data/U_CCI_List.xml')
126
+ @cci_xml = Nokogiri::XML(File.open(cci_list_path))
127
+ @cci_xml.remove_namespaces!
128
+ rescue StandardError => e
129
+ puts "Exception: #{e.message}"
130
+ end
131
+
132
+ def cci_nist_tag(cci_refs)
133
+ nist_tags = []
134
+ cci_refs.each do | cci_ref |
135
+ item_node = @cci_xml.xpath("//cci_list/cci_items/cci_item[@id='#{cci_ref}']")[0] unless @cci_xml.nil?
136
+ unless item_node.nil?
137
+ nist_ref = item_node.xpath('./references/reference[not(@version <= preceding-sibling::reference/@version) and not(@version <=following-sibling::reference/@version)]/@index').text
138
+ nist_ver = item_node.xpath('./references/reference[not(@version <= preceding-sibling::reference/@version) and not(@version <=following-sibling::reference/@version)]/@version').text
139
+ end
140
+ nist_tags << nist_ref
141
+ nist_tags << "Rev_#{nist_ver}"
142
+ end
143
+ nist_tags
144
+ end
145
+
146
+ def plugin_nist_tag(pluginfamily, pluginid)
111
147
  entries = @cwe_nist_mapping.select { |x| (x[:pluginfamily].eql?(pluginfamily) && (x[:pluginid].eql?('*') || x[:pluginid].eql?(pluginid.to_i)) ) }
112
148
  tags = entries.map { |x| [x[:nistid].split('|'), "Rev_#{x[:rev]}"] }
113
149
  tags.empty? ? DEFAULT_NIST_TAG : tags.flatten.uniq
@@ -163,6 +199,7 @@ module HeimdallTools
163
199
  @reports.each do | report|
164
200
  controls = []
165
201
  report['ReportItem'].each do | item |
202
+ printf("\rProcessing: %s", $spinner.next)
166
203
  @item = {}
167
204
  @item['tags'] = {}
168
205
  @item['descriptions'] = []
@@ -194,16 +231,9 @@ module HeimdallTools
194
231
  @item['impact'] = impact(item['severity'])
195
232
  end
196
233
  if item['compliance-reference']
197
- # TODO: Cover cases where 800-53 refs are not provided in nessus `compliance-reference` field
198
- @item['tags']['nist'] = parse_refs(item['compliance-reference'],'800-53') << DEFAULT_NIST_REV
199
- else
200
- @item['tags']['nist'] = nist_tag(item['pluginFamily'],item['pluginID'])
201
- end
202
- if item['compliance-solution']
203
- # TODO: Cover cases where 800-53 refs are not provided in nessus `compliance-reference` field
204
- @item['tags']['nist'] = parse_refs(item['compliance-reference'],'800-53') << DEFAULT_NIST_REV
234
+ @item['tags']['nist'] = cci_nist_tag(parse_refs(item['compliance-reference'],'CCI'))
205
235
  else
206
- @item['tags']['nist'] = nist_tag(item['pluginFamily'],item['pluginID'])
236
+ @item['tags']['nist'] = plugin_nist_tag(item['pluginFamily'],item['pluginID'])
207
237
  end
208
238
  if item['compliance-solution']
209
239
  @item['descriptions'] << desc_tags(item['compliance-solution'], 'check')
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdall_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.29
4
+ version: 1.3.30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Thew
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-05-28 00:00:00.000000000 Z
13
+ date: 2020-06-12 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: nokogiri
@@ -209,8 +209,8 @@ files:
209
209
  - README.md
210
210
  - Rakefile
211
211
  - exe/heimdall_tools
212
+ - lib/data/U_CCI_List.xml
212
213
  - lib/data/cwe-nist-mapping.csv
213
- - lib/data/gitkeep
214
214
  - lib/data/nessus-plugins-nist-mapping.csv
215
215
  - lib/data/owasp-nist-mapping.csv
216
216
  - lib/heimdall_tools.rb
File without changes