Class: Ronin::DB::Service

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

Overview

Represents a TCP/UDP Service that runs on various common ports.

Instance Attribute Summary collapse

Attributes included from Model::HasUniqueName

#name

Class Method Summary collapse

Methods included from Model::HasUniqueName

included

Methods included from Model::Importable

included

Methods included from Model

included

Instance Attribute Details

#created_atTime (readonly)

Defines the created_at timestamp

Returns:

  • (Time)

Since:

  • 0.2.0



48
# File 'lib/ronin/db/service.rb', line 48

attribute :created_at, :datetime

#idInteger

Primary key of the service

Returns:

  • (Integer)


40
# File 'lib/ronin/db/service.rb', line 40

attribute :id, :integer

#ip_addressesArray<IPAddress>

The IP Addresses that that run this service.

Returns:

Since:

  • 0.2.0



62
# File 'lib/ronin/db/service.rb', line 62

has_many :ip_addresses, through: :open_ports

#notesArray<Note>

The associated notes.

Returns:

Since:

  • 0.2.0



78
# File 'lib/ronin/db/service.rb', line 78

has_many :notes, dependent: :destroy

#open_portsArray<OpenPort>

The open ports running the service

Returns:



54
# File 'lib/ronin/db/service.rb', line 54

has_many :open_ports

#portsArray<Port>

The ports that that use this service.

Returns:

Since:

  • 0.2.0



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

has_many :ports, through: :open_ports

Class Method Details

.import(name) ⇒ Service

Imports a service.

Parameters:

  • name (String)

    The service name to import.

Returns:

  • (Service)

    The imported service.

Since:

  • 0.2.0



169
170
171
# File 'lib/ronin/db/service.rb', line 169

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

.lookup(name) ⇒ Service?

Looks up the service.

Parameters:

  • name (String)

    The service name to lookup.

Returns:

  • (Service, nil)

    The found service.

Since:

  • 0.2.0



154
155
156
# File 'lib/ronin/db/service.rb', line 154

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

.with_ip_address(address) ⇒ Array<Service>

Queries all services associated with the IP address.

Parameters:

  • address (String)

    The IP address to search by.

Returns:

  • (Array<Service>)

    The services associated with the IP address.

Since:

  • 0.2.0



135
136
137
138
139
140
141
# File 'lib/ronin/db/service.rb', line 135

def self.with_ip_address(address)
  joins(open_ports: :ip_address).where(
    open_ports: {
      ronin_ip_addresses: {address: address}
    }
  )
end

.with_port_number(number) ⇒ Array<Service>

Queries all services associated with the port number.

Parameters:

  • number (Integer)

    The port number to search by.

Returns:

  • (Array<Service>)

    The services associated with the port number.

Since:

  • 0.2.0



93
94
95
96
97
98
99
# File 'lib/ronin/db/service.rb', line 93

def self.with_port_number(number)
  joins(open_ports: :port).where(
    open_ports: {
      ronin_ports: {number: number}
    }
  )
end

.with_protocol(protocol) ⇒ Array<Service>

Queries all services associated with the protocol.

Parameters:

  • protocol (:tcp, :udp)

    The port protocol to search by.

Returns:

  • (Array<Service>)

    The services associated with the protocol.

Since:

  • 0.2.0



114
115
116
117
118
119
120
# File 'lib/ronin/db/service.rb', line 114

def self.with_protocol(protocol)
  joins(open_ports: :port).where(
    open_ports: {
      ronin_ports: {protocol: protocol}
    }
  )
end