inspec_tools 0.0.0.1.ENOTAG → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (42) hide show
  1. checksums.yaml +5 -5
  2. data/CHANGELOG.md +12 -657
  3. data/Guardfile +4 -0
  4. data/README.md +65 -132
  5. data/Rakefile +0 -6
  6. data/exe/inspec_tools +1 -1
  7. data/lib/data/README.TXT +1 -1
  8. data/lib/data/debug_text +5941 -0
  9. data/lib/happy_mapper_tools/cci_attributes.rb +22 -12
  10. data/lib/happy_mapper_tools/stig_checklist.rb +1 -6
  11. data/lib/inspec_tools.rb +2 -1
  12. data/lib/inspec_tools/cli.rb +140 -24
  13. data/lib/inspec_tools/command.rb +50 -0
  14. data/lib/inspec_tools/csv.rb +4 -6
  15. data/lib/inspec_tools/help/summary.md +2 -2
  16. data/lib/inspec_tools/inspec.rb +34 -133
  17. data/lib/inspec_tools/pdf.rb +2 -3
  18. data/lib/inspec_tools/summary.rb +2 -2
  19. data/lib/inspec_tools/version.rb +1 -6
  20. data/lib/inspec_tools/xccdf.rb +8 -22
  21. data/lib/utilities/inspec_util.rb +59 -208
  22. data/test/unit/inspec_tools/csv_test.rb +30 -0
  23. data/test/unit/inspec_tools/inspec_test.rb +54 -0
  24. data/test/unit/inspec_tools/pdf_test.rb +24 -0
  25. data/test/unit/inspec_tools/summary_test.rb +42 -0
  26. data/test/unit/inspec_tools/xccdf_test.rb +50 -0
  27. data/test/unit/inspec_tools_test.rb +7 -0
  28. data/test/unit/test_helper.rb +5 -0
  29. data/test/unit/utils/inspec_util_test.rb +43 -0
  30. metadata +70 -125
  31. data/lib/data/NIST_Map_02052020_CIS_Controls_Version_7.1_Implementation_Groups_1.2.xlsx +0 -0
  32. data/lib/exceptions/impact_input_error.rb +0 -6
  33. data/lib/exceptions/severity_input_error.rb +0 -6
  34. data/lib/inspec_tools/plugin.rb +0 -15
  35. data/lib/inspec_tools/plugin_cli.rb +0 -278
  36. data/lib/inspec_tools/xlsx_tool.rb +0 -148
  37. data/lib/inspec_tools_plugin.rb +0 -7
  38. data/lib/overrides/false_class.rb +0 -5
  39. data/lib/overrides/nil_class.rb +0 -5
  40. data/lib/overrides/object.rb +0 -5
  41. data/lib/overrides/string.rb +0 -5
  42. data/lib/overrides/true_class.rb +0 -5
@@ -3,7 +3,7 @@
3
3
  require 'happymapper'
4
4
  require 'nokogiri'
5
5
 
6
- # rubocop:disable Naming/ClassAndModuleCamelCase
6
+ # rubocop: disable Naming/ClassAndModuleCamelCase
7
7
 
8
8
  module HappyMapperTools
9
9
  module CCIAttributes
@@ -18,6 +18,13 @@ module HappyMapperTools
18
18
  attribute :index, String, tag: 'index'
19
19
  end
20
20
 
21
+ class References
22
+ include HappyMapper
23
+ tag 'references'
24
+
25
+ has_many :references, Reference, tag: 'reference'
26
+ end
27
+
21
28
  class CCI_Item
22
29
  include HappyMapper
23
30
  tag 'cci_item'
@@ -28,7 +35,14 @@ module HappyMapperTools
28
35
  element :contributor, String, tag: 'contributor'
29
36
  element :definition, String, tag: 'definition'
30
37
  element :type, String, tag: 'type'
31
- has_many :references, Reference, xpath: 'xmlns:references'
38
+ has_one :references, References, tag: 'references'
39
+ end
40
+
41
+ class CCI_Items
42
+ include HappyMapper
43
+ tag 'cci_items'
44
+
45
+ has_many :cci_item, CCI_Item, tag: 'cci_item'
32
46
  end
33
47
 
34
48
  class Metadata
@@ -46,21 +60,17 @@ module HappyMapperTools
46
60
  attribute :xsi, String, tag: 'xsi', namespace: 'xmlns'
47
61
  attribute :schemaLocation, String, tag: 'schemaLocation', namespace: 'xmlns'
48
62
  has_one :metadata, Metadata, tag: 'metadata'
49
- has_many :cci_items, CCI_Item, xpath: 'xmlns:cci_items'
63
+ has_many :cci_items, CCI_Items, tag: 'cci_items'
50
64
 
51
65
  def fetch_nists(ccis)
52
66
  ccis = [ccis] unless ccis.is_a?(Array)
53
-
54
- # some of the XCCDF files were having CCE- tags show up which
55
- # we don't support, not sure if this is a typo on their part or
56
- # we need to see about supporting CCE tags but ... for now
57
- filtered_ccis = ccis.select { |f| /CCI-/.match(f) }
58
- filtered_ccis.map do |cci|
59
- cci_items.find { |item| item.id == cci }.references.max_by(&:version).index
67
+ nists = []
68
+ nist_ver = cci_items[0].cci_item[0].references.references.max_by(&:version).version
69
+ ccis.each do |cci|
70
+ nists << cci_items[0].cci_item.select { |item| item.id == cci }.first.references.references.max_by(&:version).index
60
71
  end
72
+ nists << ('Rev_' + nist_ver)
61
73
  end
62
74
  end
63
75
  end
64
76
  end
65
-
66
- # rubocop:enable Naming/ClassAndModuleCamelCase
@@ -42,12 +42,6 @@ module HappyMapperTools
42
42
  # Class Asset maps from the 'STIG_DATA' from Checklist XML file using HappyMapper
43
43
  class StigData
44
44
  include HappyMapper
45
-
46
- def initialize(attrib = nil, data = nil)
47
- self.attrib = attrib
48
- self.data = data
49
- end
50
-
51
45
  tag 'STIG_DATA'
52
46
  has_one :attrib, String, tag: 'VULN_ATTRIBUTE'
53
47
  has_one :data, String, tag: 'ATTRIBUTE_DATA'
@@ -85,6 +79,7 @@ module HappyMapperTools
85
79
  tag 'CHECKLIST'
86
80
  has_one :asset, Asset, tag: 'ASSET'
87
81
  has_one :stig, Stigs, tag: 'STIGS'
82
+ Encoding.default_external = 'UTF-8'
88
83
 
89
84
  def where(attrib, data)
90
85
  stig.istig.vuln.each do |vuln|
data/lib/inspec_tools.rb CHANGED
@@ -1,6 +1,8 @@
1
1
  $LOAD_PATH.unshift(File.expand_path(__dir__))
2
2
  require 'inspec_tools/version'
3
3
  require 'rubygems'
4
+ require 'bundler/setup'
5
+ Bundler.setup(:default)
4
6
 
5
7
  module InspecTools
6
8
  autoload :Help, 'inspec_tools/help'
@@ -13,5 +15,4 @@ module InspecTools
13
15
  autoload :Inspec, 'inspec_tools/inspec'
14
16
  autoload :Summary, 'inspec_tools/summary'
15
17
  autoload :Threshold, 'inspec_tools/threshold'
16
- autoload :XLSXTool, 'inspec_tools/xlsx_tool'
17
18
  end
@@ -1,31 +1,147 @@
1
1
  require 'yaml'
2
2
  require 'json'
3
+ require_relative '../utilities/inspec_util'
4
+ require_relative '../utilities/csv_util'
3
5
 
4
- require 'inspec-objects'
5
- require 'inspec'
6
- require_relative './plugin_cli.rb'
6
+ # rubocop:disable Style/GuardClause
7
7
 
8
- # This tells the ruby cli app to use the same argument parsing as the plugin
9
8
  module InspecTools
10
- CLI = InspecPlugins::InspecToolsPlugin::CliCommand
11
- end
9
+ class CLI < Command
10
+ desc 'xccdf2inspec', 'xccdf2inspec translates an xccdf file to an inspec profile'
11
+ long_desc Help.text(:xccdf2inspec)
12
+ option :xccdf, required: true, aliases: '-x'
13
+ option :attributes, required: false, aliases: '-a'
14
+ option :output, required: false, aliases: '-o', default: 'profile'
15
+ option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'
16
+ option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'
17
+ option :replace_tags, required: false, aliases: '-r'
18
+ def xccdf2inspec
19
+ xccdf = XCCDF.new(File.read(options[:xccdf]))
20
+ profile = xccdf.to_inspec
21
+ Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
22
+ if !options[:attributes].nil?
23
+ attributes = xccdf.to_attributes
24
+ File.write(options[:attributes], YAML.dump(attributes))
25
+ end
26
+ end
12
27
 
13
- #=====================================================================#
14
- # Pre-Flight Code
15
- #=====================================================================#
16
- help_commands = ['-h', '--help', 'help']
17
- log_commands = ['-l', '--log-directory']
18
- version_commands = ['-v', '--version', 'version']
19
-
20
- #---------------------------------------------------------------------#
21
- # Adjustments for non-required version commands
22
- #---------------------------------------------------------------------#
23
- unless (version_commands & ARGV).empty?
24
- puts InspecTools::VERSION
25
- exit 0
26
- end
28
+ desc 'inspec2xccdf', 'inspec2xccdf translates an inspec profile and attributes files to an xccdf file'
29
+ long_desc Help.text(:inspec2xccdf)
30
+ option :inspec_json, required: true, aliases: '-j'
31
+ option :attributes, required: true, aliases: '-a'
32
+ option :output, required: true, aliases: '-o'
33
+ def inspec2xccdf
34
+ json = File.read(options[:inspec_json])
35
+ inspec_tool = InspecTools::Inspec.new(json)
36
+ attr_hsh = YAML.load_file(options[:attributes])
37
+ xccdf = inspec_tool.to_xccdf(attr_hsh)
38
+ File.write(options[:output], xccdf)
39
+ end
40
+
41
+ desc 'csv2inspec', 'csv2inspec translates CSV to Inspec controls using a mapping file'
42
+ long_desc Help.text(:csv2inspec)
43
+ option :csv, required: true, aliases: '-c'
44
+ option :mapping, required: true, aliases: '-m'
45
+ option :verbose, required: false, type: :boolean, aliases: '-V'
46
+ option :output, required: false, aliases: '-o', default: 'profile'
47
+ option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'
48
+ option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'
49
+ def csv2inspec
50
+ csv = CSV.read(options[:csv], encoding: 'ISO8859-1')
51
+ mapping = YAML.load_file(options[:mapping])
52
+ profile = CSVTool.new(csv, mapping, options[:csv].split('/')[-1].split('.')[0], options[:verbose]).to_inspec
53
+ Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
54
+ end
55
+
56
+ desc 'inspec2csv', 'inspec2csv translates Inspec controls to CSV'
57
+ long_desc Help.text(:inspec2csv)
58
+ option :inspec_json, required: true, aliases: '-j'
59
+ option :output, required: true, aliases: '-o'
60
+ option :verbose, required: false, type: :boolean, aliases: '-V'
61
+ def inspec2csv
62
+ csv = Inspec.new(File.read(options[:inspec_json])).to_csv
63
+ Utils::CSVUtil.unpack_csv(csv, options[:output])
64
+ end
65
+
66
+ desc 'inspec2ckl', 'inspec2ckl translates an inspec json file to a Checklist file'
67
+ long_desc Help.text(:inspec2ckl)
68
+ option :inspec_json, required: true, aliases: '-j'
69
+ option :output, required: true, aliases: '-o'
70
+ option :verbose, type: :boolean, aliases: '-V'
71
+ def inspec2ckl
72
+ ckl = InspecTools::Inspec.new(File.read(options[:inspec_json])).to_ckl
73
+ File.write(options[:output], ckl)
74
+ end
75
+
76
+ desc 'pdf2inspec', 'pdf2inspec translates a PDF Security Control Speficication to Inspec Security Profile'
77
+ long_desc Help.text(:pdf2inspec)
78
+ option :pdf, required: true, aliases: '-p'
79
+ option :output, required: false, aliases: '-o', default: 'profile'
80
+ option :debug, required: false, aliases: '-d', type: :boolean, default: false
81
+ option :format, required: false, aliases: '-f', enum: %w{ruby hash}, default: 'ruby'
82
+ option :separate_files, required: false, type: :boolean, default: true, aliases: '-s'
83
+ def pdf2inspec
84
+ pdf = File.open(options[:pdf])
85
+ profile = InspecTools::PDF.new(pdf, options[:output], options[:debug]).to_inspec
86
+ Utils::InspecUtil.unpack_inspec_json(options[:output], profile, options[:separate_files], options[:format])
87
+ end
88
+
89
+ desc 'generate_map', 'Generates mapping template from CSV to Inspec Controls'
90
+ def generate_map
91
+ template = '
92
+ # Setting csv_header to true will skip the csv file header
93
+ skip_csv_header: true
94
+ width : 80
27
95
 
28
- #---------------------------------------------------------------------#
29
- # Adjustments for non-required log-directory
30
- #---------------------------------------------------------------------#
31
- ARGV.push("--log-directory=#{Dir.pwd}/logs") if (log_commands & ARGV).empty? && (help_commands & ARGV).empty?
96
+
97
+ control.id: 0
98
+ control.title: 15
99
+ control.desc: 16
100
+ control.tags:
101
+ severity: 1
102
+ rid: 8
103
+ stig_id: 3
104
+ cci: 2
105
+ check: 12
106
+ fix: 10
107
+ '
108
+ myfile = File.new('mapping.yml', 'w')
109
+ myfile.puts template
110
+ myfile.close
111
+ end
112
+
113
+ desc 'summary', 'summary parses an inspec results json to create a summary json'
114
+ long_desc Help.text(:summary)
115
+ option :inspec_json, required: true, aliases: '-j'
116
+ option :output, required: true, aliases: '-o'
117
+ option :verbose, type: :boolean, aliases: '-V'
118
+
119
+ def summary
120
+ summary = InspecTools::Summary.new(File.read(options[:inspec_json])).to_summary
121
+ File.write(options[:output], summary.to_json)
122
+ end
123
+
124
+ desc 'compliance', 'compliance parses an inspec results json to check if the compliance level meets a specified threshold'
125
+ long_desc Help.text(:compliance)
126
+ option :inspec_json, required: true, aliases: '-j'
127
+ option :threshold_file, required: false, aliases: '-f'
128
+ option :threshold_inline, required: false, aliases: '-i'
129
+ option :verbose, type: :boolean, aliases: '-V'
130
+
131
+ def compliance
132
+ if options[:threshold_file].nil? && options[:threshold_inline].nil?
133
+ puts 'Please provide threshold as a yaml file or inline yaml'
134
+ exit(1)
135
+ end
136
+ threshold = YAML.load_file(options[:threshold_file]) unless options[:threshold_file].nil?
137
+ threshold = YAML.safe_load(options[:threshold_inline]) unless options[:threshold_inline].nil?
138
+ compliance = InspecTools::Summary.new(File.read(options[:inspec_json])).threshold(threshold)
139
+ compliance ? exit(0) : exit(1)
140
+ end
141
+
142
+ desc 'version', 'prints version'
143
+ def version
144
+ puts VERSION
145
+ end
146
+ end
147
+ end
@@ -0,0 +1,50 @@
1
+ require 'thor'
2
+
3
+ # Override thor's long_desc identation behavior
4
+ # https://github.com/erikhuda/thor/issues/398
5
+
6
+ # rubocop:disable Naming/UncommunicativeMethodParamName
7
+
8
+ class Thor
9
+ module Shell
10
+ class Basic
11
+ def print_wrapped(message, _options = {})
12
+ message = "\n#{message}" unless message[0] == "\n"
13
+ stdout.puts message
14
+ end
15
+ end
16
+ end
17
+ end
18
+
19
+ module InspecTools
20
+ class Command < Thor
21
+ class << self
22
+ def dispatch(m, args, options, config)
23
+ # Allow calling for help via:
24
+ # inspec_tools command help
25
+ # inspec_tools command -h
26
+ # inspec_tools command --help
27
+ # inspec_tools command -D
28
+ #
29
+ # as well thor's normal way:
30
+ #
31
+ # inspec_tools help command
32
+ help_flags = Thor::HELP_MAPPINGS + ['help']
33
+ if args.length > 1 && !(args & help_flags).empty?
34
+ args -= help_flags
35
+ args.insert(-2, 'help')
36
+ end
37
+
38
+ # inspec_tools version
39
+ # inspec_tools --version
40
+ # inspec_tools -v
41
+ version_flags = ['--version', '-v']
42
+ if args.length == 1 && !(args & version_flags).empty?
43
+ args = ['version']
44
+ end
45
+
46
+ super
47
+ end
48
+ end
49
+ end
50
+ end
@@ -1,5 +1,6 @@
1
1
  require 'csv'
2
2
  require 'nokogiri'
3
+ require 'inspec/objects'
3
4
  require 'word_wrap'
4
5
  require 'yaml'
5
6
  require 'digest'
@@ -55,8 +56,8 @@ module InspecTools
55
56
  @profile['supports'] = []
56
57
  @profile['attributes'] = []
57
58
  @profile['generator'] = {
58
- 'name': 'inspec_tools',
59
- 'version': VERSION
59
+ 'name': 'inspec',
60
+ 'version': Gem.loaded_specs['inspec'].version
60
61
  }
61
62
  end
62
63
 
@@ -90,10 +91,7 @@ module InspecTools
90
91
  @mapping['control.tags'].each do |tag|
91
92
  control['tags'][tag.first.to_s] = row[tag.last] unless row[tag.last].nil?
92
93
  end
93
- unless @mapping['control.tags']['severity'].nil? || row[@mapping['control.tags']['severity']].nil?
94
- control['impact'] = Utils::InspecUtil.get_impact(row[@mapping['control.tags']['severity']])
95
- control['tags']['severity'] = Utils::InspecUtil.get_impact_string(control['impact'])
96
- end
94
+ control['impact'] = Utils::InspecUtil.get_impact(row[@mapping['control.tags']['severity']]) unless @mapping['control.tags']['severity'].nil? || row[@mapping['control.tags']['severity']].nil?
97
95
  @controls << control
98
96
  end
99
97
  end
@@ -1,5 +1,5 @@
1
1
  summary parses an inspec results json to create a summary json
2
-
2
+
3
3
  Examples:
4
4
 
5
- inspec_tools summary -j examples/sample_json/rhel-simp.json -f -o summary.json
5
+ inspec_tools summary -j examples/sample_json/rhel-simp.json -o summary.json
@@ -3,7 +3,6 @@ require 'json'
3
3
  require 'cgi'
4
4
  require 'csv'
5
5
  require 'yaml'
6
- require 'pp'
7
6
  require_relative '../happy_mapper_tools/stig_attributes'
8
7
  require_relative '../happy_mapper_tools/stig_checklist'
9
8
  require_relative '../happy_mapper_tools/benchmark'
@@ -17,14 +16,12 @@ require_relative 'csv'
17
16
 
18
17
  module InspecTools
19
18
  class Inspec
20
- def initialize(inspec_json, metadata = '{}')
21
- @json = JSON.parse(inspec_json.gsub(/\\+u0000/, ''))
22
- @metadata = JSON.parse(metadata)
19
+ def initialize(inspec_json)
20
+ @json = JSON.parse(inspec_json)
23
21
  end
24
22
 
25
23
  def to_ckl(title = nil, date = nil, cklist = nil)
26
24
  @data = Utils::InspecUtil.parse_data_for_ckl(@json)
27
- @platform = Utils::InspecUtil.get_platform(@json)
28
25
  @title = generate_title title, @json, date
29
26
  @cklist = cklist
30
27
  @checklist = HappyMapperTools::StigChecklist::Checklist.new
@@ -84,7 +81,7 @@ module InspecTools
84
81
  inspec_json['controls'].each do |json_control|
85
82
  control = []
86
83
  headers.each do |key, _|
87
- control.push(json_control[key] || json_control['tags'][key] || json_control['results']&.collect { |result| result[key] }&.join(",\n") || nil)
84
+ control.push(json_control[key] || json_control['tags'][key] || (json_control['results']&.collect { |result| result[key] }&.join(",\n")) || nil)
88
85
  end
89
86
  data.push(control)
90
87
  end
@@ -113,45 +110,26 @@ module InspecTools
113
110
  end
114
111
  end
115
112
 
116
- def generate_ckl
117
- stigs = HappyMapperTools::StigChecklist::Stigs.new
118
- istig = HappyMapperTools::StigChecklist::IStig.new
119
-
120
- vuln_list = []
121
- @data.keys.each do |control_id|
122
- vuln_list.push(generate_vuln_data(@data[control_id]))
123
- end
124
-
125
- si_data = HappyMapperTools::StigChecklist::SiData.new
126
- si_data.name = 'stigid'
127
- si_data.data = ''
128
- if !@metadata['stigid'].nil?
129
- si_data.data = @metadata['stigid']
130
- end
131
-
132
- stig_info = HappyMapperTools::StigChecklist::StigInfo.new
133
- stig_info.si_data = si_data
134
- istig.stig_info = stig_info
135
-
136
- istig.vuln = vuln_list
137
- stigs.istig = istig
138
- @checklist.stig = stigs
139
-
140
- @checklist.asset = generate_asset
141
- end
142
-
143
113
  def generate_vuln_data(control)
144
114
  vuln = HappyMapperTools::StigChecklist::Vuln.new
145
115
  stig_data_list = []
146
116
 
147
- %w{Vuln_Num Group_Title Rule_ID Rule_Ver Rule_Title Vuln_Discuss Check_Content Fix_Text}.each do |attribute|
148
- stig_data_list << create_stig_data_element(attribute, control)
117
+ %w{
118
+ Vuln_Num Severity Group_Title Rule_ID Rule_Ver Rule_Title Vuln_Discuss
119
+ Check_Content Fix_Text CCI_REF
120
+ }.each do |param|
121
+ stigdata = HappyMapperTools::StigChecklist::StigData.new
122
+ stigdata.attrib = param
123
+ stigdata.data = control[param.downcase.to_sym]
124
+ stig_data_list.push(stigdata)
149
125
  end
150
- stig_data_list << handle_severity(control)
151
- stig_data_list += handle_cci_ref(control)
152
- stig_data_list << handle_stigref
153
126
 
154
- vuln.stig_data = stig_data_list.reject(&:nil?)
127
+ stigdata = HappyMapperTools::StigChecklist::StigData.new
128
+ stigdata.attrib = 'STIGRef'
129
+ stigdata.data = @title
130
+ stig_data_list.push(stigdata)
131
+
132
+ vuln.stig_data = stig_data_list
155
133
  vuln.status = Utils::InspecUtil.control_status(control)
156
134
  vuln.comments = "\nAutomated compliance tests brought to you by the MITRE corporation and the InSpec project.\n\nInspec Profile: #{control[:profile_name]}\nProfile shasum: #{control[:profile_shasum]}"
157
135
  vuln.finding_details = Utils::InspecUtil.control_finding_details(control, vuln.status)
@@ -161,66 +139,25 @@ module InspecTools
161
139
  vuln
162
140
  end
163
141
 
164
- def generate_asset
165
- asset = HappyMapperTools::StigChecklist::Asset.new
166
- asset.role = !@metadata['role'].nil? ? @metadata['role'] : 'Workstation'
167
- asset.type = !@metadata['type'].nil? ? @metadata['type'] : 'Computing'
168
- asset.host_name = generate_hostname
169
- asset.host_ip = generate_ip
170
- asset.host_mac = generate_mac
171
- asset.host_fqdn = generate_fqdn
172
- asset.tech_area = !@metadata['tech_area'].nil? ? @metadata['tech_area'] : ''
173
- asset.target_key = !@metadata['target_key'].nil? ? @metadata['target_key'] : ''
174
- asset.web_or_database = !@metadata['web_or_database'].nil? ? @metadata['web_or_database'] : '0'
175
- asset.web_db_site = !@metadata['web_db_site'].nil? ? @metadata['web_db_site'] : ''
176
- asset.web_db_instance = !@metadata['web_db_instance'].nil? ? @metadata['web_db_instance'] : ''
177
- asset
178
- end
179
-
180
- def generate_hostname
181
- hostname = @metadata['hostname']
182
- if hostname.nil? && @platform.nil?
183
- hostname = ''
184
- elsif hostname.nil?
185
- hostname = @platform[:hostname]
186
- end
187
- hostname
188
- end
189
-
190
- def generate_mac
191
- mac = @metadata['mac']
192
- if mac.nil?
193
- nics = @platform.nil? ? [] : @platform[:network]
194
- nics_macs = []
195
- nics.each do |nic|
196
- nics_macs.push(nic[:mac])
197
- end
198
- mac = nics_macs.join(',')
199
- end
200
- mac
201
- end
202
-
203
- def generate_fqdn
204
- fqdn = @metadata['fqdn']
205
- if fqdn.nil? && @platform.nil?
206
- fqdn = ''
207
- elsif fqdn.nil?
208
- fqdn = @platform[:fqdn]
209
- end
210
- fqdn
142
+ def generate_title(title, json, date)
143
+ title ||= "Untitled - Checklist Created from Automated InSpec Results JSON; Profiles: #{json['profiles'].map { |x| x['name'] }.join(' | ')}"
144
+ title + " Checklist Date: #{date || Date.today.to_s}"
211
145
  end
212
146
 
213
- def generate_ip
214
- ip = @metadata['ip']
215
- if ip.nil?
216
- nics = @platform.nil? ? [] : @platform[:network]
217
- nics_ips = []
218
- nics.each do |nic|
219
- nics_ips.push(*nic[:ip])
220
- end
221
- ip = nics_ips.join(',')
147
+ def generate_ckl
148
+ stigs = HappyMapperTools::StigChecklist::Stigs.new
149
+ istig = HappyMapperTools::StigChecklist::IStig.new
150
+ vuln_list = []
151
+ @data.keys.each do |control_id|
152
+ vuln_list.push(generate_vuln_data(@data[control_id]))
222
153
  end
223
- ip
154
+ istig.stig_info = HappyMapperTools::StigChecklist::StigInfo.new
155
+ istig.vuln = vuln_list
156
+ stigs.istig = istig
157
+ @checklist.stig = stigs
158
+ asset = HappyMapperTools::StigChecklist::Asset.new
159
+ asset.type = 'Computing'
160
+ @checklist.asset = asset
224
161
  end
225
162
 
226
163
  def populate_header
@@ -270,7 +207,7 @@ module InspecTools
270
207
  group.rule.reference.dc_identifier = @attribute['reference.dc.identifier']
271
208
 
272
209
  group.rule.ident = HappyMapperTools::Benchmark::Ident.new
273
- group.rule.ident.system = 'https://public.cyber.mil/stigs/cci/'
210
+ group.rule.ident.system = 'http://iase.disa.mil/cci'
274
211
  group.rule.ident.ident = control['cci']
275
212
 
276
213
  group.rule.fixtext = HappyMapperTools::Benchmark::Fixtext.new
@@ -291,41 +228,5 @@ module InspecTools
291
228
  end
292
229
  @benchmark.group = group_array
293
230
  end
294
-
295
- def generate_title(title, json, date)
296
- title ||= "Untitled - Checklist Created from Automated InSpec Results JSON; Profiles: #{json['profiles'].map { |x| x['name'] }.join(' | ')}"
297
- title + " Checklist Date: #{date || Date.today.to_s}"
298
- end
299
-
300
- def create_stig_data_element(attribute, control)
301
- return HappyMapperTools::StigChecklist::StigData.new(attribute, control[attribute.downcase.to_sym]) unless control[attribute.downcase.to_sym].nil?
302
- end
303
-
304
- def handle_severity(control)
305
- return if control[:impact].nil?
306
-
307
- value = Utils::InspecUtil.get_impact_string(control[:impact], use_cvss_terms: false)
308
- return if value == 'none'
309
-
310
- HappyMapperTools::StigChecklist::StigData.new('Severity', value)
311
- end
312
-
313
- def handle_cci_ref(control)
314
- return [] if control[:cci_ref].nil?
315
-
316
- cci_data = []
317
- if control[:cci_ref].respond_to?(:each)
318
- control[:cci_ref].each do |cci_number|
319
- cci_data << HappyMapperTools::StigChecklist::StigData.new('CCI_REF', cci_number)
320
- end
321
- cci_data
322
- else
323
- cci_data << HappyMapperTools::StigChecklist::StigData.new('CCI_REF', control[:cci_ref])
324
- end
325
- end
326
-
327
- def handle_stigref
328
- HappyMapperTools::StigChecklist::StigData.new('STIGRef', @title)
329
- end
330
231
  end
331
232
  end