forked from rapid7/metasploit-framework
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Land rapid7#17196, Add new get_hostname library support for Windows
- Loading branch information
Showing
1 changed file
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
# -*- coding: binary -*- | ||
|
||
module Msf | ||
class Post | ||
module Windows | ||
module System | ||
include Msf::Post::Common | ||
|
||
def initialize(info = {}) | ||
super( | ||
update_info( | ||
info, | ||
'Compat' => { | ||
'Meterpreter' => { | ||
'Commands' => %w[ | ||
stdapi_sys_config_sysinfo | ||
] | ||
} | ||
} | ||
) | ||
) | ||
end | ||
|
||
# | ||
# Gets the hostname of the system | ||
# | ||
# @return [String] hostname | ||
# | ||
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 | ||
end | ||
end | ||
end | ||
end |