heimdall_tools 1.3.32 → 1.3.37

Sign up to get free protection for your applications and to get access to all the features.
@@ -3,6 +3,7 @@ require 'heimdall_tools/hdf'
3
3
  require 'utilities/xml_to_hash'
4
4
 
5
5
  NIST_REFERENCE_NAME = 'Standards Mapping - NIST Special Publication 800-53 Revision 4'.freeze
6
+ DEFAULT_NIST_TAG = ["SA-11", "RA-5"].freeze
6
7
 
7
8
  module HeimdallTools
8
9
  class FortifyMapper
@@ -68,7 +69,7 @@ module HeimdallTools
68
69
  references = rule['References']['Reference']
69
70
  references = [references] unless references.is_a?(Array)
70
71
  tag = references.detect { |x| x['Author'].eql?(NIST_REFERENCE_NAME) }
71
- tag.nil? ? 'unmapped' : tag['Title'].match(/[a-zA-Z][a-zA-Z]-\d{1,2}/)
72
+ tag.nil? ? DEFAULT_NIST_TAG : tag['Title'].match(/[a-zA-Z][a-zA-Z]-\d{1,2}/)
72
73
  end
73
74
 
74
75
  def impact(classid)
@@ -29,7 +29,8 @@ module HeimdallTools
29
29
  groups: NA_ARRAY,
30
30
  status: 'loaded',
31
31
  controls: NA_TAG,
32
- target_id: NA_TAG)
32
+ target_id: NA_TAG,
33
+ statistics: NA_HASH)
33
34
 
34
35
  @results_json = {}
35
36
  @results_json['platform'] = {}
@@ -40,6 +41,7 @@ module HeimdallTools
40
41
 
41
42
  @results_json['statistics'] = {}
42
43
  @results_json['statistics']['duration'] = duration || NA_TAG
44
+ @results_json['statistics'].merge! statistics
43
45
 
44
46
  @results_json['profiles'] = []
45
47
 
@@ -0,0 +1,30 @@
1
+ aws_config_mapper pulls Ruby AWS SDK data to translate AWS Config Rule results into HDF format json to be viewable in Heimdall
2
+
3
+ AWS Config Rule Mapping:
4
+ The mapping of AWS Config Rules to 800-53 Controls was sourced from [this link](https://docs.aws.amazon.com/config/latest/developerguide/operational-best-practices-for-nist-800-53_rev_4.html).
5
+
6
+ Authentication with AWS:
7
+ [Developer Guide for configuring Ruby AWS SDK for authentication](https://docs.aws.amazon.com/sdk-for-ruby/v3/developer-guide/setup-config.html)
8
+
9
+ Authentication Example:
10
+
11
+ - Create `~/.aws/credentials`
12
+ - Add contents to file, replacing with your access ID and key
13
+
14
+ ```
15
+ [default]
16
+ aws_access_key_id = your_access_key_id
17
+ aws_secret_access_key = your_secret_access_key
18
+ ```
19
+
20
+ - (optional) set AWS region through `~/.aws/config` file with contents
21
+
22
+ ```
23
+ [default]
24
+ output = json
25
+ region = us-gov-west-1
26
+ ```
27
+
28
+ Examples:
29
+
30
+ heimdall_tools aws_config_mapper -o aws_config_results.json
@@ -0,0 +1,5 @@
1
+ dbprotect_mapper translates DBProtect report in `Check Results Details` format XML to HDF format JSON be viewed on Heimdall.
2
+
3
+ Examples:
4
+
5
+ heimdall_tools dbprotect_mapper -x check_results_details_report.xml -o db_protect_hdf.json
@@ -0,0 +1,5 @@
1
+ jfrog_xray_mapper translates an JFrog Xray results JSON file into HDF format JSON to be viewable in Heimdall
2
+
3
+ Examples:
4
+
5
+ heimdall_tools jfrog_xray_mapper -j xray_results.json -o output-file-name.json
@@ -0,0 +1,7 @@
1
+ nikto_mapper translates an Nikto results JSON file into HDF format JSON to be viewable in Heimdall
2
+
3
+ Note: Current this mapper only support single target Nikto Scans.
4
+
5
+ Examples:
6
+
7
+ heimdall_tools nikto_mapper [OPTIONS] -x <nikto-results-json> -o <hdf-scan-results.json>
@@ -0,0 +1,142 @@
1
+ require 'json'
2
+ require 'csv'
3
+ require 'heimdall_tools/hdf'
4
+ require 'utilities/xml_to_hash'
5
+
6
+ RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
7
+
8
+ CWE_NIST_MAPPING_FILE = File.join(RESOURCE_DIR, 'cwe-nist-mapping.csv')
9
+
10
+ IMPACT_MAPPING = {
11
+ high: 0.7,
12
+ medium: 0.5,
13
+ low: 0.3,
14
+ }.freeze
15
+
16
+ DEFAULT_NIST_TAG = ["SA-11", "RA-5"].freeze
17
+
18
+ # Loading spinner sign
19
+ $spinner = Enumerator.new do |e|
20
+ loop do
21
+ e.yield '|'
22
+ e.yield '/'
23
+ e.yield '-'
24
+ e.yield '\\'
25
+ end
26
+ end
27
+
28
+ module HeimdallTools
29
+ class JfrogXrayMapper
30
+ def initialize(xray_json, name=nil, verbose = false)
31
+ @xray_json = xray_json
32
+ @verbose = verbose
33
+
34
+ begin
35
+ @cwe_nist_mapping = parse_mapper
36
+ @project = JSON.parse(xray_json)
37
+
38
+ rescue StandardError => e
39
+ raise "Invalid JFrog Xray JSON file provided Exception: #{e}"
40
+ end
41
+ end
42
+
43
+ def finding(vulnerability)
44
+ finding = {}
45
+ finding['status'] = 'failed'
46
+ finding['code_desc'] = []
47
+ finding['code_desc'] << "source_comp_id : #{vulnerability['source_comp_id'].to_s }"
48
+ finding['code_desc'] << "vulnerable_versions : #{vulnerability['component_versions']['vulnerable_versions'].to_s }"
49
+ finding['code_desc'] << "fixed_versions : #{vulnerability['component_versions']['fixed_versions'].to_s }"
50
+ finding['code_desc'] << "issue_type : #{vulnerability['issue_type'].to_s }"
51
+ finding['code_desc'] << "provider : #{vulnerability['provider'].to_s }"
52
+ finding['code_desc'] = finding['code_desc'].join("\n")
53
+ finding['run_time'] = NA_FLOAT
54
+
55
+ # Xray results does not profile scan timestamp; using current time to satisfy HDF format
56
+ finding['start_time'] = NA_STRING
57
+ [finding]
58
+ end
59
+
60
+ def nist_tag(cweid)
61
+ entries = @cwe_nist_mapping.select { |x| cweid.include? x[:cweid].to_s }
62
+ tags = entries.map { |x| x[:nistid] }
63
+ tags.empty? ? DEFAULT_NIST_TAG : tags.flatten.uniq
64
+ end
65
+
66
+ def parse_identifiers(vulnerability, ref)
67
+ # Extracting id number from reference style CWE-297
68
+ vulnerability['component_versions']['more_details']['cves'][0][ref.downcase].map { |e| e.split("#{ref}-")[1] }
69
+ rescue
70
+ return []
71
+ end
72
+
73
+ def impact(severity)
74
+ IMPACT_MAPPING[severity.downcase.to_sym]
75
+ end
76
+
77
+ def parse_mapper
78
+ csv_data = CSV.read(CWE_NIST_MAPPING_FILE, **{ encoding: 'UTF-8',
79
+ headers: true,
80
+ header_converters: :symbol,
81
+ converters: :all })
82
+ csv_data.map(&:to_hash)
83
+ end
84
+
85
+ def desc_tags(data, label)
86
+ { "data": data || NA_STRING, "label": label || NA_STRING }
87
+ end
88
+
89
+ # Xray report could have multiple vulnerability entries for multiple findings of same issue type.
90
+ # The meta data is identical across entries
91
+ # method collapse_duplicates return unique controls with applicable findings collapsed into it.
92
+ def collapse_duplicates(controls)
93
+ unique_controls = []
94
+
95
+ controls.map { |x| x['id'] }.uniq.each do |id|
96
+ collapsed_results = controls.select { |x| x['id'].eql?(id) }.map {|x| x['results']}
97
+ unique_control = controls.find { |x| x['id'].eql?(id) }
98
+ unique_control['results'] = collapsed_results.flatten
99
+ unique_controls << unique_control
100
+ end
101
+ unique_controls
102
+ end
103
+
104
+ def to_hdf
105
+ controls = []
106
+ vulnerability_count = 0
107
+ @project['data'].uniq.each do | vulnerability |
108
+ printf("\rProcessing: %s", $spinner.next)
109
+
110
+ vulnerability_count +=1
111
+ item = {}
112
+ item['tags'] = {}
113
+ item['descriptions'] = []
114
+ item['refs'] = NA_ARRAY
115
+ item['source_location'] = NA_HASH
116
+ item['descriptions'] = NA_ARRAY
117
+
118
+ # Xray JSONs might note have `id` fields populated.
119
+ # If thats a case MD5 hash is used to collapse vulnerability findings of the same type.
120
+ item['id'] = vulnerability['id'].empty? ? OpenSSL::Digest::MD5.digest(vulnerability['summary'].to_s).unpack("H*")[0].to_s : vulnerability['id']
121
+ item['title'] = vulnerability['summary'].to_s
122
+ item['desc'] = vulnerability['component_versions']['more_details']['description'].to_s
123
+ item['impact'] = impact(vulnerability['severity'].to_s)
124
+ item['code'] = NA_STRING
125
+ item['results'] = finding(vulnerability)
126
+
127
+ item['tags']['nist'] = nist_tag( parse_identifiers( vulnerability, 'CWE') )
128
+ item['tags']['cweid'] = parse_identifiers( vulnerability, 'CWE')
129
+
130
+ controls << item
131
+ end
132
+
133
+ controls = collapse_duplicates(controls)
134
+ results = HeimdallDataFormat.new(profile_name: "JFrog Xray Scan",
135
+ version: NA_STRING,
136
+ title: "JFrog Xray Scan",
137
+ summary: "Continuous Security and Universal Artifact Analysis",
138
+ controls: controls)
139
+ results.to_hdf
140
+ end
141
+ end
142
+ end
@@ -0,0 +1,149 @@
1
+ require 'json'
2
+ require 'csv'
3
+ require 'heimdall_tools/hdf'
4
+
5
+ RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
6
+
7
+ NIKTO_NIST_MAPPING_FILE = File.join(RESOURCE_DIR, 'nikto-nist-mapping.csv')
8
+
9
+ IMPACT_MAPPING = {
10
+ high: 0.7,
11
+ medium: 0.5,
12
+ low: 0.3,
13
+ }.freeze
14
+
15
+ DEFAULT_NIST_TAG = ["SA-11", "RA-5"].freeze
16
+
17
+ # Loading spinner sign
18
+ $spinner = Enumerator.new do |e|
19
+ loop do
20
+ e.yield '|'
21
+ e.yield '/'
22
+ e.yield '-'
23
+ e.yield '\\'
24
+ end
25
+ end
26
+
27
+ module HeimdallTools
28
+ class NiktoMapper
29
+ def initialize(nikto_json, name=nil, verbose = false)
30
+ @nikto_json = nikto_json
31
+ @verbose = verbose
32
+
33
+ begin
34
+ @nikto_nist_mapping = parse_mapper
35
+ rescue StandardError => e
36
+ raise "Invalid Nikto to NIST mapping file: Exception: #{e}"
37
+ end
38
+
39
+ # TODO: Support Multi-target scan results
40
+ # Nikto multi-target scans generate invalid format JSONs
41
+ # Possible workaround to use https://stackoverflow.com/a/58209963/1670307
42
+
43
+ begin
44
+ @project = JSON.parse(nikto_json)
45
+ rescue StandardError => e
46
+ raise "Invalid Nikto JSON file provided\nNote: nikto_mapper does not support multi-target scan results\n\nException: #{e}"
47
+ end
48
+ end
49
+
50
+ def extract_scaninfo(project)
51
+ info = {}
52
+ begin
53
+ info['policy'] = 'Nikto Website Scanner'
54
+ info['version'] = NA_STRING
55
+ info['projectName'] = "Host: #{project['host']} Port: #{project['port']}"
56
+ info['summary'] = "Banner: #{project['banner']}"
57
+
58
+ info
59
+ rescue StandardError => e
60
+ raise "Error extracting project info from nikto JSON file provided Exception: #{e}"
61
+ end
62
+ end
63
+
64
+ def finding(vulnerability)
65
+ finding = {}
66
+ finding['status'] = 'failed'
67
+ finding['code_desc'] = "URL : #{vulnerability['url'].to_s } Method: #{vulnerability['method'].to_s}"
68
+ finding['run_time'] = NA_FLOAT
69
+ finding['start_time'] = NA_STRING
70
+ [finding]
71
+ end
72
+
73
+ def nist_tag(niktoid)
74
+ entries = @nikto_nist_mapping.select { |x| niktoid.eql?(x[:niktoid].to_s) }
75
+ tags = entries.map { |x| x[:nistid] }
76
+ tags.empty? ? DEFAULT_NIST_TAG : tags.flatten.uniq
77
+ end
78
+
79
+ def impact(severity)
80
+ IMPACT_MAPPING[severity.to_sym]
81
+ end
82
+
83
+ def parse_mapper
84
+ csv_data = CSV.read(NIKTO_NIST_MAPPING_FILE, **{ encoding: 'UTF-8',
85
+ headers: true,
86
+ header_converters: :symbol})
87
+ csv_data.map(&:to_hash)
88
+ end
89
+
90
+ def desc_tags(data, label)
91
+ { "data": data || NA_STRING, "label": label || NA_STRING }
92
+ end
93
+
94
+ # Nikto report could have multiple vulnerability entries for multiple findings of same issue type.
95
+ # The meta data is identical across entries
96
+ # method collapse_duplicates return unique controls with applicable findings collapsed into it.
97
+ def collapse_duplicates(controls)
98
+ unique_controls = []
99
+
100
+ controls.map { |x| x['id'] }.uniq.each do |id|
101
+ collapsed_results = controls.select { |x| x['id'].eql?(id) }.map {|x| x['results']}
102
+ unique_control = controls.find { |x| x['id'].eql?(id) }
103
+ unique_control['results'] = collapsed_results.flatten
104
+ unique_controls << unique_control
105
+ end
106
+ unique_controls
107
+ end
108
+
109
+ def to_hdf
110
+ controls = []
111
+ @project['vulnerabilities'].each do | vulnerability |
112
+ printf("\rProcessing: %s", $spinner.next)
113
+
114
+ item = {}
115
+ item['tags'] = {}
116
+ item['descriptions'] = []
117
+ item['refs'] = NA_ARRAY
118
+ item['source_location'] = NA_HASH
119
+ item['descriptions'] = NA_ARRAY
120
+
121
+ item['title'] = vulnerability['msg'].to_s
122
+ item['id'] = vulnerability['id'].to_s
123
+
124
+ # Nikto results JSON does not description fields
125
+ # Duplicating vulnerability msg field
126
+ item['desc'] = vulnerability['msg'].to_s
127
+
128
+ # Nitko does not provide finding severity; hard-coding severity to medium
129
+ item['impact'] = impact('medium')
130
+ item['code'] = NA_STRING
131
+ item['results'] = finding(vulnerability)
132
+ item['tags']['nist'] = nist_tag( vulnerability['id'].to_s )
133
+ item['tags']['ösvdb'] = vulnerability['OSVDB']
134
+
135
+ controls << item
136
+ end
137
+
138
+ controls = collapse_duplicates(controls)
139
+ scaninfo = extract_scaninfo(@project)
140
+ results = HeimdallDataFormat.new(profile_name: scaninfo['policy'],
141
+ version: scaninfo['version'],
142
+ title: "Nikto Target: #{scaninfo['projectName']}",
143
+ summary: "Banner: #{scaninfo['summary']}",
144
+ controls: controls,
145
+ target_id: scaninfo['projectName'])
146
+ results.to_hdf
147
+ end
148
+ end
149
+ end
@@ -5,6 +5,8 @@ require 'heimdall_tools/hdf'
5
5
 
6
6
  RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
7
7
 
8
+ DEFAULT_NIST_TAG = ["SA-11", "RA-5"].freeze
9
+
8
10
  MAPPING_FILES = {
9
11
  cwe: File.join(RESOURCE_DIR, 'cwe-nist-mapping.csv'),
10
12
  owasp: File.join(RESOURCE_DIR, 'owasp-nist-mapping.csv')
@@ -237,7 +239,7 @@ class Control
237
239
  return [@mappings[tag_type][parsed_tag]].flatten.uniq
238
240
  end
239
241
 
240
- ['unmapped'] # HDF expects this to be a list, but not an empty list even if there aren't results
242
+ DEFAULT_NIST_TAG # Entries with unmapped NIST tags are defaulted to NIST tags ‘SA-11, RA-5 Rev_4’
241
243
  end
242
244
 
243
245
  def hdf
@@ -7,6 +7,7 @@ require 'heimdall_tools/hdf'
7
7
  RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
8
8
 
9
9
  CWE_NIST_MAPPING_FILE = File.join(RESOURCE_DIR, 'cwe-nist-mapping.csv')
10
+ DEFAULT_NIST_TAG = ["SA-11", "RA-5"].freeze
10
11
 
11
12
  # rubocop:disable Metrics/AbcSize
12
13
 
@@ -66,7 +67,7 @@ module HeimdallTools
66
67
  def nist_tag(cweid)
67
68
  entries = @cwe_nist_mapping.select { |x| x[:cweid].to_s.eql?(cweid.to_s) }
68
69
  tags = entries.map { |x| [x[:nistid], "Rev_#{x[:rev]}"] }
69
- tags.empty? ? ['unmapped'] : tags.flatten.uniq
70
+ tags.empty? ? DEFAULT_NIST_TAG : tags.flatten.uniq
70
71
  end
71
72
 
72
73
  def impact(riskcode)
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.32
4
+ version: 1.3.37
5
5
  platform: ruby
6
6
  authors:
7
7
  - Robert Thew
@@ -10,8 +10,22 @@ authors:
10
10
  autorequire:
11
11
  bindir: exe
12
12
  cert_chain: []
13
- date: 2020-07-28 00:00:00.000000000 Z
13
+ date: 2021-03-01 00:00:00.000000000 Z
14
14
  dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: aws-sdk-configservice
17
+ requirement: !ruby/object:Gem::Requirement
18
+ requirements:
19
+ - - "~>"
20
+ - !ruby/object:Gem::Version
21
+ version: '1'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ requirements:
26
+ - - "~>"
27
+ - !ruby/object:Gem::Version
28
+ version: '1'
15
29
  - !ruby/object:Gem::Dependency
16
30
  name: nokogiri
17
31
  requirement: !ruby/object:Gem::Requirement
@@ -96,20 +110,6 @@ dependencies:
96
110
  - - "~>"
97
111
  - !ruby/object:Gem::Version
98
112
  version: '2.1'
99
- - !ruby/object:Gem::Dependency
100
- name: nori
101
- requirement: !ruby/object:Gem::Requirement
102
- requirements:
103
- - - "~>"
104
- - !ruby/object:Gem::Version
105
- version: '2.6'
106
- type: :runtime
107
- prerelease: false
108
- version_requirements: !ruby/object:Gem::Requirement
109
- requirements:
110
- - - "~>"
111
- - !ruby/object:Gem::Version
112
- version: '2.6'
113
113
  - !ruby/object:Gem::Dependency
114
114
  name: git-lite-version-bump
115
115
  requirement: !ruby/object:Gem::Requirement
@@ -166,20 +166,6 @@ dependencies:
166
166
  - - ">="
167
167
  - !ruby/object:Gem::Version
168
168
  version: '0'
169
- - !ruby/object:Gem::Dependency
170
- name: codeclimate-test-reporter
171
- requirement: !ruby/object:Gem::Requirement
172
- requirements:
173
- - - ">="
174
- - !ruby/object:Gem::Version
175
- version: '0'
176
- type: :development
177
- prerelease: false
178
- version_requirements: !ruby/object:Gem::Requirement
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- version: '0'
183
169
  - !ruby/object:Gem::Dependency
184
170
  name: rake
185
171
  requirement: !ruby/object:Gem::Requirement
@@ -209,23 +195,33 @@ files:
209
195
  - Rakefile
210
196
  - exe/heimdall_tools
211
197
  - lib/data/U_CCI_List.xml
198
+ - lib/data/aws-config-mapping.csv
212
199
  - lib/data/cwe-nist-mapping.csv
213
200
  - lib/data/nessus-plugins-nist-mapping.csv
201
+ - lib/data/nikto-nist-mapping.csv
214
202
  - lib/data/owasp-nist-mapping.csv
215
203
  - lib/heimdall_tools.rb
204
+ - lib/heimdall_tools/aws_config_mapper.rb
216
205
  - lib/heimdall_tools/burpsuite_mapper.rb
217
206
  - lib/heimdall_tools/cli.rb
218
207
  - lib/heimdall_tools/command.rb
208
+ - lib/heimdall_tools/dbprotect_mapper.rb
219
209
  - lib/heimdall_tools/fortify_mapper.rb
220
210
  - lib/heimdall_tools/hdf.rb
221
211
  - lib/heimdall_tools/help.rb
212
+ - lib/heimdall_tools/help/aws_config_mapper.md
222
213
  - lib/heimdall_tools/help/burpsuite_mapper.md
214
+ - lib/heimdall_tools/help/dbprotect_mapper.md
223
215
  - lib/heimdall_tools/help/fortify_mapper.md
216
+ - lib/heimdall_tools/help/jfrog_xray_mapper.md
224
217
  - lib/heimdall_tools/help/nessus_mapper.md
218
+ - lib/heimdall_tools/help/nikto_mapper.md
225
219
  - lib/heimdall_tools/help/snyk_mapper.md
226
220
  - lib/heimdall_tools/help/sonarqube_mapper.md
227
221
  - lib/heimdall_tools/help/zap_mapper.md
222
+ - lib/heimdall_tools/jfrog_xray_mapper.rb
228
223
  - lib/heimdall_tools/nessus_mapper.rb
224
+ - lib/heimdall_tools/nikto_mapper.rb
229
225
  - lib/heimdall_tools/snyk_mapper.rb
230
226
  - lib/heimdall_tools/sonarqube_mapper.rb
231
227
  - lib/heimdall_tools/version.rb
@@ -250,7 +246,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
250
246
  - !ruby/object:Gem::Version
251
247
  version: '0'
252
248
  requirements: []
253
- rubygems_version: 3.1.2
249
+ rubygems_version: 3.2.3
254
250
  signing_key:
255
251
  specification_version: 4
256
252
  summary: Convert Forify, Openzap and Sonarqube results to HDF