Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*****************************************************************************
- *
- * RSSC - Range Scan SSH CMD
- *
- * Author: MRK <mrkproductions@gmail.com>
- *
- * Description:
- * Simple script for connect to ssh and run custom cmd on shell
- *
- *****************************************************************************/
- error_reporting(0);
- set_time_limit(0);
- ini_set("memory_limit","2048M");
- ini_set("suhosin.memory_limit","2048M");
- class rssc {
- // SSH ACCESS DATA
- var $user;
- var $pass;
- var $port = 22;
- var $cmd;
- var $fail=0;
- var $completed=0;
- function __construct() {
- global $argv;
- $init_time = time();
- 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";
- $this->checkVendor();
- if (is_null($argv[1])):
- echo "Use: php ".$argv[0]." <ip_start> <ip_end> <user> <pass> <command line>\n\r";
- elseif (filter_var($argv[1], FILTER_VALIDATE_IP) === false):
- echo "IP Start ".$argv[1]." is not a valid ip\n";
- elseif (filter_var($argv[2], FILTER_VALIDATE_IP) === false):
- echo "IP End ".$argv[2]." is not a valid ip\n";
- elseif (is_null($argv[3])):
- echo "Use: php ".$argv[0]." <ip_start> <ip_end> <user> <pass> <command line>\n\r";
- else:
- $ips = $this->getRange($argv[1], $argv[2]);
- $this->user=$argv[3];
- $this->pass=$argv[4];
- $this->cmd=/*$argv[4]." ".*/$argv[5]." ".$argv[6]." ".$argv[7]." ".$argv[8]." ".$argv[9]." ".$argv[10]." ".$argv[11];
- /* echo "SSH Password: ";
- $stdin = fopen('php://stdin', 'r');
- $response = fgetc($stdin);
- $this->pass=$response;
- */
- echo "\e[1mSSH Login\033[0m: ".$this->user." \e[1mPass\033[0m: ".$this->pass;
- //echo " Password: ???????";
- echo " \e[1mPort\033[0m: ".$this->port;
- echo " \e[1mShell Cmd\033[0m: ".$this->cmd."\n\r";
- echo " \n\r";
- echo "\e[1m[\033[0mTotal hosts: \e[32m".count($ips)."\e[0m\e[1m]\033[0m\n\r";
- $line_ips = implode(', ',$ips);
- if (count($ips) <= 20):
- echo "\e[1mIPS\033[0m: ".$line_ips."\n\r";
- endif;
- echo "Continue? (Y/N):";
- $stdin = fopen('php://stdin', 'r');
- $response = fgetc($stdin);
- if ($response != 'Y' && $response != 'y') {
- echo "Aborted.\n";
- exit;
- }
- foreach ($ips as $v) {
- $this->conExec($v);
- }
- endif;
- $end_time = (time() - $init_time);
- 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";
- }
- function conExec($ip) {
- //var $stream;
- $user=$this->user;
- echo "Connecting to \e[1m$user\e[0m@\e[1m$ip\e[0m ";
- $connection = ssh2_connect($ip, $this->port);
- // echo "We are trying login... wait... ;) ";
- if (ssh2_auth_password($connection, $this->user, $this->pass)):
- echo "\033[42m Connected \033[0m\n\r";
- echo "Running CMD: ".$this->cmd."\n\r";
- $stream = ssh2_exec($connection, $this->cmd);
- stream_set_blocking($stream, true);
- if ($stream_out = ssh2_fetch_stream($stream, SSH2_STREAM_STDIO)):
- //echo "\n\r\tCMD OUTPUT:\n\r";
- echo "- \e[1mstart output\e[0m\n\r \n\r\t";
- echo stream_get_contents($stream_out);
- echo "\n\r- \e[1mend output\e[0m\n\r\n\r";
- //echo $ip." ".$stream."\n\r";
- $this->connected++;
- endif;
- else:
- echo "\033[41m \e[1mError \e[0m \033[0m\n\r";
- $this->fail++;
- endif;
- }
- function getRange($ip_start, $ip_end) {
- $ip_s = ip2long($ip_start);
- $ip_e = ip2long($ip_end);
- if ($ip_s > $ip_e):
- die("\e[32mIP Start must be lower than IP End\e[0m\n\r");
- endif;
- while ($ip_s <= $ip_e) {
- //echo long2ip($ip_s)."\n\r";
- $arr[] = long2ip($ip_s);
- $ip_s++;
- }
- return $arr;
- }
- function checkVendor() {
- if (!function_exists('ssh2_fetch_stream')):
- die("\e[31mSorry, you need SSH2 Pecl extension to run this script\e[0m\n\r");
- endif;
- }
- }
- $rssc = new rssc();
- //var_dump($argv);
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement