heimdall_tools 1.3.46 → 1.3.50

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,161 @@
1
+ require 'json'
2
+ require 'csv'
3
+ require 'heimdall_tools/hdf'
4
+ require 'utilities/xml_to_hash'
5
+ require 'nokogiri'
6
+
7
+ RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
8
+
9
+ # XCCDF mapping for converting SCAP client (SCC or OpenSCAP) outputs to HDF
10
+ # SCC output from the RHEL7 Lockdown image was used for testing
11
+
12
+ U_CCI_LIST = File.join(RESOURCE_DIR, 'U_CCI_List.xml')
13
+
14
+ IMPACT_MAPPING = {
15
+ critical: 0.9,
16
+ high: 0.7,
17
+ medium: 0.5,
18
+ low: 0.3,
19
+ na: 0.0
20
+ }.freeze
21
+
22
+ # severity maps to high, medium, low with weights all being 10.0 from the xml
23
+ # it doesn't really look like SCAP or SCC cares about that value, just if its high, med, or low
24
+
25
+ CWE_REGEX = 'CWE-(\d*):'.freeze
26
+ CCI_REGEX = 'CCI-(\d*)'.freeze
27
+
28
+ DEFAULT_NIST_TAG = %w{SA-11 RA-5 Rev_4}.freeze
29
+
30
+ module HeimdallTools
31
+ class XCCDFResultsMapper
32
+ def initialize(scap_xml, _name = nil)
33
+ @scap_xml = scap_xml
34
+ read_cci_xml
35
+ begin
36
+ data = xml_to_hash(scap_xml)
37
+ @results = data['Benchmark']['TestResult']
38
+ @benchmarks = data['Benchmark']
39
+ @groups = data['Benchmark']['Group']
40
+ rescue StandardError => e
41
+ raise "Invalid SCAP Client XCCDF output XML file provided Exception: #{e}"
42
+ end
43
+ end
44
+
45
+ # change for pass/fail based on output Benchmark.rule
46
+ # Pass/Fail are the only two options included in the output file
47
+ def finding(issue, count)
48
+ finding = {}
49
+ finding['status'] = issue['rule-result'][count]['result'].to_s
50
+ if finding['status'] == 'pass'
51
+ finding['status'] = 'passed'
52
+ end
53
+ if finding['status'] == 'fail'
54
+ finding['status'] = 'failed'
55
+ end
56
+ finding['code_desc'] = NA_STRING
57
+ finding['run_time'] = NA_FLOAT
58
+ finding['start_time'] = issue['start-time']
59
+ finding['message'] = NA_STRING
60
+ finding['resource_class'] = NA_STRING
61
+ [finding]
62
+ end
63
+
64
+ def read_cci_xml
65
+ @cci_xml = Nokogiri::XML(File.open(U_CCI_LIST))
66
+ @cci_xml.remove_namespaces!
67
+ rescue StandardError => e
68
+ puts "Exception: #{e.message}"
69
+ end
70
+
71
+ def cci_nist_tag(cci_refs)
72
+ nist_tags = []
73
+ cci_refs.each do |cci_ref|
74
+ item_node = @cci_xml.xpath("//cci_list/cci_items/cci_item[@id='#{cci_ref}']")[0] unless @cci_xml.nil?
75
+ unless item_node.nil?
76
+ nist_ref = item_node.xpath('./references/reference[not(@version <= preceding-sibling::reference/@version) and not(@version <=following-sibling::reference/@version)]/@index').text
77
+ end
78
+ nist_tags << nist_ref
79
+ end
80
+ nist_tags
81
+ end
82
+
83
+ def get_impact(severity)
84
+ IMPACT_MAPPING[severity.to_sym]
85
+ end
86
+
87
+ def parse_refs(refs)
88
+ refs.map { |ref| ref['text'] if ref['text'].match?(CCI_REGEX) }.reject!(&:nil?)
89
+ end
90
+
91
+ # Clean up output by removing the Satsifies block and the end of the description
92
+ def satisfies_parse(satisf)
93
+ temp_satisf = satisf.match('Satisfies: ([^;]*)<\/VulnDiscussion>')
94
+ return temp_satisf[1].split(',') unless temp_satisf.nil?
95
+
96
+ NA_ARRAY
97
+ end
98
+
99
+ def desc_tags(data, label)
100
+ { data: data || NA_STRING, label: label || NA_STRING }
101
+ end
102
+
103
+ def collapse_duplicates(controls)
104
+ unique_controls = []
105
+
106
+ controls.map { |x| x['id'] }.uniq.each do |id|
107
+ collapsed_results = controls.select { |x| x['id'].eql?(id) }.map { |x| x['results'] }
108
+ unique_control = controls.find { |x| x['id'].eql?(id) }
109
+ unique_control['results'] = collapsed_results.flatten
110
+ unique_controls << unique_control
111
+ end
112
+ unique_controls
113
+ end
114
+
115
+ def to_hdf
116
+ controls = []
117
+ @groups.each_with_index do |group, i|
118
+ @item = {}
119
+ @item['id'] = group['Rule']['id'].split('.').last.split('_').drop(2).first.split('r').first.split('S')[1]
120
+ @item['title'] = group['Rule']['title'].to_s
121
+ @item['desc'] = group['Rule']['description'].to_s.split('Satisfies').first
122
+ @item['descriptions'] = []
123
+ @item['descriptions'] << desc_tags(group['Rule']['description'], 'default')
124
+ @item['descriptions'] << desc_tags('NA', 'rationale')
125
+ @item['descriptions'] << desc_tags(group['Rule']['check']['check-content-ref']['name'], 'check')
126
+ @item['descriptions'] << desc_tags(group['Rule']['fixtext']['text'], 'fix')
127
+ @item['impact'] = get_impact(group['Rule']['severity'])
128
+ @item['refs'] = NA_ARRAY
129
+ @item['tags'] = {}
130
+ @item['tags']['severity'] = nil
131
+ @item['tags']['gtitle'] = group['title']
132
+ @item['tags']['satisfies'] = satisfies_parse(group['Rule']['description'])
133
+ @item['tags']['gid'] = group['Rule']['id'].split('.').last.split('_').drop(2).first.split('r').first
134
+ @item['tags']['legacy_id'] = group['Rule']['ident'][2]['text']
135
+ @item['tags']['rid'] = group['Rule']['ident'][1]['text']
136
+ @item['tags']['stig_id'] = @benchmarks['id']
137
+ @item['tags']['fix_id'] = group['Rule']['fix']['id']
138
+ @item['tags']['cci'] = parse_refs(group['Rule']['ident'])
139
+ @item['tags']['nist'] = cci_nist_tag(@item['tags']['cci'])
140
+ @item['code'] = NA_STRING
141
+ @item['source_location'] = NA_HASH
142
+ # results were in another location and using the top block "Benchmark" as a starting point caused odd issues. This works for now for the results.
143
+ @item['results'] = finding(@results, i)
144
+ controls << @item
145
+ end
146
+
147
+ controls = collapse_duplicates(controls)
148
+ results = HeimdallDataFormat.new(profile_name: @benchmarks['id'],
149
+ version: @benchmarks['style'],
150
+ duration: NA_FLOAT,
151
+ title: @benchmarks['title'],
152
+ maintainer: @benchmarks['reference']['publisher'],
153
+ summary: @benchmarks['description'],
154
+ license: @benchmarks['notice']['id'],
155
+ copyright: @benchmarks['metadata']['creator'],
156
+ copyright_email: 'disa.stig_spt@mail.mil',
157
+ controls: controls)
158
+ results.to_hdf
159
+ end
160
+ end
161
+ end
@@ -1,5 +1,6 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(__dir__))
2
2
  require 'heimdall_tools/version'
3
+ puts "NOTICE: The heimdall_tools Ruby gem is deprecated. Please see instructions on how to convert to the new TypeScript SAF CLI. https://github.com/mitre/saf\n\n"
3
4
 
4
5
  module HeimdallTools
5
6
  autoload :Help, 'heimdall_tools/help'
@@ -18,4 +19,7 @@ module HeimdallTools
18
19
  autoload :NetsparkerMapper, 'heimdall_tools/netsparker_mapper'
19
20
  autoload :SarifMapper, 'heimdall_tools/sarif_mapper'
20
21
  autoload :ScoutSuiteMapper, 'heimdall_tools/scoutsuite_mapper'
22
+ autoload :XCCDFResultsMapper, 'heimdall_tools/xccdf_results_mapper'
23
+ autoload :ASFFMapper, 'heimdall_tools/asff_mapper'
24
+ autoload :ProwlerMapper, 'heimdall_tools/prowler_mapper'
21
25
  end
metadata CHANGED
@@ -1,16 +1,17 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: heimdall_tools
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.3.46
4
+ version: 1.3.50
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Thew
8
8
  - Rony Xavier
9
+ - Amndeep Singh Mann
9
10
  - Aaron Lippold
10
11
  autorequire:
11
12
  bindir: exe
12
13
  cert_chain: []
13
- date: 2021-05-27 00:00:00.000000000 Z
14
+ date: 2021-12-23 00:00:00.000000000 Z
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
16
17
  name: aws-sdk-configservice
@@ -26,6 +27,20 @@ dependencies:
26
27
  - - "~>"
27
28
  - !ruby/object:Gem::Version
28
29
  version: '1'
30
+ - !ruby/object:Gem::Dependency
31
+ name: aws-sdk-securityhub
32
+ requirement: !ruby/object:Gem::Requirement
33
+ requirements:
34
+ - - "~>"
35
+ - !ruby/object:Gem::Version
36
+ version: '1'
37
+ type: :runtime
38
+ prerelease: false
39
+ version_requirements: !ruby/object:Gem::Requirement
40
+ requirements:
41
+ - - "~>"
42
+ - !ruby/object:Gem::Version
43
+ version: '1'
29
44
  - !ruby/object:Gem::Dependency
30
45
  name: csv
31
46
  requirement: !ruby/object:Gem::Requirement
@@ -54,6 +69,20 @@ dependencies:
54
69
  - - ">="
55
70
  - !ruby/object:Gem::Version
56
71
  version: 0.17.2
72
+ - !ruby/object:Gem::Dependency
73
+ name: htmlentities
74
+ requirement: !ruby/object:Gem::Requirement
75
+ requirements:
76
+ - - "~>"
77
+ - !ruby/object:Gem::Version
78
+ version: 4.3.4
79
+ type: :runtime
80
+ prerelease: false
81
+ version_requirements: !ruby/object:Gem::Requirement
82
+ requirements:
83
+ - - "~>"
84
+ - !ruby/object:Gem::Version
85
+ version: 4.3.4
57
86
  - !ruby/object:Gem::Dependency
58
87
  name: httparty
59
88
  requirement: !ruby/object:Gem::Requirement
@@ -216,6 +245,10 @@ files:
216
245
  - lib/data/owasp-nist-mapping.csv
217
246
  - lib/data/scoutsuite-nist-mapping.csv
218
247
  - lib/heimdall_tools.rb
248
+ - lib/heimdall_tools/asff_compatible_products/firewall_manager.rb
249
+ - lib/heimdall_tools/asff_compatible_products/prowler.rb
250
+ - lib/heimdall_tools/asff_compatible_products/securityhub.rb
251
+ - lib/heimdall_tools/asff_mapper.rb
219
252
  - lib/heimdall_tools/aws_config_mapper.rb
220
253
  - lib/heimdall_tools/burpsuite_mapper.rb
221
254
  - lib/heimdall_tools/cli.rb
@@ -224,6 +257,7 @@ files:
224
257
  - lib/heimdall_tools/fortify_mapper.rb
225
258
  - lib/heimdall_tools/hdf.rb
226
259
  - lib/heimdall_tools/help.rb
260
+ - lib/heimdall_tools/help/asff_mapper.md
227
261
  - lib/heimdall_tools/help/aws_config_mapper.md
228
262
  - lib/heimdall_tools/help/burpsuite_mapper.md
229
263
  - lib/heimdall_tools/help/dbprotect_mapper.md
@@ -232,6 +266,7 @@ files:
232
266
  - lib/heimdall_tools/help/nessus_mapper.md
233
267
  - lib/heimdall_tools/help/netsparker_mapper.md
234
268
  - lib/heimdall_tools/help/nikto_mapper.md
269
+ - lib/heimdall_tools/help/prowler_mapper.md
235
270
  - lib/heimdall_tools/help/sarif_mapper.md
236
271
  - lib/heimdall_tools/help/scoutsuite_mapper.md
237
272
  - lib/heimdall_tools/help/snyk_mapper.md
@@ -241,11 +276,13 @@ files:
241
276
  - lib/heimdall_tools/nessus_mapper.rb
242
277
  - lib/heimdall_tools/netsparker_mapper.rb
243
278
  - lib/heimdall_tools/nikto_mapper.rb
279
+ - lib/heimdall_tools/prowler_mapper.rb
244
280
  - lib/heimdall_tools/sarif_mapper.rb
245
281
  - lib/heimdall_tools/scoutsuite_mapper.rb
246
282
  - lib/heimdall_tools/snyk_mapper.rb
247
283
  - lib/heimdall_tools/sonarqube_mapper.rb
248
284
  - lib/heimdall_tools/version.rb
285
+ - lib/heimdall_tools/xccdf_results_mapper.rb
249
286
  - lib/heimdall_tools/zap_mapper.rb
250
287
  - lib/utilities/xml_to_hash.rb
251
288
  homepage: https://github.com/mitre/heimdall_tools
@@ -267,8 +304,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
267
304
  - !ruby/object:Gem::Version
268
305
  version: '0'
269
306
  requirements: []
270
- rubygems_version: 3.2.15
307
+ rubygems_version: 3.2.32
271
308
  signing_key:
272
309
  specification_version: 4
273
- summary: Convert Forify, Openzap and Sonarqube results to HDF
310
+ summary: Convert a variety of security product results to HDF
274
311
  test_files: []