Class: Ronin::DB::OS

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
Model, Model::HasName
Defined in:
lib/ronin/db/os.rb

Overview

Represents an Operating System and pre-defines other common ones (OS.linux, OS.freebsd, OS.openbsd, OS.netbsd, OS.macos, and OS.windows.

Instance Attribute Summary collapse

Attributes included from Model::HasName

#name

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Model::HasName

included

Methods included from Model

included

Instance Attribute Details

#flavor"linux", "bsd"

The flavor of the OS (Linux, BSD).

Returns:



47
# File 'lib/ronin/db/os.rb', line 47

enum :flavor, {linux: 'Linux', bsd: 'BSD'}

#idInteger

The primary key of the OS.

Returns:

  • (Integer)


41
# File 'lib/ronin/db/os.rb', line 41

attribute :id, :integer

#ip_addressesArray<IPAddress>

Any IP Addresses that might be running the Operating System

Returns:



68
69
# File 'lib/ronin/db/os.rb', line 68

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

#os_guessesArray<OSGuess>

Any OS guesses for the Operating System.

Returns:



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

has_many :os_guesses, dependent:  :destroy,
class_name: 'OSGuess'

#versionString

The version of the Operating System.

Returns:

  • (String)


53
# File 'lib/ronin/db/os.rb', line 53

attribute :version, :string

Class Method Details

.freebsd(version) ⇒ OS

The FreeBSD OS

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



125
126
127
# File 'lib/ronin/db/os.rb', line 125

def self.freebsd(version)
  find_or_create_by(name: 'FreeBSD', flavor: :bsd, version: version)
end

.linux(version) ⇒ OS

The Linux OS

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



113
114
115
# File 'lib/ronin/db/os.rb', line 113

def self.linux(version)
  find_or_create_by(name: 'Linux', flavor: :linux, version: version)
end

.macos(version) ⇒ OS

The macOS OS.

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



161
162
163
# File 'lib/ronin/db/os.rb', line 161

def self.macos(version)
  find_or_create_by(name: 'macOS', flavor: :bsd, version: version)
end

.netbsd(version) ⇒ OS

The NetBSD OS

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



149
150
151
# File 'lib/ronin/db/os.rb', line 149

def self.netbsd(version)
  find_or_create_by(name: 'NetBSD', flavor: :bsd, version: version)
end

.openbsd(version) ⇒ OS

The OpenBSD OS

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



137
138
139
# File 'lib/ronin/db/os.rb', line 137

def self.openbsd(version)
  find_or_create_by(name: 'OpenBSD', flavor: :bsd, version: version)
end

.windows(version) ⇒ OS

The Windows OS

Parameters:

  • version (String)

    Optional version of the OS.

Returns:



173
174
175
# File 'lib/ronin/db/os.rb', line 173

def self.windows(version)
  find_or_create_by(name: 'Windows', version: version)
end

.with_flavor(flavor) ⇒ Array<OS>

Queries all OSes with the matching flavor.

Parameters:

  • flavor (:linux, :bsd)

    The flavor to search for.

Returns:

  • (Array<OS>)

    The matching OSes.

Since:

  • 0.2.0



84
85
86
# File 'lib/ronin/db/os.rb', line 84

def self.with_flavor(flavor)
  where(flavor: flavor)
end

.with_version(version) ⇒ Array<OS>

Queries all OSes with the matching version.

Parameters:

  • version (String)

    The version number to search for.

Returns:

  • (Array<OS>)

    The matching OSes.

Since:

  • 0.2.0



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

def self.with_version(version)
  where(version: version)
end

Instance Method Details

#recent_ip_addressIPAddress

The IP Address that was most recently guessed to be using the Operating System.

Returns:

  • (IPAddress)

    The IP Address most recently guessed to be using the Operating System.



187
188
189
190
191
192
193
# File 'lib/ronin/db/os.rb', line 187

def recent_ip_address
  relation = self.os_guesses.order('created_at DESC').first

  if relation
    return relation.ip_address
  end
end

#to_sString

Converts the Operating System to a String.

Examples:

os = OS.new(name: 'Linux', version: '2.6.11')
os.to_s
# => "Linux 2.6.11"

Returns:

  • (String)

    The OS name and version.



208
209
210
# File 'lib/ronin/db/os.rb', line 208

def to_s
  "#{self.name} #{self.version}"
end