Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

using Nokogiri::XML::Reader #15

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 27 additions & 19 deletions lib/dradis/plugins/nessus/importer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,26 +11,34 @@ def import(params={})
doc = Nokogiri::XML( file_content )
logger.info{'Done.'}

if doc.xpath('/NessusClientData_v2/Report').empty?
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You're loosing important validation with this change, no?

error = "No reports were detected in the uploaded file (/NessusClientData_v2/Report). Ensure you uploaded a Nessus XML v2 (.nessus) report."
logger.fatal{ error }
content_service.create_note text: error
return false
# if doc.xpath('/NessusClientData_v2/Report').empty?
# error = "No reports were detected in the uploaded file (/NessusClientData_v2/Report). Ensure you uploaded a Nessus XML v2 (.nessus) report."
# logger.fatal{ error }
# content_service.create_note text: error
# return false
# end

logger.info { 'Parsing nessus output file...' }
Nokogiri::XML::Reader(file_content).each do |node|
if node.name == 'ReportHost' && node.node_type == Nokogiri::XML::Reader::TYPE_ELEMENT
process_report_host(Nokogiri::XML(node.outer_xml).at('./ReportHost'))
end
end

doc.xpath('/NessusClientData_v2/Report').each do |xml_report|
report_label = xml_report.attributes['name'].value
logger.info{ "Processing report: #{report_label}" }
# No need to create a report node for each report. It may be good to
# create a plugin.output/nessus.reports with info for each scan, but
# for the time being we just append stuff to the Host
# report_node = parent.children.find_or_create_by_label(report_label)

xml_report.xpath('./ReportHost').each do |xml_host|
process_report_host(xml_host)
end #/ReportHost
logger.info{ "Report processed." }
end #/Report
logger.info { 'Done.' }

# doc.xpath('/NessusClientData_v2/Report').each do |xml_report|
# report_label = xml_report.attributes['name'].value
# logger.info{ "Processing report: #{report_label}" }
# # No need to create a report node for each report. It may be good to
# # create a plugin.output/nessus.reports with info for each scan, but
# # for the time being we just append stuff to the Host
# # report_node = parent.children.find_or_create_by_label(report_label)
#
# xml_report.xpath('./ReportHost').each do |xml_host|
# process_report_host(xml_host)
# end #/ReportHost
# logger.info{ "Report processed." }
# end #/Report

return true
end # /import
Expand Down
2 changes: 1 addition & 1 deletion spec/dradis/plugins/nessus/field_processor_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
value = processor.value(field: 'report_item.description')
expect(value).to_not be_empty

expect(value).to include("* A denial of service vulnerability exists relating to the 'mod_dav' module as it relates to MERGE requests. (CVE-2013-1896)")
expect(value).to include("* A denial of service vulnerability exists relating to the 'mod_dav' module as it relates to MERGE requests.\n\n (CVE-2013-1896)")
end
end
end
Expand Down