Module: Nessus::Client::Report
- Included in:
- Nessus::Client
- Defined in:
- lib/nessus/client/report.rb
Overview
Report Auxiliary methods collapse
- #report_find_all(name) ⇒ Object
-
#report_find_by_name(name) ⇒ Array<Hash>
Reports by readableName regex.
- #report_find_by_readable_name(name) ⇒ Object
- #report_findings(report) ⇒ Object
-
#report_hostlist(report) ⇒ Array
Of hostnames/IP addresses.
- #report_item(report_findings, hostname, plugin_id) ⇒ Object
- #report_parse(report) ⇒ Object
- #report_plugin_summary(report_findings) ⇒ Object
-
#report_portlist(report, ip_address) ⇒ Array<Array>
Of port numbers and protocol.
- #report_readable_name(name) ⇒ Object
Instance Method Summary collapse
-
#report_delete(report) ⇒ Object
POST /report/delete.
-
#report_details(report, hostname, port, protocol) ⇒ Object
POST /report/details.
-
#report_hosts(report) ⇒ Object
POST /report/hosts.
-
#report_list ⇒ Array<Hash>
GET /report/list.
-
#report_ports(report, hostname) ⇒ Object
POST /report/ports.
-
#report_tags(report, hostname) ⇒ Object
POST /report/tags.
Instance Method Details
#report_delete(report) ⇒ Object
POST /report/delete
18 19 20 21 |
# File 'lib/nessus/client/report.rb', line 18 def report_delete(report) response = post '/report/delete', :report => report response['reply']['contents'] end |
#report_details(report, hostname, port, protocol) ⇒ Object
POST /report/details
58 59 60 61 62 63 64 65 66 67 |
# File 'lib/nessus/client/report.rb', line 58 def report_details(report, hostname, port, protocol) arguments = { :report => report, :hostname => hostname, :port => port, :protocol => protocol } response = post '/report/details', arguments response['reply']['contents'] end |
#report_find_all(name) ⇒ Object
126 127 128 129 130 |
# File 'lib/nessus/client/report.rb', line 126 def report_find_all(name) report_list.find_all do |report| report['readableName'] =~ /#{name}/i end end |
#report_find_by_name(name) ⇒ Array<Hash>
Returns reports by readableName regex.
110 111 112 113 114 115 116 117 118 |
# File 'lib/nessus/client/report.rb', line 110 def report_find_by_name(name) if report_list.is_a? Array report_list.find_all do |report| report['name'] == name end elsif report_list['name'] == name [report_list] end end |
#report_find_by_readable_name(name) ⇒ Object
120 121 122 123 124 |
# File 'lib/nessus/client/report.rb', line 120 def report_find_by_readable_name(name) report_list.find_all do |report| report['readableName'] == name end end |
#report_findings(report) ⇒ Object
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 |
# File 'lib/nessus/client/report.rb', line 136 def report_findings(report) hosts = report_hostlist(report) ports = hosts.map do |host| report_portlist(report, host) end hosts_and_ports= hosts.zip(ports).map do |key, value| { key => value } end hosts_and_ports_hash = hosts_and_ports.inject(:merge) report_element_array = hosts_and_ports_hash.map do |key, values| { key => values.map do |value| { 'port_number' => value.first, 'port_type' => value.last, 'findings' => report_details(report, key, value.first, value.last) } end } end report_hash = report_element_array.inject(:merge) json_report = JSON.pretty_generate(report_hash) end |
#report_hostlist(report) ⇒ Array
Returns of hostnames/IP addresses.
87 88 89 90 91 92 93 94 95 96 |
# File 'lib/nessus/client/report.rb', line 87 def report_hostlist(report) hostlist = report_hosts(report)['hostlist']['host'] if hostlist.is_a? Array hostlist.map {|host| host['hostname']} else [hostlist['hostname']] end rescue [] end |
#report_hosts(report) ⇒ Object
POST /report/hosts
28 29 30 31 32 33 |
# File 'lib/nessus/client/report.rb', line 28 def report_hosts(report) response = get '/report/hosts', :report => report response['reply']['contents'] rescue [] end |
#report_item(report_findings, hostname, plugin_id) ⇒ Object
198 199 200 201 202 |
# File 'lib/nessus/client/report.rb', line 198 def report_item(report_findings, hostname, plugin_id) report_findings[hostname].find_all do |report_item| report_item['pluginid'].eql? plugin_id end end |
#report_list ⇒ Array<Hash>
GET /report/list
8 9 10 11 |
# File 'lib/nessus/client/report.rb', line 8 def report_list response = get '/report/list' response['reply']['contents']['reports']['report'] end |
#report_parse(report) ⇒ Object
204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 |
# File 'lib/nessus/client/report.rb', line 204 def report_parse(report) doc = Nokogiri::XML(report) report_data = doc.css('ReportHost').map { |report_host| { report_host.attributes['name'].value => report_host.css('ReportItem').map { |report_item| report_item.map { |key, attribute| { key.downcase => attribute } }.inject(:merge).merge({ 'data' => %w[ description fname plugin_modification_date plugin_name plugin_publication_date plugin_type risk_factor script_version solution synopsis plugin_output ].map { |report_subitem| report_item.css(report_subitem).map { |node| { node.name => node.text } } }.flatten.inject(:merge) }) } } }.inject(:merge).sort_by { |k, v| k } Hash[report_data] end |
#report_plugin_summary(report_findings) ⇒ Object
164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 |
# File 'lib/nessus/client/report.rb', line 164 def report_plugin_summary(report_findings) hostname_to_report_items_arr = report_findings.map do |hostname, reports| [ hostname, reports.map do |report_item| { 'pluginid' => report_item['pluginid'], 'pluginname' => report_item['pluginname'], 'severity' => report_item['severity'] } end ] end hostname_to_report_items = Hash[hostname_to_report_items_arr] pluginid_arr = hostname_to_report_items.values.flatten.uniq.sort_by { |report_item| report_item['pluginid'] }.map do |report_item| [ report_item['pluginid'], { 'hosts' => hostname_to_report_items.map { |hostname, reports| if reports.uniq.map { |other_report_item| other_report_item['pluginid'] }.include? report_item['pluginid'] hostname end }.compact.sort, 'pluginname' => report_item['pluginname'], 'severity' => report_item['severity'] } ] end pluginid_to_hostnames = Hash[pluginid_arr] end |
#report_portlist(report, ip_address) ⇒ Array<Array>
Returns of port numbers and protocol.
99 100 101 102 103 104 105 106 107 |
# File 'lib/nessus/client/report.rb', line 99 def report_portlist(report, ip_address) ports = report_ports(report, ip_address)['portlist']['port'] if ports.is_a? Hash ports = [ports] end ports.map do |port| [port['portnum'], port['protocol']] end end |
#report_ports(report, hostname) ⇒ Object
POST /report/ports
41 42 43 44 45 46 47 48 |
# File 'lib/nessus/client/report.rb', line 41 def report_ports(report, hostname) arguments = { :report => report, :hostname => hostname } response = post '/report/ports', arguments response['reply']['contents'] end |
#report_readable_name(name) ⇒ Object
132 133 134 |
# File 'lib/nessus/client/report.rb', line 132 def report_readable_name(name) report_list.find{|report| report['name'].eql? name}['readableName'] end |
#report_tags(report, hostname) ⇒ Object
POST /report/tags
75 76 77 78 79 80 81 82 |
# File 'lib/nessus/client/report.rb', line 75 def (report, hostname) arguments = { :report => report, :hostname => hostname } response = post '/report/tags', arguments response['reply']['contents'] end |