Class: NessusXMLRPC::NessusXMLRPCnokogiri

Inherits:
NessusXMLRPCrexml show all
Defined in:
lib/nessus-xmlrpc.rb

Overview

So, check NessusXMLRPCrexml for method documentation

Instance Method Summary collapse

Methods inherited from NessusXMLRPCrexml

#initialize, #logged_in, #nessus_http_request, #plugins_list, #report_delete, #report_file1_download, #report_file_download, #scan_finished, #scan_pause, #scan_pause_all, #scan_resume, #scan_resume_all, #scan_stop, #scan_stop_all, #users_list

Constructor Details

This class inherits a constructor from NessusXMLRPC::NessusXMLRPCrexml

Instance Method Details

#login(user, password) ⇒ Object



450
451
452
453
454
455
456
457
458
459
460
461
# File 'lib/nessus-xmlrpc.rb', line 450

def (user, password)
	post = { "login" => user, "password" => password }
	docxml=nessus_request('login', post)
	if docxml == '' 
		@token=''
	else
		@token = docxml.xpath("/reply/contents/token").collect(&:text)[0]
		@name = docxml.xpath("/reply/contents/user/name").collect(&:text)[0]
		@admin = docxml.xpath("/reply/contents/user/admin").collect(&:text)[0]
	end
		
end

#nessus_request(uri, post_data) ⇒ Object

return: nokogiri XML file



435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/nessus-xmlrpc.rb', line 435

def nessus_request(uri, post_data) 
	body=nessus_http_request(uri, post_data)
	docxml = Nokogiri::XML.parse(body)
	begin 
	status = docxml.xpath("/reply/status").collect(&:text)[0]
	rescue
		puts "[e] error in XML parsing"
	end
	if status == "OK"
		return docxml 
	else 
		return ''
	end
end

#policy_get_firstObject



517
518
519
520
521
522
523
# File 'lib/nessus-xmlrpc.rb', line 517

def policy_get_first
	post= { "token" => @token } 
	docxml=nessus_request('policy/list', post)
	id=docxml.xpath("/reply/contents/policies/policy/policyID").collect(&:text)[0]
	name=docxml.xpath("/reply/contents/policies/policy/policyName").collect(&:text)[0]
	return id, name
end

#policy_get_id(textname) ⇒ Object



505
506
507
508
509
# File 'lib/nessus-xmlrpc.rb', line 505

def policy_get_id(textname) 
	post= { "token" => @token } 
	docxml=nessus_request('policy/list', post)
	return docxml.xpath("/reply/contents/policies/policy/policyName[text()='"+textname+"']/..policyID").collect(&:text)[0]
end

#policy_list_namesObject



525
526
527
528
529
# File 'lib/nessus-xmlrpc.rb', line 525

def policy_list_names
	post= { "token" => @token } 
	docxml=nessus_request('policy/list', post)
	return docxml.xpath("/reply/contents/policies/policy/policyName").collect(&:text)
end

#policy_list_uidsObject



511
512
513
514
515
# File 'lib/nessus-xmlrpc.rb', line 511

def policy_list_uids
	post= { "token" => @token } 
	docxml=nessus_request('policy/list', post)
	return docxml.xpath("/reply/contents/policies/policy/policyID").collect(&:text)
end

#report_get_host(report_id, host) ⇒ Object



537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
# File 'lib/nessus-xmlrpc.rb', line 537

def report_get_host(report_id,host)
	post= { "token" => @token, "report" => report_id } 
	docxml=nessus_request('report/hosts', post)
	items = docxml.xpath("/reply/contents/hostList/host/hostname[text()='"+host+"']")
	retval = items.collect do |item|
		tmpitem = {}
		[
			[:severity, 'severity'],
			[:current, 'scanProgressCurrent'],
			[:total, 'scanProgressTotal']
		].collect do |key, xpath|
		tmpitem[key] = item.at_xpath(xpath).content
		end
		tmpitem
	end
	return retval
end

#report_hosts(report_id) ⇒ Object



531
532
533
534
535
# File 'lib/nessus-xmlrpc.rb', line 531

def report_hosts(report_id)
	post= { "token" => @token, "report" => report_id } 
	docxml=nessus_request('report/hosts', post)
	return docxml.xpath("/reply/contents/hostList/host/hostname").collect(&:text)
end

#scan_list_hashObject



486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
# File 'lib/nessus-xmlrpc.rb', line 486

def scan_list_hash
	post= { "token" => @token } 
	docxml=nessus_request('scan/list', post)
	items = docxml.xpath("/reply/contents/scans/scanList/scan")
	retval = items.collect do |item|
		tmpitem = {}
		[
			[:id, 'uuid'],
			[:name, 'readableName'],
			[:current, 'completion_current'],
			[:total, 'completion_total']
		].collect do |key, xpath|
		tmpitem[key] = item.at_xpath(xpath).content
		end
		tmpitem
	end
	return retval
end

#scan_list_uidsObject



480
481
482
483
484
# File 'lib/nessus-xmlrpc.rb', line 480

def scan_list_uids
	post= { "token" => @token } 
	docxml=nessus_request('scan/list', post)
	return docxml.xpath("/reply/contents/scans/scanList/scan/uuid").collect(&:text)
end

#scan_new(policy_id, scan_name, target) ⇒ Object



463
464
465
466
467
468
469
470
471
472
# File 'lib/nessus-xmlrpc.rb', line 463

def scan_new(policy_id,scan_name,target)
	post= { "token" => @token, "policy_id" => policy_id, "scan_name" => scan_name, "target" => target } 
	docxml=nessus_request('scan/new', post)
	if docxml == '' 
		return ''
	else
		uuid=docxml.xpath("/reply/contents/scan/uuid").collect(&:text)[0]
		return uuid
	end	
end

#scan_status(uuid) ⇒ Object



474
475
476
477
478
# File 'lib/nessus-xmlrpc.rb', line 474

def scan_status(uuid)
	post= { "token" => @token, "report" => uuid } 
	docxml=nessus_request('report/list', post)
	return docxml.xpath("/reply/contents/reports/report/name[text()='"+uuid+"']/../status").collect(&:text)[0]
end