如何解决使用 Ruby 解析和显示 XML
我需要(想要)使用 ruby 脚本解析 Nessus 输出(XML),并最终将其输出到 CSV 和 HTML 文件。我是 Ruby 的新手,所以在我学习的时候,我会对终端的一些输出感到满意。下面是 Nessus 输出的示例和我迄今为止构建的脚本。该脚本不会按原样返回任何错误,但也不会返回我需要的任何数据。有人能指出我正确的方向吗?
</NessusClientData_v2>
</Report>
</ReportHost>
<ReportItem port="0" svc_name="general" protocol="tcp" severity="0" pluginID="12053" pluginName="Host Fully Qualified Domain Name (FQDN) Resolution" pluginFamily="General">
<description>Nessus was able to resolve the FQDN of the remote host.</description>
<fname>fqdn.nasl</fname>
<plugin_modification_date>2012/09/28</plugin_modification_date>
<plugin_name>Host Fully Qualified Domain Name (FQDN) Resolution</plugin_name>
<plugin_publication_date>2004/02/11</plugin_publication_date>
<plugin_type>remote</plugin_type>
<risk_factor>None</risk_factor>
<script_version>$Revision: 1.12 $</script_version>
<solution>n/a</solution>
<synopsis>It was possible to resolve the name of the remote host.</synopsis>
<plugin_output>
12.233.108.201 resolves as preprod.boardvantage.net.
</plugin_output>
</ReportItem>
<ReportItem port="443" svc_name="https?" protocol="tcp" severity="0" pluginID="11219" pluginName="Nessus SYN scanner" pluginFamily="Port scanners">
<description>This plugin is a SYN 'half-open' port scanner.
It shall be reasonably quick even against a firewalled target.
Note that SYN scanners are less intrusive than TCP (full connect) scanners against broken services,but they might kill lame misconfigured firewalls. They might also leave unclosed connections on the remote target,if the network is loaded.</description>
<fname>nessus_syn_scanner.nbin</fname>
<plugin_modification_date>2011/04/05</plugin_modification_date>
<plugin_name>Nessus SYN scanner</plugin_name>
<plugin_type>remote</plugin_type>
<risk_factor>None</risk_factor>
<script_version>$Revision: 1.14 $</script_version>
<solution>Protect your target with an IP filter.</solution>
<synopsis>It is possible to determine which TCP ports are open.</synopsis>
<plugin_output>Port 443/tcp was found to be open</plugin_output>
</ReportItem>
</ReportHost>
</Report>
</NessusClientData_v2>
NessusParse.rb
#!/usr/bin/ruby
require 'nokogiri'
Nessus_to_parse = gets
doc = Nokogiri::XML(Nessus_to_parse)
doc.xpath('//ReportItem').each do |i|
puts "Host = " + i.at_xpath('name').content
puts "Name = " + i.at_xpath('plugin_name').content
puts "Severity = " + i.at_xpath('risk_factor').content
end
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。