Module: Nexpose::NexposeAPI
- Included in:
- Connection
- Defined in:
- lib/nexpose.rb
Instance Method Summary collapse
- #asset_group_delete(connection, id, debug = false) ⇒ Object
- #console_command(cmd_string) ⇒ Object
- #device_delete(param) ⇒ Object
- #make_xml(name, opts = {}, data = '') ⇒ Object
- #report_config_delete(param) ⇒ Object
- #report_delete(param) ⇒ Object
- #report_generate(param) ⇒ Object
- #report_history(param) ⇒ Object
- #report_last(param) ⇒ Object
- #report_template_listing ⇒ Object
- #scan_activity ⇒ Object
- #scan_statistics(param) ⇒ Object
- #scan_status(param) ⇒ Object
- #scan_stop(param) ⇒ Object
- #site_delete(param) ⇒ Object
- #site_device_listing(site_id) ⇒ Object
- #site_listing ⇒ Object
- #system_information ⇒ Object
Instance Method Details
#asset_group_delete(connection, id, debug = false) ⇒ Object
336 337 338 339 |
# File 'lib/nexpose.rb', line 336 def asset_group_delete(connection, id, debug = false) r = execute(make_xml('AssetGroupDeleteRequest', { 'group-id' => param })) r.success end |
#console_command(cmd_string) ⇒ Object
408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 |
# File 'lib/nexpose.rb', line 408 def console_command(cmd_string) xml = make_xml('ConsoleCommandRequest', { }) cmd = REXML::Element.new('Command') cmd.text = cmd_string xml << cmd r = execute(xml) if(r.success) res = "" r.res.elements.each("//Output") do |out| res << out.text.to_s end return res else return false end end |
#device_delete(param) ⇒ Object
331 332 333 334 |
# File 'lib/nexpose.rb', line 331 def device_delete(param) r = execute(make_xml('DeviceDeleteRequest', { 'site-id' => param })) r.success end |
#make_xml(name, opts = {}, data = '') ⇒ Object
216 217 218 219 220 221 222 223 224 225 226 227 228 229 |
# File 'lib/nexpose.rb', line 216 def make_xml(name, opts={}, data='') xml = REXML::Element.new(name) if(@session_id) xml.attributes['session-id'] = @session_id end opts.keys.each do |k| xml.attributes[k] = "#{opts[k]}" end xml.text = data xml end |
#report_config_delete(param) ⇒ Object
321 322 323 324 |
# File 'lib/nexpose.rb', line 321 def report_config_delete(param) r = execute(make_xml('ReportDeleteRequest', { 'reportcfg-id' => param })) r.success end |
#report_delete(param) ⇒ Object
326 327 328 329 |
# File 'lib/nexpose.rb', line 326 def report_delete(param) r = execute(make_xml('ReportDeleteRequest', { 'report-id' => param })) r.success end |
#report_generate(param) ⇒ Object
296 297 298 299 |
# File 'lib/nexpose.rb', line 296 def report_generate(param) r = execute(make_xml('ReportGenerateRequest', { 'report-id' => param })) r.success end |
#report_history(param) ⇒ Object
317 318 319 |
# File 'lib/nexpose.rb', line 317 def report_history(param) execute(make_xml('ReportHistoryRequest', { 'reportcfg-id' => param })) end |
#report_last(param) ⇒ Object
301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/nexpose.rb', line 301 def report_last(param) r = execute(make_xml('ReportHistoryRequest', { 'reportcfg-id' => param })) res = nil if(r.success) stk = [] r.res.elements.each("//ReportSummary") do |rep| stk << [ rep.attributes['id'].to_i, rep.attributes['report-URI'] ] end if (stk.length > 0) stk.sort!{|a,b| b[0] <=> a[0]} res = stk[0][1] end end res end |
#report_template_listing ⇒ Object
384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 |
# File 'lib/nexpose.rb', line 384 def report_template_listing r = execute(make_xml('ReportTemplateListingRequest', { })) if(r.success) res = [] r.res.elements.each("//ReportTemplateSummary") do |template| desc = '' template.elements.each("//description") do |ent| desc = ent.text end res << { :template_id => template.attributes['id'].to_s, :name => template.attributes['name'].to_s, :description => desc.to_s } end return res else return false end end |
#scan_activity ⇒ Object
241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/nexpose.rb', line 241 def scan_activity r = execute(make_xml('ScanActivityRequest', { })) if(r.success) res = [] r.res.elements.each("//ScanSummary") do |scan| res << { :scan_id => scan.attributes['scan-id'].to_i, :site_id => scan.attributes['site-id'].to_i, :engine_id => scan.attributes['engine-id'].to_i, :status => scan.attributes['status'].to_s, :start_time => Date.parse(scan.attributes['startTime'].to_s).to_time } end return res else return false end end |
#scan_statistics(param) ⇒ Object
260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 |
# File 'lib/nexpose.rb', line 260 def scan_statistics(param) r = execute(make_xml('ScanStatisticsRequest', {'scan-id' => param })) if(r.success) res = {} r.res.elements.each("//ScanSummary/nodes") do |node| res[:nodes] = {} node.attributes.keys.each do |k| res[:nodes][k] = node.attributes[k].to_i end end r.res.elements.each("//ScanSummary/tasks") do |task| res[:task] = {} task.attributes.keys.each do |k| res[:task][k] = task.attributes[k].to_i end end r.res.elements.each("//ScanSummary/vulnerabilities") do |vuln| res[:vulns] ||= {} k = vuln.attributes['status'] + (vuln.attributes['severity'] ? ("-" + vuln.attributes['severity']) : '') res[:vulns][k] = vuln.attributes['count'].to_i end r.res.elements.each("//ScanSummary") do |summ| res[:summary] = {} summ.attributes.keys.each do |k| res[:summary][k] = summ.attributes[k] if (res[:summary][k] =~ /^\d+$/) res[:summary][k] = res[:summary][k].to_i end end end return res else return false end end |
#scan_status(param) ⇒ Object
236 237 238 239 |
# File 'lib/nexpose.rb', line 236 def scan_status(param) r = execute(make_xml('ScanStatusRequest', { 'scan-id' => param })) r.success ? r.attributes['status'] : nil end |
#scan_stop(param) ⇒ Object
231 232 233 234 |
# File 'lib/nexpose.rb', line 231 def scan_stop(param) r = execute(make_xml('ScanStopRequest', { 'scan-id' => param })) r.success end |
#site_delete(param) ⇒ Object
341 342 343 344 |
# File 'lib/nexpose.rb', line 341 def site_delete(param) r = execute(make_xml('SiteDeleteRequest', { 'site-id' => param })) r.success end |
#site_device_listing(site_id) ⇒ Object
365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 |
# File 'lib/nexpose.rb', line 365 def site_device_listing(site_id) r = execute(make_xml('SiteDeviceListingRequest', { 'site-id' => site_id.to_s })) if(r.success) res = [] r.res.elements.each("//device") do |device| res << { :device_id => device.attributes['id'].to_i, :address => device.attributes['address'].to_s, :risk_factor => device.attributes['risk_factor'].to_f, :risk_score => device.attributes['risk_score'].to_f, } end return res else return false end end |
#site_listing ⇒ Object
346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 |
# File 'lib/nexpose.rb', line 346 def site_listing r = execute(make_xml('SiteListingRequest', { })) if(r.success) res = [] r.res.elements.each("//SiteSummary") do |site| res << { :site_id => site.attributes['id'].to_i, :name => site.attributes['name'].to_s, :risk_factor => site.attributes['risk_factor'].to_f, :risk_score => site.attributes['risk_score'].to_f, } end return res else return false end end |
#system_information ⇒ Object
428 429 430 431 432 433 434 435 436 437 438 439 440 441 |
# File 'lib/nexpose.rb', line 428 def system_information r = execute(make_xml('SystemInformationRequest', { })) if(r.success) res = {} r.res.elements.each("//Statistic") do |stat| res[ stat.attributes['name'].to_s ] = stat.text.to_s end return res else return false end end |