Module: Ronin::Masscan::Converters::JSON Private

Defined in:
lib/ronin/masscan/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 masscan scan files into JSON.

Class Method Summary collapse

Class Method Details

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 masscan record into a JSON representation.

Parameters:

  • banner (::Masscan::Banner)

    The masscan banner record to convert.

Returns:

  • (Hash{Symbol => Object})

    The JSON representation of the record.



129
130
131
132
133
134
135
136
137
138
# File 'lib/ronin/masscan/converters/json.rb', line 129

def self.banner_as_json(banner)
  {
    protocol:     banner.protocol,
    port:         banner.port,
    ip:           banner.ip,
    timestamp:    banner.timestamp,
    app_protocol: banner.app_protocol,
    payload:      banner.payload
  }
end

.convert(masscan_file, 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 the masscan scan file to JSON.

Parameters:

  • masscan_file (::Masscan::OutputFile)

    The opened masscan scan file.

  • output (IO, StringIO)

    Optional output stream to write the JSON to.



42
43
44
# File 'lib/ronin/masscan/converters/json.rb', line 42

def self.convert(masscan_file,output)
  masscan_file_to_json(masscan_file,output)
end

.masscan_file_as_json(output_file) ⇒ Array<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 masscan scan file into JSON representation.

Parameters:

  • output_file (::Masscan::OutputFile)

    The opened masscan file.

Returns:

  • (Array<Hash{Symbol => Object}>)

    The JSON representation of the masscan scan file.



68
69
70
71
72
# File 'lib/ronin/masscan/converters/json.rb', line 68

def self.masscan_file_as_json(output_file)
  output_file.each.map do |record|
    record_as_json(record)
  end
end

.masscan_file_to_json(masscan_file, 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 the masscan scan file to JSON.

Parameters:

  • masscan_file (::Masscan::OutputFile)

    The opened masscan scan file.

  • output (IO, StringIO)

    Optional output stream to write the JSON to.



55
56
57
# File 'lib/ronin/masscan/converters/json.rb', line 55

def self.masscan_file_to_json(masscan_file,output)
  ::JSON.dump(masscan_file_as_json(masscan_file),output)
end

.record_as_json(record) ⇒ 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 masscan record into a JSON representation.

Parameters:

  • record (::Masscan::Status, ::Masscan::Banner)

    The masscan status or banner record to convert.

Returns:

  • (Hash{Symbol => Object})

    The JSON representation of the record.



83
84
85
86
87
88
89
90
91
92
# File 'lib/ronin/masscan/converters/json.rb', line 83

def self.record_as_json(record)
  case record
  when ::Masscan::Status
    status_as_json(record)
  when ::Masscan::Banner
    banner_as_json(record)
  else
    raise(NotImplementedError,"unable to convert masscan record: #{record.inspect}")
  end
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 a masscan status record into a JSON representation.

Parameters:

  • status (::Masscan::Status)

    The masscan status record to convert.

Returns:

  • (Hash{Symbol => Object})

    The JSON representation of the record.



103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
# File 'lib/ronin/masscan/converters/json.rb', line 103

def self.status_as_json(status)
  hash = {
    status:    status.status,
    protocol:  status.protocol,
    port:      status.port,
    reason:    status.reason,
    ttl:       status.ttl,
    ip:        status.ip,
    timestamp: status.timestamp
  }

  # omit the `mac` field if it's nil
  hash[:mac] = status.mac if status.mac

  return hash
end