Advertisement
Guest User

Untitled

a guest
Feb 29th, 2016
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.91 KB | None | 0 0
  1. <?php
  2. /*****************************************************************************
  3.  *
  4.  *  RSSC - Range Scan SSH CMD
  5.  *
  6.  *  Author: MRK <mrkproductions@gmail.com>
  7.  *
  8.  *  Description:
  9.  *  Simple script for connect to ssh and run custom cmd on shell
  10.  *
  11.  *****************************************************************************/
  12. error_reporting(0);
  13. set_time_limit(0);
  14. ini_set("memory_limit","2048M");
  15. ini_set("suhosin.memory_limit","2048M");
  16.  
  17. class rssc {
  18.    
  19.     // SSH ACCESS DATA
  20.     var $user;
  21.     var $pass;
  22.     var $port = 22;
  23.     var $cmd;
  24.    
  25.     var $fail=0;
  26.     var $completed=0;
  27.  
  28.    
  29.     function __construct() {
  30.         global $argv;
  31.         $init_time = time();
  32.        
  33.         echo "\e[1mRSSC\e[0m (\e[1mR\e[0mange \e[1mS\e[0mcan \e[1mS\e[0mSH \e[1mC\e[0mMD) by \e[1mMRK\e[0m <mrkproductions@gmail.com>\n\r";
  34.         $this->checkVendor();
  35.        
  36.         if (is_null($argv[1])):
  37.             echo "Use: php ".$argv[0]." <ip_start> <ip_end> <user> <pass> <command line>\n\r";
  38.        
  39.         elseif (filter_var($argv[1], FILTER_VALIDATE_IP) === false):
  40.             echo "IP Start ".$argv[1]." is not a valid ip\n";
  41.        
  42.         elseif (filter_var($argv[2], FILTER_VALIDATE_IP) === false):
  43.             echo "IP End ".$argv[2]." is not a valid ip\n";
  44.        
  45.         elseif (is_null($argv[3])):
  46.             echo "Use: php ".$argv[0]." <ip_start> <ip_end> <user> <pass> <command line>\n\r";
  47.        
  48.         else:
  49.             $ips = $this->getRange($argv[1], $argv[2]);
  50.             $this->user=$argv[3];
  51.             $this->pass=$argv[4];
  52.            
  53.             $this->cmd=/*$argv[4]." ".*/$argv[5]." ".$argv[6]." ".$argv[7]." ".$argv[8]." ".$argv[9]." ".$argv[10]." ".$argv[11];
  54.         /*  echo "SSH Password: ";
  55.             $stdin = fopen('php://stdin', 'r');
  56.             $response = fgetc($stdin);
  57.             $this->pass=$response;
  58.         */
  59.             echo "\e[1mSSH Login\033[0m: ".$this->user." \e[1mPass\033[0m: ".$this->pass;
  60.             //echo " Password: ???????";
  61.             echo " \e[1mPort\033[0m: ".$this->port;
  62.             echo " \e[1mShell Cmd\033[0m: ".$this->cmd."\n\r";
  63.             echo " \n\r";
  64.             echo "\e[1m[\033[0mTotal hosts: \e[32m".count($ips)."\e[0m\e[1m]\033[0m\n\r";
  65.             $line_ips = implode(', ',$ips);
  66.             if (count($ips) <= 20):
  67.                 echo "\e[1mIPS\033[0m: ".$line_ips."\n\r";
  68.             endif;
  69.            
  70.             echo "Continue? (Y/N):";
  71.             $stdin = fopen('php://stdin', 'r');
  72.             $response = fgetc($stdin);
  73.             if ($response != 'Y' && $response != 'y') {
  74.                echo "Aborted.\n";
  75.                exit;
  76.             }
  77.             foreach ($ips as $v) {
  78.                 $this->conExec($v);
  79.             }
  80.         endif;
  81.         $end_time = (time() - $init_time);
  82.         echo "Errors: \e[31m".$this->fail."\e[0m Completed: \e[32m".$this->completed."\e[0m @ Execution time: \e[1m$end_time \e[0msecs\n\r";
  83.     }
  84.    
  85.     function conExec($ip) {
  86.         //var $stream;
  87.         $user=$this->user;
  88.         echo "Connecting to \e[1m$user\e[0m@\e[1m$ip\e[0m ";
  89.         $connection = ssh2_connect($ip, $this->port);
  90.     //  echo "We are trying login... wait... ;) ";
  91.    
  92.         if (ssh2_auth_password($connection, $this->user, $this->pass)):
  93.             echo "\033[42m Connected \033[0m\n\r";
  94.             echo "Running CMD: ".$this->cmd."\n\r";
  95.             $stream = ssh2_exec($connection, $this->cmd);
  96.             stream_set_blocking($stream, true);
  97.        
  98.             if ($stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO)):
  99.                 //echo "\n\r\tCMD OUTPUT:\n\r";
  100.                 echo "- \e[1mstart output\e[0m\n\r \n\r\t";
  101.                 echo stream_get_contents($stream_out);
  102.                 echo "\n\r- \e[1mend output\e[0m\n\r\n\r";
  103.                 //echo $ip." ".$stream."\n\r";
  104.                 $this->connected++;
  105.             endif;
  106.         else:
  107.             echo "\033[41m \e[1mError \e[0m \033[0m\n\r";
  108.             $this->fail++;
  109.         endif;
  110.     }
  111.    
  112.     function getRange($ip_start, $ip_end) {
  113.         $ip_s = ip2long($ip_start);
  114.         $ip_e = ip2long($ip_end);
  115.         if ($ip_s > $ip_e):
  116.             die("\e[32mIP Start must be lower than IP End\e[0m\n\r");
  117.         endif;
  118.         while ($ip_s <= $ip_e) {
  119.            
  120.             //echo long2ip($ip_s)."\n\r";
  121.             $arr[] = long2ip($ip_s);
  122.             $ip_s++;
  123.         }
  124.         return $arr;
  125.     }
  126.     function checkVendor() {
  127.         if (!function_exists('ssh2_fetch_stream')):
  128.             die("\e[31mSorry, you need SSH2 Pecl extension to run this script\e[0m\n\r");
  129.         endif;
  130.     }
  131. }
  132.  
  133. $rssc = new rssc();
  134. //var_dump($argv);
  135. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement