heimdall_tools 1.3.25 → 1.3.30

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,108 @@
1
+ pluginFamily,pluginID,NIST-ID,Rev
2
+ AIX Local Security Checks,*,SI-2|RA-5,4
3
+ Amazon Linux Local Security Checks,*,SI-2|RA-5,4
4
+ CentOS Local Security Checks,*,SI-2|RA-5,4
5
+ Debian Local Security Checks,*,SI-2|RA-5,4
6
+ F5 Networks Local Security Checks,*,SI-2|RA-5,4
7
+ Fedora Local Security Checks,*,SI-2|RA-5,4
8
+ FreeBSD Local Security Checks,*,SI-2|RA-5,4
9
+ Gentoo Local Security Checks,*,SI-2|RA-5,4
10
+ HP-UX Local Security Checks,*,SI-2|RA-5,4
11
+ Huawei Local Security Checks,*,SI-2|RA-5,4
12
+ Junos Local Security Checks,*,SI-2|RA-5,4
13
+ MacOS X Local Security Checks,*,SI-2|RA-5,4
14
+ Mandriva Local Security Checks,*,SI-2|RA-5,4
15
+ NewStart CGSL Local Security Checks,*,SI-2|RA-5,4
16
+ Oracle Linux Local Security Checks,*,SI-2|RA-5,4
17
+ OracleVM Local Security Checks,*,SI-2|RA-5,4
18
+ Palo Alto Local Security Checks,*,SI-2|RA-5,4
19
+ PhotonOS Local Security Checks,*,SI-2|RA-5,4
20
+ Red Hat Local Security Checks,*,SI-2|RA-5,4
21
+ Scientific Linux Local Security Checks,*,SI-2|RA-5,4
22
+ Slackware Local Security Checks,*,SI-2|RA-5,4
23
+ Solaris Local Security Checks,*,SI-2|RA-5,4
24
+ SuSE Local Security Checks,*,SI-2|RA-5,4
25
+ Ubuntu Local Security Checks,*,SI-2|RA-5,4
26
+ VMware ESX Local Security Checks,*,SI-2|RA-5,4
27
+ Virtuozzo Local Security Checks,*,SI-2|RA-5,4
28
+ Backdoors,,,
29
+ Brute force attacks,,,
30
+ CGI abuses,,,
31
+ CGI abuses : XSS,,,
32
+ CISCO,,,
33
+ DNS,,,
34
+ Databases,,,
35
+ Default Unix Accounts,,,
36
+ Denial of Service,,,
37
+ FTP,,,
38
+ Firewalls,56310,SC-7,4
39
+ Gain a shell remotely,,,
40
+ General,133964,AC-3(4),4
41
+ General,117530,UM-1,4
42
+ General,110483,CM-7,4
43
+ General,95928,AC-2,4
44
+ General,90191,CM-8,4
45
+ General,86420,CM-8,4
46
+ General,70544,AC-17(2)|SC-13,4
47
+ General,66334,SI-2|RA-5,4
48
+ General,64582,CM-8,4
49
+ General,57582,SC-12,4
50
+ General,57041,AC-17(2)|SC-13,4
51
+ General,56984,AC-17(2)|SC-13,4
52
+ General,56468,CM-8,4
53
+ General,55472,CM-8,4
54
+ General,54615,CM-8,4
55
+ General,51192,SC-12,4
56
+ General,45590,CM-8,4
57
+ General,45432,CM-8,4
58
+ General,45410,SC-12,4
59
+ General,39520,SI-2|RA-5,4
60
+ General,35351,CM-8,4
61
+ General,34098,CM-8,4
62
+ General,33276,CM-8,4
63
+ General,25220,SC-8,4
64
+ General,25203,CM-8,4
65
+ General,25202,CM-8,4
66
+ General,22869,CM-8,4
67
+ General,21643,AC-17(2)|SC-13,4
68
+ General,12053,CM-8,4
69
+ General,11936,CM-8,4
70
+ General,10881,AC-17(2)|SC-13,4
71
+ General,10863,SC-12,4
72
+ General,10287,CM-8,4
73
+ General,10114,CM-6,4
74
+ Misc.,118237,CM-8,4
75
+ Misc.,97993,CM-8,4
76
+ Misc.,90707,CM-8,4
77
+ Misc.,84821,AC-17(2)|SC-13,4
78
+ Misc.,83875,AC-17(2)|SC-13,4
79
+ Misc.,70657,AC-17(2)|SC-13,4
80
+ Misc.,58651,AC-17,4
81
+ Mobile Devices,,,
82
+ Netware,,,
83
+ Peer-To-Peer File Sharing,,,
84
+ Policy Compliance,,,
85
+ Port scanners,14272,CM-8,4
86
+ RPC,53335,CM-8,4
87
+ RPC,10223,CM-8,4
88
+ SCADA,,,
89
+ SMTP problems,,,
90
+ SNMP,,,
91
+ Service detection,121010,AC-17(2)|SC-13,4
92
+ Service detection,104743,AC-17(2)|SC-13,4
93
+ Service detection,25221,CM-8,4
94
+ Service detection,22964,CM-8,4
95
+ Service detection,11111,CM-8,4
96
+ Service detection,10884,AU-8(1),4
97
+ Service detection,10267,AC-17(2),4
98
+ Settings,117887,UM-1,4
99
+ Settings,110095,UM-1,4
100
+ Settings,19506,UM-1,4
101
+ Web Servers,85805,SC-8|SC-13,4
102
+ Web Servers,84502,AC-17(2)|SC-13,4
103
+ Web Servers,43111,CM-8,4
104
+ Web Servers,24260,CM-8,4
105
+ Web Servers,10107,CM-8,4
106
+ Windows,,,
107
+ Windows : Microsoft Bulletins,,,
108
+ Windows : User management,,,
@@ -9,4 +9,5 @@ module HeimdallTools
9
9
  autoload :ZapMapper, 'heimdall_tools/zap_mapper'
10
10
  autoload :SonarQubeMapper, 'heimdall_tools/sonarqube_mapper'
11
11
  autoload :BurpSuiteMapper, 'heimdall_tools/burpsuite_mapper'
12
+ autoload :NessusMapper, 'heimdall_tools/nessus_mapper'
12
13
  end
@@ -45,6 +45,22 @@ module HeimdallTools
45
45
  File.write(options[:output], hdf)
46
46
  end
47
47
 
48
+ desc 'nessus_mapper', 'nessus_mapper translates nessus xml report to HDF format Json be viewed on Heimdall'
49
+ long_desc Help.text(:nessus_mapper)
50
+ option :xml, required: true, aliases: '-x'
51
+ option :output_prefix, required: true, aliases: '-o'
52
+ option :verbose, type: :boolean, aliases: '-V'
53
+ def nessus_mapper
54
+ hdfs = HeimdallTools::NessusMapper.new(File.read(options[:xml])).to_hdf
55
+
56
+ puts "\nHDF Generated:"
57
+ hdfs.keys.each do | host |
58
+ File.write("#{options[:output_prefix]}-#{host}.json", hdfs[host])
59
+ puts "#{options[:output_prefix]}-#{host}.json"
60
+ end
61
+
62
+ end
63
+
48
64
  desc 'version', 'prints version'
49
65
  def version
50
66
  puts VERSION
@@ -28,12 +28,14 @@ module HeimdallTools
28
28
  depends: NA_ARRAY,
29
29
  groups: NA_ARRAY,
30
30
  status: 'loaded',
31
- controls: NA_TAG)
31
+ controls: NA_TAG,
32
+ target_id: NA_TAG)
32
33
 
33
34
  @results_json = {}
34
35
  @results_json['platform'] = {}
35
36
  @results_json['platform']['name'] = 'Heimdall Tools'
36
37
  @results_json['platform']['release'] = HeimdallTools::VERSION
38
+ @results_json['platform']['target_id'] = target_id.to_s
37
39
  @results_json['version'] = HeimdallTools::VERSION
38
40
 
39
41
  @results_json['statistics'] = {}
@@ -0,0 +1,9 @@
1
+ nessus_mapper translates an Nessus exported XML results file into HDF format json to be viewable in Heimdall
2
+
3
+ The current iteration maps all plugin families except 'Policy Compliance'
4
+
5
+ A separate HDF JSON is generated for each host reported in the Nessus Report.
6
+
7
+ Examples:
8
+
9
+ heimdall_tools nessus_mapper -x nessus_results.xml -o file-prefix
@@ -0,0 +1,258 @@
1
+ require 'json'
2
+ require 'csv'
3
+ require 'heimdall_tools/hdf'
4
+ require 'utilities/xml_to_hash'
5
+ require 'nokogiri'
6
+ require 'pp'
7
+
8
+ RESOURCE_DIR = Pathname.new(__FILE__).join('../../data')
9
+
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')
12
+
13
+ IMPACT_MAPPING = {
14
+ Info: 0.0,
15
+ Low: 0.3,
16
+ Medium: 0.5,
17
+ High: 0.7,
18
+ Critical: 0.9,
19
+ }.freeze
20
+
21
+ DEFAULT_NIST_TAG = ["unmapped"].freeze
22
+
23
+ # Nessus results file 800-53 refs does not contain Nist rev version. Using this default
24
+ # version in that case
25
+ DEFAULT_NIST_REV = 'Rev_4'.freeze
26
+
27
+ NA_PLUGIN_OUTPUT = "This Nessus Plugin does not provide output message.".freeze
28
+
29
+ # rubocop:disable Metrics/AbcSize
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
+
41
+ module HeimdallTools
42
+ class NessusMapper
43
+ def initialize(nessus_xml, verbose = false)
44
+ @nessus_xml = nessus_xml
45
+ @verbose = verbose
46
+ read_cci_xml
47
+ begin
48
+ @cwe_nist_mapping = parse_mapper
49
+ @data = xml_to_hash(nessus_xml)
50
+ @reports = extract_report
51
+ @scaninfo = extract_scaninfo
52
+ rescue StandardError => e
53
+ raise "Invalid Nessus XML file provided Exception: #{e}"
54
+ end
55
+
56
+ end
57
+
58
+ def extract_report
59
+ begin
60
+ # When there are multiple hosts in the nessus report ReportHost field is an array
61
+ # When there is only one host in the nessus report ReportHost field is a hash
62
+ # Array() converts ReportHost to array in case there is only one host
63
+ reports = @data['NessusClientData_v2']['Report']['ReportHost']
64
+ reports.kind_of?(Array) ? reports : [reports]
65
+ rescue StandardError => e
66
+ raise "Invalid Nessus XML file provided Exception: #{e}"
67
+ end
68
+ end
69
+
70
+ def parse_refs(refs, key)
71
+ refs.split(',').map { |x| x.split('|')[1] if x.include?(key) }.compact
72
+ end
73
+
74
+ def extract_scaninfo
75
+ begin
76
+ policy = @data['NessusClientData_v2']['Policy']
77
+ info = {}
78
+
79
+ info['policyName'] = policy['policyName']
80
+ info['version'] = policy['Preferences']['ServerPreferences']['preference'].select {|x| x['name'].eql? 'sc_version'}.first['value']
81
+ info
82
+ rescue StandardError => e
83
+ raise "Invalid Nessus XML file provided Exception: #{e}"
84
+ end
85
+ end
86
+
87
+ def extract_timestamp(report)
88
+ begin
89
+ timestamp = report['HostProperties']['tag'].select {|x| x['name'].eql? 'HOST_START'}.first['text']
90
+ rescue StandardError => e
91
+ raise "Invalid Nessus XML file provided Exception: #{e}"
92
+ end
93
+ end
94
+
95
+ def format_desc(issue)
96
+ desc = ''
97
+ desc += "Plugin Family: #{issue['pluginFamily']}; "
98
+ desc += "Port: #{issue['port']}; "
99
+ desc += "Protocol: #{issue['protocol']};"
100
+ desc
101
+ end
102
+
103
+ def finding(issue, timestamp)
104
+ finding = {}
105
+ # if compliance-result field, this is a policy compliance result entry
106
+ # nessus policy compliance result provides a pass/fail data
107
+ # For non policy compliance results are defaulted to failed
108
+ if issue['compliance-result']
109
+ finding['status'] = issue['compliance-result'].eql?('PASSED') ? 'passed' : 'failed'
110
+ else
111
+ finding['status'] = 'failed'
112
+ end
113
+
114
+ if issue['description']
115
+ finding['code_desc'] = issue['description'].to_s || NA_PLUGIN_OUTPUT
116
+ else
117
+ finding['code_desc'] = issue['plugin_output'] || NA_PLUGIN_OUTPUT
118
+ end
119
+ finding['run_time'] = NA_FLOAT
120
+ finding['start_time'] = timestamp
121
+ [finding]
122
+ end
123
+
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)
147
+ entries = @cwe_nist_mapping.select { |x| (x[:pluginfamily].eql?(pluginfamily) && (x[:pluginid].eql?('*') || x[:pluginid].eql?(pluginid.to_i)) ) }
148
+ tags = entries.map { |x| [x[:nistid].split('|'), "Rev_#{x[:rev]}"] }
149
+ tags.empty? ? DEFAULT_NIST_TAG : tags.flatten.uniq
150
+ end
151
+
152
+ def impact(severity)
153
+ # Map CAT levels and Plugin severity to HDF impact levels
154
+ case severity
155
+ when "0"
156
+ IMPACT_MAPPING[:Info]
157
+ when "1","III"
158
+ IMPACT_MAPPING[:Low]
159
+ when "2","II"
160
+ IMPACT_MAPPING[:Medium]
161
+ when "3","I"
162
+ IMPACT_MAPPING[:High]
163
+ when "4"
164
+ IMPACT_MAPPING[:Critical]
165
+ else
166
+ -1
167
+ end
168
+ end
169
+
170
+ def parse_mapper
171
+ csv_data = CSV.read(NESSUS_PLUGINS_NIST_MAPPING_FILE, { encoding: 'UTF-8',
172
+ headers: true,
173
+ header_converters: :symbol,
174
+ converters: :all })
175
+ csv_data.map(&:to_hash)
176
+ end
177
+
178
+ def desc_tags(data, label)
179
+ { "data": data || NA_STRING, "label": label || NA_STRING }
180
+ end
181
+
182
+ # Nessus report could have multiple issue entries for multiple findings of same issue type.
183
+ # The meta data is identical across entries
184
+ # method collapse_duplicates return unique controls with applicable findings collapsed into it.
185
+ def collapse_duplicates(controls)
186
+ unique_controls = []
187
+
188
+ controls.map { |x| x['id'] }.uniq.each do |id|
189
+ collapsed_results = controls.select { |x| x['id'].eql?(id) }.map {|x| x['results']}
190
+ unique_control = controls.find { |x| x['id'].eql?(id) }
191
+ unique_control['results'] = collapsed_results.flatten
192
+ unique_controls << unique_control
193
+ end
194
+ unique_controls
195
+ end
196
+
197
+ def to_hdf
198
+ host_results = {}
199
+ @reports.each do | report|
200
+ controls = []
201
+ report['ReportItem'].each do | item |
202
+ printf("\rProcessing: %s", $spinner.next)
203
+ @item = {}
204
+ @item['tags'] = {}
205
+ @item['descriptions'] = []
206
+ @item['refs'] = NA_ARRAY
207
+ @item['source_location'] = NA_HASH
208
+
209
+ # Nessus results field set are different for 'Policy Compliance' plug-in family vs other plug-in families
210
+ # Following if conditions capture compliance* if it exists else it will default to plugin* fields
211
+ # Current version covers STIG based 'Policy Compliance' results
212
+ # TODO Cover cases for 'Policy Compliance' results based on CIS
213
+ if item['compliance-reference']
214
+ @item['id'] = parse_refs(item['compliance-reference'],'Vuln-ID').join.to_s
215
+ else
216
+ @item['id'] = item['pluginID'].to_s
217
+ end
218
+ if item['compliance-check-name']
219
+ @item['title'] = item['compliance-check-name'].to_s
220
+ else
221
+ @item['title'] = item['pluginName'].to_s
222
+ end
223
+ if item['compliance-info']
224
+ @item['desc'] = item['compliance-info'].to_s
225
+ else
226
+ @item['desc'] = format_desc(item).to_s
227
+ end
228
+ if item['compliance-reference']
229
+ @item['impact'] = impact(parse_refs(item['compliance-reference'],'CAT').join.to_s)
230
+ else
231
+ @item['impact'] = impact(item['severity'])
232
+ end
233
+ if item['compliance-reference']
234
+ @item['tags']['nist'] = cci_nist_tag(parse_refs(item['compliance-reference'],'CCI'))
235
+ else
236
+ @item['tags']['nist'] = plugin_nist_tag(item['pluginFamily'],item['pluginID'])
237
+ end
238
+ if item['compliance-solution']
239
+ @item['descriptions'] << desc_tags(item['compliance-solution'], 'check')
240
+ end
241
+
242
+ @item['code'] = ''
243
+ @item['results'] = finding(item, extract_timestamp(report))
244
+ controls << @item
245
+ end
246
+ controls = collapse_duplicates(controls)
247
+ results = HeimdallDataFormat.new(profile_name: "Nessus #{@scaninfo['policyName']}",
248
+ version: @scaninfo['version'],
249
+ title: "Nessus #{@scaninfo['policyName']}",
250
+ summary: "Nessus #{@scaninfo['policyName']}",
251
+ controls: controls,
252
+ target_id: report['name'])
253
+ host_results[report['name']] = results.to_hdf
254
+ end
255
+ host_results
256
+ end
257
+ end
258
+ end
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.25
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-04-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
@@ -116,14 +116,14 @@ dependencies:
116
116
  requirements:
117
117
  - - ">="
118
118
  - !ruby/object:Gem::Version
119
- version: '0.17'
119
+ version: 0.17.2
120
120
  type: :runtime
121
121
  prerelease: false
122
122
  version_requirements: !ruby/object:Gem::Requirement
123
123
  requirements:
124
124
  - - ">="
125
125
  - !ruby/object:Gem::Version
126
- version: '0.17'
126
+ version: 0.17.2
127
127
  - !ruby/object:Gem::Dependency
128
128
  name: bundler
129
129
  requirement: !ruby/object:Gem::Requirement
@@ -209,8 +209,9 @@ 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
+ - lib/data/nessus-plugins-nist-mapping.csv
214
215
  - lib/data/owasp-nist-mapping.csv
215
216
  - lib/heimdall_tools.rb
216
217
  - lib/heimdall_tools/burpsuite_mapper.rb
@@ -221,8 +222,10 @@ files:
221
222
  - lib/heimdall_tools/help.rb
222
223
  - lib/heimdall_tools/help/burpsuite_mapper.md
223
224
  - lib/heimdall_tools/help/fortify_mapper.md
225
+ - lib/heimdall_tools/help/nessus_mapper.md
224
226
  - lib/heimdall_tools/help/sonarqube_mapper.md
225
227
  - lib/heimdall_tools/help/zap_mapper.md
228
+ - lib/heimdall_tools/nessus_mapper.rb
226
229
  - lib/heimdall_tools/sonarqube_mapper.rb
227
230
  - lib/heimdall_tools/version.rb
228
231
  - lib/heimdall_tools/zap_mapper.rb