Skip to content

Commit 8559478

Browse files
author
Rony Xavier
committed
Initial commit for dbprotect_mapper
Signed-off-by: Rony Xavier <[email protected]>
1 parent 2b63d63 commit 8559478

File tree

5 files changed

+161
-0
lines changed

5 files changed

+161
-0
lines changed

README.md

+16
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ HeimdallTools supplies several methods to convert output from various tools to "
1313
- **snyk_mapper** - commercial package vulnerability scanner
1414
- **nikto_mapper** - open-source web server scanner
1515
- **jfrog_xray_mapper** - package vulnerability scanner
16+
- **dbprotect_mapper** - database vulnerability scanner
1617

1718
Ruby 2.4 or higher (check using "ruby -v")
1819

@@ -197,6 +198,21 @@ FLAGS:
197198
example: heimdall_tools jfrog_xray_mapper -j xray_results.json -o xray_results_hdf.json
198199
```
199200

201+
## dbprotect_mapper
202+
203+
dbprotect_mapper translates DBProtect report in `Check Results Details` format XML to HDF format JSON be viewed on Heimdall.
204+
205+
```
206+
USAGE: heimdall_tools dbprotect_mapper [OPTIONS] -x <check_results_details_report_xml> -o <db_protect_hdf.json>
207+
208+
FLAGS:
209+
-x <check_results_details_report_xml> : path to DBProtect report XML file.
210+
-o --output <scan-results> : path to output scan-results json.
211+
-V --verbose : verbose run [optional].
212+
213+
example: heimdall_tools dbprotect_mapper -x check_results_details_report.xml -o db_protect_hdf.json
214+
```
215+
200216
## version
201217

202218
Prints out the gem version

lib/heimdall_tools.rb

+1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ module HeimdallTools
1313
autoload :SnykMapper, 'heimdall_tools/snyk_mapper'
1414
autoload :NiktoMapper, 'heimdall_tools/nikto_mapper'
1515
autoload :JfrogXrayMapper, 'heimdall_tools/jfrog_xray_mapper'
16+
autoload :DBProtectMapper, 'heimdall_tools/dbprotect_mapper'
1617
end

lib/heimdall_tools/cli.rb

+12
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,18 @@ def jfrog_xray_mapper
9999
puts "#{options[:output]}"
100100
end
101101

102+
desc 'dbprotect_mapper', 'dbprotect_mapper translates dbprotect results xml to HDF format Json be viewed on Heimdall'
103+
long_desc Help.text(:dbprotect_mapper)
104+
option :xml, required: true, aliases: '-x'
105+
option :output, required: true, aliases: '-o'
106+
option :verbose, type: :boolean, aliases: '-V'
107+
def dbprotect_mapper
108+
hdf = HeimdallTools::DBProtectMapper.new(File.read(options[:xml])).to_hdf
109+
File.write(options[:output], hdf)
110+
puts "\r\HDF Generated:\n"
111+
puts "#{options[:output]}"
112+
end
113+
102114
desc 'version', 'prints version'
103115
def version
104116
puts VERSION
+127
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,127 @@
1+
require 'json'
2+
require 'csv'
3+
require 'heimdall_tools/hdf'
4+
require 'utilities/xml_to_hash'
5+
6+
IMPACT_MAPPING = {
7+
High: 0.7,
8+
Medium: 0.5,
9+
Low: 0.3,
10+
Informational: 0.0
11+
}.freeze
12+
13+
# rubocop:disable Metrics/AbcSize
14+
15+
module HeimdallTools
16+
class DBProtectMapper
17+
def initialize(xml, name=nil, verbose = false)
18+
@verbose = verbose
19+
20+
begin
21+
dataset = xml_to_hash(xml)
22+
@entries = compile_findings(dataset['dataset'])
23+
24+
rescue StandardError => e
25+
raise "Invalid DBProtect XML file provided Exception: #{e};\nNote that XML must be of kind `Check Results Details`."
26+
end
27+
28+
end
29+
30+
def to_hdf
31+
controls = []
32+
@entries.each do |entry|
33+
@item = {}
34+
@item['id'] = entry['Check ID']
35+
@item['title'] = entry['Check']
36+
@item['desc'] = format_desc(entry)
37+
@item['impact'] = impact(entry['Risk DV'])
38+
@item['tags'] = {}
39+
@item['descriptions'] = []
40+
@item['refs'] = NA_ARRAY
41+
@item['source_location'] = NA_HASH
42+
@item['code'] = ''
43+
@item['results'] = finding(entry)
44+
45+
controls << @item
46+
end
47+
controls = collapse_duplicates(controls)
48+
results = HeimdallDataFormat.new(profile_name: @entries.first['Policy'],
49+
version: "",
50+
title: @entries.first['Job Name'],
51+
summary: format_summary(@entries.first),
52+
controls: controls)
53+
results.to_hdf
54+
end
55+
56+
private
57+
58+
def compile_findings(dataset)
59+
keys = dataset['metadata']['item'].map{ |e| e['name']}
60+
findings = dataset['data']['row'].map { |e| Hash[keys.zip(e['value'])] }
61+
findings
62+
end
63+
64+
def format_desc(entry)
65+
text = []
66+
text << "Task : #{entry['Task']}"
67+
text << "Check Category : #{entry['Check Category']}"
68+
text.join("; ")
69+
end
70+
71+
def format_summary(entry)
72+
text = []
73+
text << "Organization : #{entry['Organization']}"
74+
text << "Asset : #{entry['Check Asset']}"
75+
text << "Asset Type : #{entry['Asset Type']}"
76+
text << "IP Address, Port, Instance : #{entry['Asset Type']}"
77+
text << "IP Address, Port, Instance : #{entry['IP Address, Port, Instance']}"
78+
text.join("\n")
79+
end
80+
81+
def finding(entry)
82+
finding = {}
83+
84+
finding['code_desc'] = entry['Details']
85+
finding['run_time'] = 0.0
86+
finding['start_time'] = entry['Date']
87+
88+
case entry['Result Status']
89+
when 'Fact'
90+
finding['status'] = 'skipped'
91+
when 'Failed'
92+
finding['status'] = 'failed'
93+
finding['backtrace'] = ["DB Protect Failed Check"]
94+
when 'Finding'
95+
finding['status'] = 'failed'
96+
when 'Not A Finding'
97+
finding['status'] = 'passed'
98+
when 'Skipped'
99+
finding['status'] = 'skipped'
100+
else
101+
finding['status'] = 'skipped'
102+
end
103+
[finding]
104+
end
105+
106+
def impact(severity)
107+
IMPACT_MAPPING[severity.to_sym]
108+
end
109+
110+
# DBProtect report could have multiple issue entries for multiple findings of same issue type.
111+
# The meta data is identical across entries
112+
# method collapse_duplicates return unique controls with applicable findings collapsed into it.
113+
def collapse_duplicates(controls)
114+
unique_controls = []
115+
116+
controls.map { |x| x['id'] }.uniq.each do |id|
117+
collapsed_results = controls.select { |x| x['id'].eql?(id) }.map {|x| x['results']}
118+
unique_control = controls.find { |x| x['id'].eql?(id) }
119+
unique_control['results'] = collapsed_results.flatten
120+
unique_controls << unique_control
121+
end
122+
unique_controls
123+
end
124+
125+
126+
end
127+
end
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)