class NessusXMLRPC::NessusXMLRPCnokogiri
Class which uses nokogiri to parse nessus XML RPC replies. It is adviseable to use NessusXMLRPC
class, not this class directly. As NessusXMLRPC
class will use nokogiri or rexml, depending on availability.
Documentation for this class documents only differences from NessusXMLRPCrexml
. So, check NessusXMLRPCrexml for method documentation
Public Instance Methods
login(user, password)
click to toggle source
# File lib/nessus-xmlrpc.rb, line 450 def login(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)
click to toggle source
send standard Nessus XML request and check
return: nokogiri XML file
# 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_first()
click to toggle source
# 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)
click to toggle source
# 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_names()
click to toggle source
# 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_uids()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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_hash()
click to toggle source
# 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_uids()
click to toggle source
# 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)
click to toggle source
# 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)
click to toggle source
# 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