Land #3129 - Fix 2782 with 2961 and stop stack-tracing download_exec

bug/bundler_fix
sinn3r 2014-03-21 11:36:59 -05:00
commit 13f5c22536
No known key found for this signature in database
GPG Key ID: 2384DB4EF06F730B
3 changed files with 120 additions and 2 deletions

View File

@ -153,4 +153,55 @@ module Msf::Post::Common
report_host(vm_data)
end
#
# Returns the value of the environment variable +env+
#
def get_env(env)
case session.type
when /meterpreter/
return session.sys.config.getenv(env)
when /shell/
if session.platform =~ /win/
if env[0,1] == '%'
unless env[-1,1] == '%'
env << '%'
end
else
env = "%#{env}%"
end
return cmd_exec("echo #{env}")
else
unless env[0,1] == '$'
env = "$#{env}"
end
return cmd_exec("echo \"#{env}\"")
end
end
nil
end
#
# Returns a hash of environment variables +envs+
#
def get_envs(*envs)
case session.type
when /meterpreter/
return session.sys.config.getenvs(*envs)
when /shell/
result = {}
envs.each do |env|
res = get_env(env)
result[env] = res unless res.blank?
end
return result
end
nil
end
end

View File

@ -45,13 +45,19 @@ class Metasploit3 < Msf::Post
end
def exists_exe?(exe)
path = session.sys.config.getenv("PATH")
vprint_status "Searching for #{exe} in the current $PATH..."
path = get_env("PATH")
if path.nil? or path.empty?
return false
vprint_error "No local $PATH set!"
else
vprint_status "$PATH is #{path.strip!}"
end
path.split(":").each{ |p|
return true if file_exist?(p + "/" + exe)
full_path = p + "/" + exe
vprint_status "Searching for '#{full_path}' ..."
return true if file_exist?(full_path)
}
return false

View File

@ -0,0 +1,61 @@
$:.push "test/lib" unless $:.include? "test/lib"
require 'module_test'
#load 'test/lib/module_test.rb'
#load 'lib/rex/text.rb'
#load 'lib/msf/core/post/common.rb'
class Metasploit4 < Msf::Post
include Msf::ModuleTest::PostTest
include Msf::Post::Common
def initialize(info={})
super( update_info( info,
'Name' => 'Testing Get Envs',
'Description' => %q{ This module will test Post::Common get envs API methods },
'License' => MSF_LICENSE,
'Author' => [ 'Ben Campbell'],
'Platform' => [ 'windows', 'linux', 'java', 'python' ],
'SessionTypes' => [ 'meterpreter', 'shell' ]
))
end
def test_get_env_windows
if session.platform =~ /win/i
it "should return windows path" do
path = get_env('WINDIR')
path =~ /windows/i
end
it "should handle % signs" do
path = get_env('%WINDIR%')
path =~ /windows/i
end
end
end
def test_get_env_nix
unless session.platform =~ /win/i
it "should return user" do
user = get_env('USER')
!user.blank?
end
it "should handle $ sign" do
user = get_env('$USER')
!user.blank?
end
end
end
def test_get_envs
it "should return multiple envs" do
res = get_envs('PATH','USERNAME')
!res['PATH'].blank? && !res['USERNAME'].blank?
end
end
end