Class: Mdm::Host

Inherits:
ActiveRecord::Base
  • Object
show all
Includes:
OperatingSystemNormalization
Defined in:
app/models/mdm/host.rb

Overview

A system with an IP address on the network that has been discovered in some way.

Defined Under Namespace

Modules: OperatingSystemNormalization

Constant Summary collapse

ARCHITECTURES =

Either the CPU architecture for native code or the programming language name for exploits that run code in the programming language's virtual machine.

[
    'armbe',
    'armle',
    'cbea',
    'cbea64',
    'cmd',
    'java',
    'mips',
    'mipsbe',
    'mipsle',
    'php',
    'ppc',
    'ppc64',
    'ruby',
    'sparc',
    'tty',
    # To be used for compatability with 'X86_64'
    'x64',
    'x86',
    'x86_64'
]
SEARCH_FIELDS =

Fields searched for the search scope

[
    'address::text',
    'comments',
    'mac',
    'name',
    'os_flavor',
    'os_name',
    'os_sp',
    'purpose'
]
STATES =

Valid values for #state.

[
    'alive',
    'down',
    'unknown'
]

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from OperatingSystemNormalization

#get_arch_from_string, #normalize_os, #normalize_scanner_fp, #parse_windows_os_str, #validate_fingerprint_data

Instance Attribute Details

#addressString

The IP address of this host.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 208

#archString

The architecture of the host's CPU OR the programming language for virtual machine programming language like Ruby, PHP, and Java.

Returns:



# File 'app/models/mdm/host.rb', line 213

#commString

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 219

#commentsString

User supplied comments about host.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 224

#created_atDateTime

When this host was created in the database.

Returns:

  • (DateTime)


# File 'app/models/mdm/host.rb', line 229

#cred_countInteger

Counter cache for #creds.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 234

#credsArray<Mdm::Cred> (readonly)

Credentials captured from #services.

Returns:

See Also:



140
# File 'app/models/mdm/host.rb', line 140

has_many :creds, :class_name => 'Mdm::Cred', :through => :services

#exploit_attempt_countInteger

Counter cache for #exploit_attempts.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 239

#exploit_attemptsArray<Mdm::ExploitAttempt]

Attempts to run exploits against this host.

Returns:



60
61
62
# File 'app/models/mdm/host.rb', line 60

has_many :exploit_attempts,
:class_name => 'Mdm::ExploitAttempt',
:dependent => :destroy

#exploited_hostsArray<Mdm::ExploitedHost>

Returns:



67
# File 'app/models/mdm/host.rb', line 67

has_many :exploited_hosts, :class_name => 'Mdm::ExploitedHost', :dependent => :destroy

#host_detail_countInteger

Counter cache for #host_details.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 244

#host_detailsArray<Mdm::HostDetail>

Returns:



71
# File 'app/models/mdm/host.rb', line 71

has_many :host_details, :class_name => 'Mdm::HostDetail', :dependent => :destroy

#hosts_tagsArray<Mdm::HostTag>

A join model between Tag and Mdm::Host. Use #tags to get the actual Mdm::Tags on this host. #hosts_tags are cleaned up in a before_destroy: #cleanup_tags.

Returns:



79
# File 'app/models/mdm/host.rb', line 79

has_many :hosts_tags, :class_name => 'Mdm::HostTag'

#infoString

Information about this host gathered from the host.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 249

#lootsArray<Mdm::Loot>

Loot gathered from the host with newest loot first.

Returns:



86
# File 'app/models/mdm/host.rb', line 86

has_many :loots, :class_name => 'Mdm::Loot', :dependent => :destroy, :order => 'loots.created_at DESC'

#macString

The MAC address of this host.

Returns:

  • (String)

See Also:



# File 'app/models/mdm/host.rb', line 254

#module_detailsArray<Mdm::Module::Detail] (readonly)

Details about modules that were used to find vulnerabilities on this host.

Returns:



198
199
200
201
202
# File 'app/models/mdm/host.rb', line 198

has_many :module_details,
:class_name => 'Mdm::Module::Detail',
:source =>:detail,
:through => :module_refs,
:uniq => true

#module_refsArray<Mdm::Module::Ref> (readonly)

Returns:



188
# File 'app/models/mdm/host.rb', line 188

has_many :module_refs, :class_name => 'Mdm::Module::Ref', :through => :refs

#nameString

The name of the host. If the host name is not available, then it will just be the IP address.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 260

#note_countInteger

Counter cache for #notes.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 265

#notesArray<Mdm::Note>

Notes about the host entered by a user with oldest notes first.

Returns:



92
# File 'app/models/mdm/host.rb', line 92

has_many :notes, :class_name => 'Mdm::Note', :dependent => :delete_all, :order => 'notes.created_at'

#os_flavorString

The flavor of #os_name.

Examples:

Windows XP

host.os_name = 'Microsoft Windows'
host.os_flavor = 'XP'

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 270

#os_langString

Free-form language of operating system. Usually either spelled out like 'English' or an IETF language tag like 'en' or 'en-US'.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 279

#os_nameString

The name of the operating system.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 285

#os_spString

The service pack of the #os_flavor of the #os_name.

Examples:

Windows XP SP2

host.os_name = 'Microsoft Windows'
host.os_flavor = 'XP'
host.os_sp = 'SP2'

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 290

#purposeString

The purpose of the host on the network, such as 'client' or 'firewall'.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 300

#refsArray<Mdm::Ref> (readonly)

External references, such as CVE, to vulnerabilities found on this host.

Returns:

See Also:



178
# File 'app/models/mdm/host.rb', line 178

has_many :refs, :class_name => 'Mdm::Ref', :through => :vuln_refs

#scopeString

Interface identifier for link-local IPv6



# File 'app/models/mdm/host.rb', line 305

#service_countInteger

Counter cache for #services.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 311

#service_notesArray<Mdm::Note> (readonly)

Notes about #services running on this host.

Returns:

See Also:



147
# File 'app/models/mdm/host.rb', line 147

has_many :service_notes, :class_name => 'Mdm::Note', :through => :services

#servicesArray<Mdm::Service>

The services running on ports on the host with services ordered by port and protocol.

Returns:



99
# File 'app/models/mdm/host.rb', line 99

has_many :services, :class_name => 'Mdm::Service', :dependent => :destroy, :order => 'services.port, services.proto'

#sessionsArray<Mdm::Session]

Sessions that are open or previously were open on the host ordered by when the session was opened

Returns:



106
# File 'app/models/mdm/host.rb', line 106

has_many :sessions, :class_name => 'Mdm::Session', :dependent => :destroy, :order => 'sessions.opened_at'

#stateString

Whether the host is alive, down, or in an unknown state.

Returns:

  • (String)

    element of STATES.



# File 'app/models/mdm/host.rb', line 316

#tagsArray<Mdm::Tag> (readonly)

The tags on this host. Tags are used to filter hosts.

Returns:

See Also:



129
# File 'app/models/mdm/host.rb', line 129

has_many :tags, :class_name => 'Mdm::Tag', :through => :hosts_tags

#updated_atDateTime

The last time this host was updated in the database.

Returns:

  • (DateTime)


# File 'app/models/mdm/host.rb', line 321

#virtual_hostString

The name of the virtual machine host software, such as 'VMWare', 'QEMU', 'XEN', etc.

Returns:

  • (String)


# File 'app/models/mdm/host.rb', line 326

#vuln_countInteger

Counter cache for #vulns.

Returns:

  • (Integer)


# File 'app/models/mdm/host.rb', line 331

#vuln_refsArray<Mdm::VulnRef> (readonly)

Join model between #vulns and #refs. Use either of those asssociations instead of this join model.

Returns:

See Also:



167
# File 'app/models/mdm/host.rb', line 167

has_many :vuln_refs, :class_name => 'Mdm::VulnRef', :source => :vulns_refs, :through => :vulns

#vulnsArray<Mdm::Vuln>

Vulnerabilities found on the host.

Returns:



112
# File 'app/models/mdm/host.rb', line 112

has_many :vulns, :class_name => 'Mdm::Vuln', :dependent => :delete_all

#web_sitesArray<Mdm::WebSite> (readonly)

Web sites running on top of #services on this host.

Returns:

See Also:



154
# File 'app/models/mdm/host.rb', line 154

has_many :web_sites, :class_name => 'Mdm::WebSite', :through => :services

#workspaceMdm::Workspace

The workspace in which this host was found.

Returns:



118
# File 'app/models/mdm/host.rb', line 118

belongs_to :workspace, :class_name => 'Mdm::Workspace'

Instance Method Details

#attribute_locked?(attr) ⇒ true, false

Returns whether 'host.updated.' note is locked.

Returns:

  • (true)

    if Mdm::Note with 'host.updated.' as Note#name exists and data[:locked] is true.

  • (false)

    otherwise.



403
404
405
406
# File 'app/models/mdm/host.rb', line 403

def attribute_locked?(attr)
  n = notes.find_by_ntype("host.updated.#{attr}")
  n && n.data[:locked]
end

#cleanup_tagsvoid

This method returns an undefined value.

Destroys any Mdm::Tags that will have no Tag#hosts left after this host is deleted.



411
412
413
414
415
416
417
418
# File 'app/models/mdm/host.rb', line 411

def cleanup_tags
  # No need to keep tags with no hosts
  tags.each do |tag|
    tag.destroy if tag.hosts == [self]
  end
  # Clean up association table records
  Mdm::HostTag.delete_all("host_id = #{self.id}")
end

#ip_address_invalid?void

This method returns an undefined value.

This is replicated by the IpAddressValidator class. Had to put it here as well to avoid SQL errors when checking address uniqueness.



424
425
426
427
428
429
430
431
# File 'app/models/mdm/host.rb', line 424

def ip_address_invalid?
  begin
    potential_ip = IPAddr.new(address)
    return true unless potential_ip.ipv4? || potential_ip.ipv6?
  rescue ArgumentError
    return true
  end
end

#is_vm?true, false

Returns whether this host is a virtual machine.

Returns:



437
438
439
# File 'app/models/mdm/host.rb', line 437

def is_vm?
  !!self.virtual_host
end