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:



91
92
93
# File 'lib/ronin/db/os.rb', line 91

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:



79
80
81
# File 'lib/ronin/db/os.rb', line 79

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:



127
128
129
# File 'lib/ronin/db/os.rb', line 127

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:



115
116
117
# File 'lib/ronin/db/os.rb', line 115

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:



103
104
105
# File 'lib/ronin/db/os.rb', line 103

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:



139
140
141
# File 'lib/ronin/db/os.rb', line 139

def self.windows(version)
  find_or_create_by(name: 'Windows', 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.



153
154
155
156
157
158
159
# File 'lib/ronin/db/os.rb', line 153

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.



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

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