Module: Msf::Post::Windows::System

Includes:
Common
Defined in:
lib/msf/core/post/windows/system.rb

Instance Method Summary collapse

Methods included from Common

#clear_screen, #cmd_exec, #cmd_exec_get_pid, #cmd_exec_with_result, #command_exists?, #create_process, #get_env, #get_envs, #peer, #report_virtualization, #rhost, #rport

Instance Method Details

#get_hostnameString

Gets the hostname of the system

Returns:

  • (String)

    hostname



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/msf/core/post/windows/system.rb', line 29

def get_hostname
  hostname = nil

  if session.type == 'meterpreter'
    hostname = session.sys.config.sysinfo['Computer'].to_s
  end

  if hostname.blank? && session.type == 'powershell'
    hostname = cmd_exec('[System.Net.Dns]::GetHostName()').to_s
  end

  if hostname.blank? && command_exists?('hostname')
    hostname = cmd_exec('hostname').to_s
  end

  if hostname.blank?
    hostname = get_env('COMPUTERNAME').to_s
  end

  raise if hostname.blank?

  report_host({ host: rhost, name: hostname.downcase })
  hostname.downcase
rescue StandardError
  raise 'Unable to retrieve hostname'
end

#initialize(info = {}) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/msf/core/post/windows/system.rb', line 9

def initialize(info = {})
  super(
    update_info(
      info,
      'Compat' => {
        'Meterpreter' => {
          'Commands' => %w[
            stdapi_sys_config_sysinfo
          ]
        }
      }
    )
  )
end