Module: Ronin::Nmap::Converters::JSON Private
- Defined in:
- lib/ronin/nmap/converters/json.rb
Overview
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Handles converting nmap XML into JSON.
Class Method Summary collapse
-
.address_as_json(address) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Address
object into JSON representation. -
.convert(xml, output) ⇒ Object
private
Converts parsed nmap XML to JSON.
-
.hop_as_json(hop) ⇒ Hash{Symbol => Object}
private
Converts an
Nmap::XML::Hop
object into JSON representation. -
.host_as_json(host) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Host
object into JSON representation. -
.host_script_as_json(host_script) ⇒ Hash{String => Object}
private
Converts the
Nmap::XML::HostScript
object into JSON representation. -
.hostname_as_json(hostname) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Hostname
object into JSON representation. -
.ip_id_sequence_as_json(ip_id_sequence) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::IpIdSequence
object into JSON representation. -
.os_as_json(os) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::OS
object into JSON representation. -
.os_class_as_json(os_class) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::OSClass
object into JSON representation. -
.os_match_as_json(os_match) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::OSMatch
object into JSON representation. -
.port_as_json(port) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Port
object into JSON representation. -
.run_stat_as_json(run_stat) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::RunStat
object into JSON representation. -
.scan_info_as_json(scan_info) ⇒ Hash{Symbol => Object}
private
Converts a
Nmap::XML::ScanInfo
object into JSON representation. -
.scan_task_as_json(scan_task) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::ScanTask
object into JSON representation. -
.scanner_as_json(scanner) ⇒ Hash{Symbol => Object}
private
Converts a
Nmap::XML::Scanner
object into JSON representation. -
.script_as_json(script) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Script
object into JSON representation. -
.scripts_as_json(has_scripts) ⇒ Hash{String => Object}
private
Converts the object, which includes
Nmap::XML::Scripts
module, into JSON representation. -
.sequence_as_json(sequence) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Sequence
object into JSON representation. -
.service_as_json(service) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Serivce
object into JSON representation. -
.status_as_json(status) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Status
object into JSON representation. -
.tcp_sequence_as_json(tcp_sequence) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::TcpSequence
object into JSON representation. -
.tcp_ts_sequence_as_json(tcp_ts_sequence) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::TcpTsSequence
object into JSON representation. -
.traceroute_as_json(traceroute) ⇒ Hash{Symbol => Object}
private
Converts the
Nmap::XML::Traceroute
object into JSON representation. -
.uptime_as_json(uptime) ⇒ Hash{Symbol => Object}
private
Converts the ``Nmap::XML::Uptime object into JSON representation.
-
.xml_as_json(xml) ⇒ Hash{Symbol => Object}
private
Converts the parsed nmap XML into a JSON representation.
-
.xml_to_json(xml, output) ⇒ Object
private
Converts parsed nmap XML to JSON.
Class Method Details
.address_as_json(address) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Address
object into JSON representation.
243 244 245 246 247 248 249 |
# File 'lib/ronin/nmap/converters/json.rb', line 243 def self.address_as_json(address) { type: address.type, addr: address.addr, vendor: address.vendor } end |
.convert(xml, output) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts parsed nmap XML to JSON.
41 42 43 |
# File 'lib/ronin/nmap/converters/json.rb', line 41 def self.convert(xml,output) xml_to_json(xml,output) end |
.hop_as_json(hop) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts an Nmap::XML::Hop
object into JSON representation.
551 552 553 554 555 556 557 558 |
# File 'lib/ronin/nmap/converters/json.rb', line 551 def self.hop_as_json(hop) { addr: hop.addr, host: hop.host, ttl: hop.ttl, rtt: hop.rtt } end |
.host_as_json(host) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Host
object into JSON representation.
175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 |
# File 'lib/ronin/nmap/converters/json.rb', line 175 def self.host_as_json(host) hash = { start_time: host.start_time, end_time: host.end_time, status: status_as_json(host.status), addresses: host.each_address.map(&method(:address_as_json)), hostnames: host.each_hostname.map(&method(:hostname_as_json)) } if (os = host.os) hash[:os] = os_as_json(os) end if (uptime = host.uptime) hash[:uptime] = uptime_as_json(uptime) end if (tcp_sequence = host.tcp_sequence) hash[:tcp_sequence] = tcp_sequence_as_json(tcp_sequence) end if (ip_id_sequence = host.ip_id_sequence) hash[:ip_id_sequence] = ip_id_sequence_as_json(ip_id_sequence) end if (tcp_ts_sequence = host.tcp_ts_sequence) hash[:tcp_ts_sequence] = tcp_ts_sequence_as_json(tcp_ts_sequence) end hash[:ports] = host.each_port.map(&method(:port_as_json)) if (host_script = host.host_script) hash[:host_script] = host_script_as_json(host_script) end if (traceroute = host.traceroute) hash[:traceroute] = traceroute_as_json(traceroute) end return hash end |
.host_script_as_json(host_script) ⇒ Hash{String => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::HostScript
object into JSON representation.
472 473 474 |
# File 'lib/ronin/nmap/converters/json.rb', line 472 def self.host_script_as_json(host_script) scripts_as_json(host_script) end |
.hostname_as_json(hostname) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Hostname
object into JSON representation.
260 261 262 263 264 265 |
# File 'lib/ronin/nmap/converters/json.rb', line 260 def self.hostname_as_json(hostname) { type: hostname.type, name: hostname.name } end |
.ip_id_sequence_as_json(ip_id_sequence) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::IpIdSequence
object into JSON
representation.
377 378 379 |
# File 'lib/ronin/nmap/converters/json.rb', line 377 def self.ip_id_sequence_as_json(ip_id_sequence) sequence_as_json(ip_id_sequence) end |
.os_as_json(os) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::OS
object into JSON representation.
276 277 278 279 280 281 282 283 284 285 286 287 288 |
# File 'lib/ronin/nmap/converters/json.rb', line 276 def self.os_as_json(os) hash = { os_classes: os.each_class.map(&method(:os_class_as_json)), os_matches: os.each_match.map(&method(:os_match_as_json)), ports_used: os.ports_used } if (fingerprint = os.fingerprint) hash[:fingerprint] = fingerprint end return hash end |
.os_class_as_json(os_class) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::OSClass
object into JSON representation.
299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 |
# File 'lib/ronin/nmap/converters/json.rb', line 299 def self.os_class_as_json(os_class) hash = {} if (type = os_class.type) hash[:type] = type end hash[:vendor] = os_class.vendor hash[:family] = os_class.family if (gen = os_class.gen) hash[:gen] = gen end hash[:accuracy] = os_class.accuracy return hash end |
.os_match_as_json(os_match) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::OSMatch
object into JSON representation.
326 327 328 329 330 331 |
# File 'lib/ronin/nmap/converters/json.rb', line 326 def self.os_match_as_json(os_match) { name: os_match.name, accuracy: os_match.accuracy } end |
.port_as_json(port) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Port
object into JSON representation.
420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 |
# File 'lib/ronin/nmap/converters/json.rb', line 420 def self.port_as_json(port) hash = { protocol: port.protocol, number: port.number, state: port.state, reason: port.reason, reason_ttl: port.reason_ttl } if (service = port.service) hash[:service] = service_as_json(service) end hash[:scripts] = scripts_as_json(port) return hash end |
.run_stat_as_json(run_stat) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::RunStat
object into JSON representation.
139 140 141 142 143 144 145 146 |
# File 'lib/ronin/nmap/converters/json.rb', line 139 def self.run_stat_as_json(run_stat) { end_time: run_stat.end_time, elapsed: run_stat.elapsed, summary: run_stat.summary, exit_status: run_stat.exit_status } end |
.scan_info_as_json(scan_info) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a Nmap::XML::ScanInfo
object into JSON representation.
117 118 119 120 121 122 123 124 125 126 127 128 |
# File 'lib/ronin/nmap/converters/json.rb', line 117 def self.scan_info_as_json(scan_info) { type: scan_info.type, protocol: scan_info.protocol, services: scan_info.services.map do |ports| case ports when Range then "#{ports.begin}-#{ports.end}" else ports end end } end |
.scan_task_as_json(scan_task) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::ScanTask
object into JSON representation.
157 158 159 160 161 162 163 164 |
# File 'lib/ronin/nmap/converters/json.rb', line 157 def self.scan_task_as_json(scan_task) { name: scan_task.name, start_time: scan_task.start_time, end_time: scan_task.end_time, extra_info: scan_task.extra_info } end |
.scanner_as_json(scanner) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts a Nmap::XML::Scanner
object into JSON representation.
99 100 101 102 103 104 105 106 |
# File 'lib/ronin/nmap/converters/json.rb', line 99 def self.scanner_as_json(scanner) { name: scanner.name, version: scanner.version, args: scanner.arguments, start: scanner.start_time } end |
.script_as_json(script) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Script
object into JSON representation.
505 506 507 508 509 510 511 512 513 514 515 516 |
# File 'lib/ronin/nmap/converters/json.rb', line 505 def self.script_as_json(script) hash = { id: script.id, output: script.output } if (data = script.data) hash[:data] = data end return hash end |
.scripts_as_json(has_scripts) ⇒ Hash{String => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the object, which includes Nmap::XML::Scripts
module, into
JSON representation.
486 487 488 489 490 491 492 493 494 |
# File 'lib/ronin/nmap/converters/json.rb', line 486 def self.scripts_as_json(has_scripts) hash = {} has_scripts.scripts.each do |id,script| hash[id] = script_as_json(script) end return hash end |
.sequence_as_json(sequence) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Sequence
object into JSON representation.
404 405 406 407 408 409 |
# File 'lib/ronin/nmap/converters/json.rb', line 404 def self.sequence_as_json(sequence) { description: sequence.description, values: sequence.values } end |
.service_as_json(service) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Serivce
object into JSON representation.
446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 |
# File 'lib/ronin/nmap/converters/json.rb', line 446 def self.service_as_json(service) { name: service.name, ssl: service.ssl?, protocol: service.protocol, product: service.product, version: service.version, extra_info: service.extra_info, hostname: service.hostname, os_type: service.os_type, device_type: service.device_type, fingerprint_method: service.fingerprint_method, fingerprint: service.fingerprint, confidence: service.confidence } end |
.status_as_json(status) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Status
object into JSON representation.
226 227 228 229 230 231 232 |
# File 'lib/ronin/nmap/converters/json.rb', line 226 def self.status_as_json(status) { state: status.state, reason: status.reason, reason_ttl: status.reason_ttl } end |
.tcp_sequence_as_json(tcp_sequence) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::TcpSequence
object into JSON representation.
358 359 360 361 362 363 364 365 |
# File 'lib/ronin/nmap/converters/json.rb', line 358 def self.tcp_sequence_as_json(tcp_sequence) hash = sequence_as_json(tcp_sequence) hash[:index] = tcp_sequence.index hash[:difficulty] = tcp_sequence.difficulty return hash end |
.tcp_ts_sequence_as_json(tcp_ts_sequence) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::TcpTsSequence
object into JSON
representation.
391 392 393 |
# File 'lib/ronin/nmap/converters/json.rb', line 391 def self.tcp_ts_sequence_as_json(tcp_ts_sequence) sequence_as_json(tcp_ts_sequence) end |
.traceroute_as_json(traceroute) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the Nmap::XML::Traceroute
object into JSON representation.
527 528 529 530 531 532 533 534 535 536 537 538 539 540 |
# File 'lib/ronin/nmap/converters/json.rb', line 527 def self.traceroute_as_json(traceroute) hash = {} if (port = traceroute.port) hash[:port] = port end if (protocol = traceroute.protocol) hash[:protocol] = protocol end hash[:traceroute] = traceroute.map(&method(:hop_as_json)) return hash end |
.uptime_as_json(uptime) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the ``Nmap::XML::Uptime object into JSON representation.
342 343 344 345 346 347 |
# File 'lib/ronin/nmap/converters/json.rb', line 342 def self.uptime_as_json(uptime) { seconds: uptime.seconds, last_boot: uptime.last_boot } end |
.xml_as_json(xml) ⇒ Hash{Symbol => Object}
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts the parsed nmap XML into a JSON representation.
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/ronin/nmap/converters/json.rb', line 67 def self.xml_as_json(xml) hash = { scanner: scanner_as_json(xml.scanner), version: xml.version, scan_info: xml.scan_info.map(&method(:scan_info_as_json)), run_stats: xml.each_run_stat.map(&method(:run_stat_as_json)), verbose: xml.verbose, debugging: xml.debugging, tasks: xml.each_task.map(&method(:scan_task_as_json)) } if xml.prescript hash[:prescript] = prescript_as_json(xml.prescript) end if xml.postscript hash[:postscript] = postscript_as_json(xml.postscript) end hash[:hosts] = xml.each_host.map(&method(:host_as_json)) return hash end |
.xml_to_json(xml, output) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Converts parsed nmap XML to JSON.
54 55 56 |
# File 'lib/ronin/nmap/converters/json.rb', line 54 def self.xml_to_json(xml,output) ::JSON.dump(xml_as_json(xml),output) end |