Class: Ronin::DB::HostName

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::Importable, Model::LastScannedAt
Defined in:
lib/ronin/db/host_name.rb

Overview

Represents host names and their associated IP addresses.

Instance Attribute Summary collapse

Attributes included from Model::LastScannedAt

#last_scanned_at

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::LastScannedAt

included

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#advisoriesArray<Advisory>

The advisories that the host names is vulnerable to.

Returns:

Since:

  • 0.2.0



118
# File 'lib/ronin/db/host_name.rb', line 118

has_many :advisories, through: :vulnerabilities

#created_atTime

When the host name was first created.

Returns:

  • (Time)


63
# File 'lib/ronin/db/host_name.rb', line 63

attribute :created_at, :datetime

#email_addressesArray<EmailAddress>

The email addresses that are associated with the host-name.

Returns:



95
# File 'lib/ronin/db/host_name.rb', line 95

has_many :email_addresses, dependent: :destroy

#host_name_ip_addressesArray<HostNameIPAddress>

The IP Address associations.

Returns:



69
70
# File 'lib/ronin/db/host_name.rb', line 69

has_many :host_name_ip_addresses, dependent: :destroy,
class_name: 'HostNameIPAddress'

#idInteger

The primary ID of the host name.

Returns:

  • (Integer)


44
# File 'lib/ronin/db/host_name.rb', line 44

attribute :id, :integer

#ip_addressesArray<IPAddress>

The IP Addresses that host the host name.

Returns:



76
77
# File 'lib/ronin/db/host_name.rb', line 76

has_many :ip_addresses, through:    :host_name_ip_addresses,
class_name: 'IPAddress'

#nameString

The address of the host name.

Returns:

  • (String)


50
# File 'lib/ronin/db/host_name.rb', line 50

attribute :name, :string

#notesArray<Note>

The associated notes.

Returns:

Since:

  • 0.2.0



142
# File 'lib/ronin/db/host_name.rb', line 142

has_many :notes, dependent: :destroy

#open_portsArray<OpenPort>

The open ports of the host.

Returns:



83
# File 'lib/ronin/db/host_name.rb', line 83

has_many :open_ports, through: :ip_addresses

#organization_host_namesArray<OrganizationHostName>

The association of host names and organizations.

Returns:

Since:

  • 0.2.0



126
# File 'lib/ronin/db/host_name.rb', line 126

has_many :organization_host_names, dependent: :destroy

#organizationsArray<Organization>

The organizations that claim ownership of the host name.

Returns:

Since:

  • 0.2.0



134
# File 'lib/ronin/db/host_name.rb', line 134

has_many :organizations, through: :organization_host_names

#portsArray<Port>

The ports of the host.

Returns:



89
# File 'lib/ronin/db/host_name.rb', line 89

has_many :ports, through: :ip_addresses

#urlsArray<URL>

The URLs that point to this host name.

Returns:



101
102
# File 'lib/ronin/db/host_name.rb', line 101

has_many :urls, dependent: :destroy,
class_name: 'URL'

#vulnerabilitiesArray<Vulnerability>

The vulnerabilities which reference the host name.

Returns:

Since:

  • 0.2.0



110
# File 'lib/ronin/db/host_name.rb', line 110

has_many :vulnerabilities, dependent: :destroy

Class Method Details

.import(name) ⇒ HostName

Creates a new host name.

Parameters:

  • name (String)

    The host name.

Returns:

  • (HostName)

    The created host name record.



166
167
168
# File 'lib/ronin/db/host_name.rb', line 166

def self.import(name)
  create(name: name)
end

.lookup(name) ⇒ HostName?

Looks up the host name.

Parameters:

  • name (String)

    The raw host name.

Returns:

  • (HostName, nil)

    The found host name.



153
154
155
# File 'lib/ronin/db/host_name.rb', line 153

def self.lookup(name)
  find_by(name: name)
end

.with_domain(name) ⇒ Array<HostName>

Searches for all host names sharing a canonical domain name.

Parameters:

  • name (String)

    The canonical domain name to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



228
229
230
231
232
233
234
# File 'lib/ronin/db/host_name.rb', line 228

def self.with_domain(name)
  name_column = self.arel_table[:name]

  name = sanitize_sql_like(name)

  where(name: name).or(where(name_column.matches("%.#{name}")))
end

.with_ip_address(ip) ⇒ Array<HostName>

Searches for host names associated with the given IP address(es).

Parameters:

  • ip (Array<String>, String)

    The IP address(es) to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



181
182
183
# File 'lib/ronin/db/host_name.rb', line 181

def self.with_ip_address(ip)
  joins(:ip_addresses).where(ip_addresses: {address: ip})
end

.with_port_number(number) ⇒ Array<HostName>

Searches for host names with the given open port(s).

Parameters:

  • number (Array<Integer>, Integer)

    The open port(s) to search for.

Returns:

  • (Array<HostName>)

    The matching host names.



196
197
198
# File 'lib/ronin/db/host_name.rb', line 196

def self.with_port_number(number)
  joins(:ports).where(ports: {number: number})
end

.with_tld(name) ⇒ Array<HostName>

Searches for all host names under the Top-Level Domain (TLD).

Parameters:

  • name (String)

    The Top-Level Domain (TLD).

Returns:

  • (Array<HostName>)

    The matching host names.



211
212
213
214
215
# File 'lib/ronin/db/host_name.rb', line 211

def self.with_tld(name)
  name_column = self.arel_table[:name]

  where(name_column.matches("%.#{sanitize_sql_like(name)}"))
end

Instance Method Details

#recent_ip_addressIPAddress

The IP Address that was most recently used by the host name.

Returns:

  • (IPAddress)

    The IP Address that most recently used by the host name.



244
245
246
# File 'lib/ronin/db/host_name.rb', line 244

def recent_ip_address
  self.host_name_ip_addresses.order('created_at DESC').ip_addresses.first
end

#to_sString

Converts the host name to a String.

Returns:

  • (String)

    The host name.



256
257
258
# File 'lib/ronin/db/host_name.rb', line 256

def to_s
  self.name.to_s
end