Module: Ronin::Recon::Importer

Defined in:
lib/ronin/recon/importer.rb

Overview

Handles importing recon values into ronin-db.

Examples

require 'ronin/db'
require 'ronin/recon/importer'

Ronin::DB.connect

values = [Ronin::Recon::Values::Domain.new('...'), ...]

Ronin::Recon::Engine.run(values) do |engine|
  engine.on(:value) do |value|
    puts "Fond new value #{value}"
    Ronin::Recon::Importer.import_value(value)
  end
end

Class Method Summary collapse

Class Method Details

.import_cert(cert) ⇒ Ronin::DB::Cert

Imports a SSL/TLS certificate.

Parameters:

  • cert (Ronin::Support::Crypto::Cert, OpenSSL::X509::Certificate)

    The SSL/TLS certificate to import.

Returns:

  • (Ronin::DB::Cert)

    The imported certificate.



217
218
219
220
221
# File 'lib/ronin/recon/importer.rb', line 217

def self.import_cert(cert)
  DB::Cert.transaction do
    DB::Cert.find_or_import(cert)
  end
end

.import_connection(value, parent) ⇒ (Ronin::DB::Model, Ronin::DB::Model)

Imports the connection between two values.

Parameters:

  • value (Value)

    A discovered recon value to import.

  • parent (Value)

    The parent value of the discovered recon value.

Returns:

  • ((Ronin::DB::Model, Ronin::DB::Model))

    The imported value and the imported parent value.



61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/ronin/recon/importer.rb', line 61

def self.import_connection(value,parent)
  imported_value  = import_value(value)
  imported_parent = import_value(parent)

  if imported_value.kind_of?(DB::IPAddress) &&
     imported_parent.kind_of?(DB::HostName)
    imported_value.host_name_ip_addresses.find_or_create_by(
      host_name: imported_parent
    )
  elsif imported_value.kind_of?(DB::Cert) &&
        imported_parent.kind_of?(DB::OpenPort)
    imported_parent.update(cert: imported_value)
  end

  return imported_value, imported_parent
end

.import_host_name(host_name) ⇒ Ronin::DB::HostName

Imports a host value.

Parameters:

  • host_name (String)

    The host name to import.

Returns:

  • (Ronin::DB::HostName)

    The imported host name record.



110
111
112
113
114
# File 'lib/ronin/recon/importer.rb', line 110

def self.import_host_name(host_name)
  DB::HostName.transaction do
    DB::HostName.find_or_import(host_name)
  end
end

.import_ip_address(address) ⇒ Ronin::DB::IPAddress

Imports a IP address.

Parameters:

  • address (String)

    The IP address to import.

Returns:

  • (Ronin::DB::IPAddress)

    The imported IP address record.



125
126
127
128
129
# File 'lib/ronin/recon/importer.rb', line 125

def self.import_ip_address(address)
  DB::IPAddress.transaction do
    DB::IPAddress.find_or_import(address)
  end
end

.import_open_port(open_port) ⇒ Ronin::DB::Open_port

Imports an open port value.

Parameters:

Returns:

  • (Ronin::DB::Open_port)

    The imported open port record.



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/ronin/recon/importer.rb', line 191

def self.import_open_port(open_port)
  imported_ip_address = import_ip_address(open_port.address)
  imported_port       = import_port(open_port.protocol,open_port.number)
  imported_service    = if (service = open_port.service)
                          import_service(service)
                        end
  imported_open_port  = DB::OpenPort.transaction do
                          DB::OpenPort.find_or_create_by(
                            ip_address: imported_ip_address,
                            port:       imported_port,
                            service:    imported_service
                          )
                        end

  return imported_open_port
end

.import_port(protocol, number) ⇒ Ronin::DB::Port

Imports a port number.

Parameters:

  • protocol (:tcp, :udp)

    The protocol that the port uses.

  • number (Integer)

    The port number to import.

Returns:

  • (Ronin::DB::Port)

    The imported port record.



158
159
160
161
162
163
164
165
# File 'lib/ronin/recon/importer.rb', line 158

def self.import_port(protocol,number)
  DB::Port.transaction do
    DB::Port.find_or_create_by(
      protocol: protocol,
      number:   number
    )
  end
end

.import_service(service) ⇒ Ronin::DB::Service

Imports a service name.

Parameters:

  • service (String)

    The service name to import.

Returns:

  • (Ronin::DB::Service)

    The imported service record.



176
177
178
179
180
# File 'lib/ronin/recon/importer.rb', line 176

def self.import_service(service)
  DB::Service.transaction do
    DB::Service.find_or_import(service)
  end
end

.import_url(url) ⇒ Ronin::DB::URL

Imports a URL.

Parameters:

  • url (URI::HTTP, String)

    The URL string to import.

Returns:

  • (Ronin::DB::URL)

    The imported URL record.



140
141
142
143
144
# File 'lib/ronin/recon/importer.rb', line 140

def self.import_url(url)
  DB::URL.transaction do
    DB::URL.find_or_import(url)
  end
end

.import_value(value) ⇒ Ronin::DB::HostName, ...

Imports a value into the database.

The imported record.

Parameters:

  • value (Value)

    A discovered recon value to import.

Returns:

  • (Ronin::DB::HostName, Ronin::DB::IPAddress, Ronin::DB::OpenPort, Ronin::DB::URL, Ronin::DB::Cert)


91
92
93
94
95
96
97
98
99
# File 'lib/ronin/recon/importer.rb', line 91

def self.import_value(value)
  case value
  when Values::Host     then import_host_name(value.name)
  when Values::IP       then import_ip_address(value.address)
  when Values::OpenPort then import_open_port(value)
  when Values::URL      then import_url(value.uri)
  when Values::Cert     then import_cert(value.cert)
  end
end