Class: Nexpose::ScanTemplate
- Inherits:
-
Object
- Object
- Nexpose::ScanTemplate
- Includes:
- Sanitize
- Defined in:
- lib/nexpose/scan_template.rb
Overview
Configuration object for a scan template.
The constructor is designed to take a valid XML representation of a scan template. If you wish to create a new scan template from scratch, use the #load method without a template ID. If you wish to copy and modify an existing template, use the #copy method.
This class is only a partial representation of some of the features available for configuration.
Instance Attribute Summary collapse
-
#xml ⇒ Object
readonly
Parsed XML of a scan template.
Class Method Summary collapse
-
.copy(nsc, id) ⇒ ScanTemplate
Copy an existing scan template, changing the id and title.
-
.load(nsc, id = nil) ⇒ ScanTemplate
Load a scan template.
Instance Method Summary collapse
- #_disable_check(check, elem) ⇒ Object
- #_enable_check(check, elem) ⇒ Object
- #_remove_check(check, elem) ⇒ Object
-
#checks_by_category ⇒ Array[String]
Get a list of the check categories enabled for this scan template.
-
#checks_by_type ⇒ Array[String]
Get a list of the check types enabled for this scan template.
-
#correlate=(enable) ⇒ Object
Adjust whether to correlate reliable checks with regular checks.
-
#correlate? ⇒ Boolean
Whether to correlate reliable checks with regular checks.
-
#delete(nsc) ⇒ Object
Delete this scan template from the console.
-
#description ⇒ String
Description of this scan template.
-
#description=(description) ⇒ Object
Assign a description to this scan template.
-
#disable_checks_by_category(category) ⇒ Object
Disable checks by category for this template.
-
#disable_checks_by_type(type) ⇒ Object
Disable checks by type for this template.
-
#disable_vuln_check(check_id) ⇒ Object
Disable individual check for this template.
-
#enable_checks_by_category(category) ⇒ Object
Enable checks by category for this template.
-
#enable_checks_by_type(type) ⇒ Object
Enable checks by type for this template.
-
#enable_vuln_check(check_id) ⇒ Object
Enable individual check for this template.
-
#id ⇒ String
Unique identifier of the scan template.
-
#initialize(xml) ⇒ ScanTemplate
constructor
A new instance of ScanTemplate.
-
#name ⇒ String
Name or title of this scan template.
-
#name=(name) ⇒ Object
Assign name to this scan template.
-
#policy_scanning=(enable) ⇒ Object
Adjust whether to perform policy scanning with this template.
-
#policy_scanning? ⇒ Boolean
Whether policy scanning in enabled.
-
#potential_checks=(enable) ⇒ Object
Adjust whether to perform potential vulnerability checks with this template.
-
#potential_checks? ⇒ Boolean
Whether potential vulnerability checks are performed with this template.
-
#remove_checks_by_category(category) ⇒ Object
Remove checks by category for this template.
-
#remove_checks_by_type(type) ⇒ Object
Remove checks by type for this template.
-
#remove_vuln_check(check_id) ⇒ Object
Remove individual check for this template.
-
#save(nsc) ⇒ Object
Save this scan template configuration to a Nexpose console.
-
#unsafe_checks=(enable) ⇒ Object
Adjust whether to perform unsafe vulnerability checks with this template.
-
#unsafe_checks? ⇒ Boolean
Whether unsafe vulnerability checks are performed by this template.
-
#vuln_checks ⇒ Array[String]
Get a list of the individual vuln checks enabled for this scan template.
-
#vuln_scanning=(enable) ⇒ Object
Adjust whether to perform vuln scanning with this template.
-
#vuln_scanning? ⇒ Boolean
Whether vuln scanning in enabled.
-
#web_spidering=(enable) ⇒ Object
Adjust whether to perform web spidering with this template.
-
#web_spidering? ⇒ Boolean
Whether web spidering in enabled.
Methods included from Sanitize
Constructor Details
#initialize(xml) ⇒ ScanTemplate
Returns a new instance of ScanTemplate.
55 56 57 |
# File 'lib/nexpose/scan_template.rb', line 55 def initialize(xml) @xml = REXML::Document.new(xml) end |
Instance Attribute Details
#xml ⇒ Object (readonly)
Parsed XML of a scan template.
52 53 54 |
# File 'lib/nexpose/scan_template.rb', line 52 def xml @xml end |
Class Method Details
.copy(nsc, id) ⇒ ScanTemplate
Copy an existing scan template, changing the id and title.
349 350 351 352 353 354 |
# File 'lib/nexpose/scan_template.rb', line 349 def self.copy(nsc, id) dupe = load(nsc, id) dupe.id = '#NewScanTemplate#' dupe.title = "#{dupe.title} Copy" dupe end |
.load(nsc, id = nil) ⇒ ScanTemplate
Load a scan template.
333 334 335 336 337 338 339 340 341 |
# File 'lib/nexpose/scan_template.rb', line 333 def self.load(nsc, id = nil) if id response = JSON.parse(AJAX.get(nsc, "/data/scan/templates/#{URI.encode(id)}")) xml = response['value'] else xml = AJAX.get(nsc, '/ajax/scantemplate_config.txml') end new(xml) end |
Instance Method Details
#_disable_check(check, elem) ⇒ Object
259 260 261 262 263 |
# File 'lib/nexpose/scan_template.rb', line 259 def _disable_check(check, elem) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/#{elem}[@name='#{check}']") checks.elements['Disabled'].add_element(elem, { 'name' => check }) end |
#_enable_check(check, elem) ⇒ Object
253 254 255 256 257 |
# File 'lib/nexpose/scan_template.rb', line 253 def _enable_check(check, elem) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/#{elem}[@name='#{check}']") checks.elements['Enabled'].add_element(elem, { 'name' => check }) end |
#_remove_check(check, elem) ⇒ Object
265 266 267 268 269 |
# File 'lib/nexpose/scan_template.rb', line 265 def _remove_check(check, elem) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/#{elem}[@name='#{check}']") checks.elements.delete("Enabled/#{elem}[@name='#{check}']") end |
#checks_by_category ⇒ Array[String]
Get a list of the check categories enabled for this scan template.
189 190 191 192 |
# File 'lib/nexpose/scan_template.rb', line 189 def checks_by_category checks = REXML::XPath.first(@xml, '//VulnerabilityChecks/Enabled') checks.elements.to_a('VulnCategory').map { |c| c.attributes['name'] } end |
#checks_by_type ⇒ Array[String]
Get a list of the check types enabled for this scan template.
223 224 225 226 |
# File 'lib/nexpose/scan_template.rb', line 223 def checks_by_type checks = REXML::XPath.first(@xml, '//VulnerabilityChecks/Enabled') checks.elements.to_a('CheckType').map { |c| c.attributes['name'] } end |
#correlate=(enable) ⇒ Object
Adjust whether to correlate reliable checks with regular checks.
152 153 154 155 |
# File 'lib/nexpose/scan_template.rb', line 152 def correlate=(enable) vuln_checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') vuln_checks.attributes['correlate'] = enable ? '1' : '0' end |
#correlate? ⇒ Boolean
Returns Whether to correlate reliable checks with regular checks.
145 146 147 148 |
# File 'lib/nexpose/scan_template.rb', line 145 def correlate? vuln_checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') vuln_checks.attributes['correlate'] == '1' end |
#delete(nsc) ⇒ Object
Delete this scan template from the console. Cannot be used to delete a built-in template.
361 362 363 |
# File 'lib/nexpose/scan_template.rb', line 361 def delete(nsc) nsc.delete_scan_template(@id) end |
#description ⇒ String
Returns Description of this scan template.
86 87 88 89 |
# File 'lib/nexpose/scan_template.rb', line 86 def description desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') desc.nil? ? nil : desc.text.to_s end |
#description=(description) ⇒ Object
Assign a description to this scan template. Require attribute.
93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/nexpose/scan_template.rb', line 93 def description=(description) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.text = replace_entities(description) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_text(description) root.add_element(desc) end end |
#disable_checks_by_category(category) ⇒ Object
Disable checks by category for this template.
206 207 208 |
# File 'lib/nexpose/scan_template.rb', line 206 def disable_checks_by_category(category) _disable_check(category, 'VulnCategory') end |
#disable_checks_by_type(type) ⇒ Object
Disable checks by type for this template.
240 241 242 |
# File 'lib/nexpose/scan_template.rb', line 240 def disable_checks_by_type(type) _disable_check(type, 'CheckType') end |
#disable_vuln_check(check_id) ⇒ Object
Disable individual check for this template.
294 295 296 297 298 |
# File 'lib/nexpose/scan_template.rb', line 294 def disable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Enabled/Check[@id='#{check_id}']") checks.elements['Disabled'].add_element('Check', { 'id' => check_id }) end |
#enable_checks_by_category(category) ⇒ Object
Enable checks by category for this template.
198 199 200 |
# File 'lib/nexpose/scan_template.rb', line 198 def enable_checks_by_category(category) _enable_check(category, 'VulnCategory') end |
#enable_checks_by_type(type) ⇒ Object
Enable checks by type for this template.
232 233 234 |
# File 'lib/nexpose/scan_template.rb', line 232 def enable_checks_by_type(type) _enable_check(type, 'CheckType') end |
#enable_vuln_check(check_id) ⇒ Object
Enable individual check for this template.
284 285 286 287 288 |
# File 'lib/nexpose/scan_template.rb', line 284 def enable_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements['Enabled'].add_element('Check', { 'id' => check_id }) end |
#id ⇒ String
Returns Unique identifier of the scan template.
60 61 62 63 |
# File 'lib/nexpose/scan_template.rb', line 60 def id root = REXML::XPath.first(xml, 'ScanTemplate') root.attributes['id'] end |
#name ⇒ String
Returns Name or title of this scan template.
66 67 68 69 |
# File 'lib/nexpose/scan_template.rb', line 66 def name desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') desc.nil? ? nil : desc.attributes['title'] end |
#name=(name) ⇒ Object
Assign name to this scan template. Required attribute.
73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/nexpose/scan_template.rb', line 73 def name=(name) desc = REXML::XPath.first(@xml, 'ScanTemplate/templateDescription') if desc desc.attributes['title'] = replace_entities(name) else root = REXML::XPath.first(xml, 'ScanTemplate') desc = REXML::Element.new('templateDescription') desc.add_attribute('title', name) root.add_element(desc) end end |
#policy_scanning=(enable) ⇒ Object
Adjust whether to perform policy scanning with this template.
126 127 128 129 |
# File 'lib/nexpose/scan_template.rb', line 126 def policy_scanning=(enable) gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disablePolicyScan'] = enable ? '0' : '1' end |
#policy_scanning? ⇒ Boolean
Returns Whether policy scanning in enabled.
119 120 121 122 |
# File 'lib/nexpose/scan_template.rb', line 119 def policy_scanning? gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disablePolicyScan'] == '0' end |
#potential_checks=(enable) ⇒ Object
Adjust whether to perform potential vulnerability checks with this template.
180 181 182 183 |
# File 'lib/nexpose/scan_template.rb', line 180 def potential_checks=(enable) checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') checks.attributes['potential'] = enable ? '1' : '0' end |
#potential_checks? ⇒ Boolean
Returns Whether potential vulnerability checks are performed with this template.
173 174 175 176 |
# File 'lib/nexpose/scan_template.rb', line 173 def potential_checks? checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') checks.attributes['potential'] == '1' end |
#remove_checks_by_category(category) ⇒ Object
Remove checks by category for this template. Removes both enabled and disabled checks.
215 216 217 |
# File 'lib/nexpose/scan_template.rb', line 215 def remove_checks_by_category(category) _remove_check(category, 'VulnCategory') end |
#remove_checks_by_type(type) ⇒ Object
Remove checks by type for this template. Removes both enabled and disabled checks.
249 250 251 |
# File 'lib/nexpose/scan_template.rb', line 249 def remove_checks_by_type(type) _remove_check(type, 'CheckType') end |
#remove_vuln_check(check_id) ⇒ Object
Remove individual check for this template. Removes both enabled and disabled checks.
305 306 307 308 309 |
# File 'lib/nexpose/scan_template.rb', line 305 def remove_vuln_check(check_id) checks = REXML::XPath.first(@xml, '//VulnerabilityChecks') checks.elements.delete("Disabled/Check[@id='#{check_id}']") checks.elements.delete("Enabled/Check[@id='#{check_id}']") end |
#save(nsc) ⇒ Object
Save this scan template configuration to a Nexpose console.
315 316 317 318 319 320 321 322 323 324 |
# File 'lib/nexpose/scan_template.rb', line 315 def save(nsc) root = REXML::XPath.first(@xml, 'ScanTemplate') if root.attributes['id'] == '#NewScanTemplate#' response = JSON.parse(AJAX.post(nsc, '/data/scan/templates', xml)) root.attributes['id'] = response['value'] else response = JSON.parse(AJAX.put(nsc, "/data/scan/templates/#{URI.encode(id)}", xml)) end response['value'] end |
#unsafe_checks=(enable) ⇒ Object
Adjust whether to perform unsafe vulnerability checks with this template.
166 167 168 169 |
# File 'lib/nexpose/scan_template.rb', line 166 def unsafe_checks=(enable) checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') checks.attributes['unsafe'] = enable ? '1' : '0' end |
#unsafe_checks? ⇒ Boolean
Returns Whether unsafe vulnerability checks are performed by this template.
159 160 161 162 |
# File 'lib/nexpose/scan_template.rb', line 159 def unsafe_checks? checks = REXML::XPath.first(@xml, 'ScanTemplate/VulnerabilityChecks') checks.attributes['unsafe'] == '1' end |
#vuln_checks ⇒ Array[String]
Get a list of the individual vuln checks enabled for this scan template.
275 276 277 278 |
# File 'lib/nexpose/scan_template.rb', line 275 def vuln_checks checks = REXML::XPath.first(@xml, '//VulnerabilityChecks/Enabled') checks.elements.to_a('Check').map { |c| c.attributes['id'] } end |
#vuln_scanning=(enable) ⇒ Object
Adjust whether to perform vuln scanning with this template.
113 114 115 116 |
# File 'lib/nexpose/scan_template.rb', line 113 def vuln_scanning=(enable) gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disableVulnScan'] = enable ? '0' : '1' end |
#vuln_scanning? ⇒ Boolean
Returns Whether vuln scanning in enabled.
106 107 108 109 |
# File 'lib/nexpose/scan_template.rb', line 106 def vuln_scanning? gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disableVulnScan'] == '0' end |
#web_spidering=(enable) ⇒ Object
Adjust whether to perform web spidering with this template.
139 140 141 142 |
# File 'lib/nexpose/scan_template.rb', line 139 def web_spidering=(enable) gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disableWebSpider'] = enable ? '0' : '1' end |
#web_spidering? ⇒ Boolean
Returns Whether web spidering in enabled.
132 133 134 135 |
# File 'lib/nexpose/scan_template.rb', line 132 def web_spidering? gen = REXML::XPath.first(@xml, 'ScanTemplate/General') gen.attributes['disableWebSpider'] == '0' end |