login() public method

The $password parameter can be a plaintext password, a Crypt_RSA object or an array
See also: self::_login()
public login ( string $username ) : boolean
$username string
return boolean
コード例 #1
16
ファイル: AriiExec.php プロジェクト: AriiPortal/I5Bundle
 public function Exec($command)
 {
     $engine = $this->session->getSpooler();
     if (!isset($engine[0]['shell'])) {
         print "?!";
         exit;
     }
     $shell = $engine[0]['shell'];
     $host = $shell['host'];
     $user = $shell['user'];
     $password = $shell['password'];
     $method = 'CURL';
     set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
     include 'Net/SSH2.php';
     include 'Crypt/RSA.php';
     $ssh = new \Net_SSH2($host);
     if (1) {
         $key = new \Crypt_RSA();
         $ret = $key->loadKey("-----BEGIN RSA PRIVATE KEY-----\nMIICWgIBAAKBgQCzRy01HoHIzBJJb/D8A/eTV3qiZxy0NIR97NE14rJblnJZT5Kg\noP2DvIRzlB0msL5cHQJ/qXYAoemHRDKqNZuj89+MYsBeZqNu3/DXdZLq9XJ8e2rb\nsGrDjHvCHEDWL0JIRFnRacem55+XsUsKTIs4tbcD6adMPIYJSQQ7oB/8AQIBIwKB\ngB67vptkUMNWLwVGY9NuZPSv6SMnnoVK1OJjHIzlCKH8iKGYnMsUSLd/ZynBnpjr\nGVGekrbMl+LZ7YTnHqDV/WxGoWEc3xiHE8/HwZwQZxP92K70inz8+6dGEagsrSqO\nQkdAPR/+qen7uQ9yXqj7WAoNFicPJ2cpo8kuEW33KywzAkEA4yH4jf0uNBFDUkR6\ni9DQC5bsgEloVezWnCsm6eIm5o5SGKPZ6Rpro/h3pq5qvPmCtjrZFnK0Dab9xkFr\n/F9lkwJBAMoQMqxYdnPz74Bto99o0PZrk2ikROwXR9eURi3B4bWGq9+mvN3OEQdE\n8JofGyq60LMlnFAkE7v49fYHziyaFJsCQHTPpGZHsVybKe/LcjlG0WULyhYXH7cp\nWG2SiQqRkFlQgf4LH5xz/Nf8IEcX3x9bv5DrEI8zrQ5V4Zko9bT93HcCQQCEyNDX\np9jP2tCWOWuwEa3jwwkY4PoXfQNTJuxJ9G/AbnDyDnwcup15zje1vKtz2dmaS+pg\njLyC1s2Ea4d8ZUC9AkAeUr/N+011K2zGTjxZnAFY/Ow348bomzddiJYAYA+76exV\n3wUYsjeDxqq8Km93+iMQ8DDNZIvoVcfYQW9BfDlf\n-----END RSA PRIVATE KEY-----   ");
         if (!$ret) {
             echo "loadKey failed\n";
             print "<pre>" . $ssh->getLog() . '</pre>';
             exit;
         }
     } elseif (isset($shell['password'])) {
         $key = $shell['password'];
     } else {
         $key = '';
         // ?! possible ?
     }
     if (!$ssh->login($user, $key)) {
         exit("Login Failed ({$user})");
     }
     return $ssh->exec("system '{$command}'");
 }
コード例 #2
1
ファイル: CiscoSSH.php プロジェクト: reyronald/CiscoSSH
 /**
  * Logs in to a SSH server with the specified credentials,
  * and returns the Net_SSH2 instance.
  *
  * @return 	Net_SSH2 $ssh 
  * @author 	Ronald Rey
  **/
 public static final function getSSH($host, $user, $pass, $timeout)
 {
     $ssh = new Net_SSH2($host);
     if (!$ssh->login($user, $pass)) {
         exit('Login to failed.');
     }
     $ssh->setTimeout($timeout);
     $ssh->write(" ");
     return $ssh;
 }
コード例 #3
0
ファイル: Ssh.php プロジェクト: sayiho/Jumper
 /**
  * @throws \Jumper\Exception\CommunicatorException
  */
 public function connect()
 {
     $authentication = $this->authentication->getAuthentication($this->ssh);
     if (!$this->ssh->login($this->authentication->getUser(), $authentication)) {
         throw new CommunicatorException($this->ssh->getLastError());
     }
 }
コード例 #4
0
ファイル: SshHelper.php プロジェクト: rafeco/simpledeployer
 public function runCommand($cmd)
 {
     if (!empty($this->key_path)) {
         $key = new Crypt_RSA();
         $key->loadKey(file_get_contents($this->key_path));
     }
     $ssh = new Net_SSH2($this->host, $this->port);
     if ($key) {
         $ssh->login($this->user, $key);
     } else {
         $ssh->login($this->user, $this->password);
     }
     $out = $ssh->exec($cmd);
     return $out;
 }
コード例 #5
0
function getPing($sourceIP, $destinationIP)
{
    // This will work with any pfSense install. $sourceIP is the IP address of the WAN that you want to
    // use to ping with. This allows you to ping the same address from multiple WANs if you need to.
    global $local_pfsense_ip;
    global $pfSense_username;
    global $pfSense_password;
    $ssh = new Net_SSH2($local_pfsense_ip);
    if (!$ssh->login($pfSense_username, $pfSense_password)) {
        //exit('Login Failed');
        return array(0, 0);
    }
    $terminal_output = $ssh->exec('ping -c 5 -q -S ' . $sourceIP . ' ' . $destinationIP);
    // If using something besides OS X you might want to customize the following variables for proper output of average ping.
    $findme_start = '= ';
    $start = strpos($terminal_output, $findme_start);
    $ping_return_value_str = substr($terminal_output, $start + 2, 100);
    $findme_stop1 = '.';
    $stop = strpos($ping_return_value_str, $findme_stop1);
    $findme_avgPing_decimal = '.';
    $avgPing_decimal = strpos($ping_return_value_str, $findme_avgPing_decimal, 6);
    $findme_forward_slash = '/';
    $avgPing_forward_slash = strpos($ping_return_value_str, $findme_forward_slash);
    $avgPing = substr($ping_return_value_str, $stop + 5, $avgPing_decimal - $avgPing_forward_slash - 1);
    return $avgPing;
}
コード例 #6
0
 public function execute($com = false)
 {
     if ($com == false) {
         die("Epic Fail! Yes, it was epic");
     }
     $oldPath = set_include_path("/home/sites/berrics.dev/sharedVendors/phpseclib");
     App::import("Vendor", "SSH2", array("file" => "phpseclib/Net/SSH2.php"));
     set_include_path($oldPath);
     $ssh = new Net_SSH2('10.181.67.27');
     $login = $ssh->login('root', 'WEB1MH0r5t7Wn');
     $out = '';
     switch ($com) {
         case "sync-berrics-all":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-all");
             $out .= $ssh->exec("/home/sites/berrics.shell/clear-cache");
             break;
         case "sync-berrics-all-check":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-all-check");
             break;
         case "sync-berrics-splash":
             $out .= $ssh->exec("/home/sites/berrics.shell/sync-berrics-splash");
             break;
         default:
             $out .= "Nothing to do...";
             break;
     }
     $this->set(compact("out"));
     //echo $ssh->exec('/home/sites/berrics.shell/sync-berrics-all-check');
 }
コード例 #7
0
function set_addr($subnet, $interface)
{
    $interface = $interface != '' ? $interface : $GLOBALS['ethernet_forenaming_scheme'] . '1';
    $ip = explode('/', $subnet);
    $cidr = $ip[1];
    $ip_parts = explode('.', $ip[0]);
    $ip_parts[3] = $ip_parts[3] + 1;
    $gw = implode('.', $ip_parts);
    $ip_parts[3] = $ip_parts[3] + 1;
    $ip = implode('.', $ip_parts);
    $ssh = new Net_SSH2('192.168.88.1');
    if ($ssh->login('admin', $GLOBALS['admin_password'])) {
        //while we're here we might as well reset the mac addresses again.
        $detail = $ssh->exec('int eth print');
        if (preg_match_all("/{$GLOBALS['ethernet_forenaming_scheme']}/", $detail, $matches)) {
            $i = 1;
            foreach ($matches[0] as $match) {
                $ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['ethernet_forenaming_scheme'] . $i);
                $ssh->exec(':beep frequency=120 length=2ms;');
                $i++;
                if ($i == '10') {
                    $ssh->exec('int ethernet reset-mac-address ' . $GLOBALS['sfp_forenaming_scheme'] . '1');
                }
            }
        }
        $ssh->exec('ip address add address=' . $ip . '/' . $cidr . ' interface=' . $interface);
        //set the ip on the specified interface.
        $ssh->exec('ip route add dst-address=0.0.0.0/0 gateway=' . $gw);
        //add the default route
    }
}
コード例 #8
0
ファイル: Release.class.php プロジェクト: Warkot/Bolt
 public function deploy()
 {
     $releaseId = $this->dataBase->startRelease();
     $ssh = new Net_SSH2(SSH_SERVER);
     $key = new Crypt_RSA();
     $key->setPassword(SSH_PASSWORD);
     $key->loadKey(file_get_contents(PATH_TO_PRIVATE_KEY));
     if (!$ssh->login(SSH_LOGIN, $key)) {
         $this->dataBase->logStep($releaseId, 'ssh ' . SSH_SERVER, ['error' => 'Login failed'], 1);
         exit('Login Failed');
     }
     $ssh->enableQuietMode();
     $command = $this->bash->dtLock('sandbox-mercury', 'mercury');
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
     $command = $this->bash->dtPrep('sandbox-mercury', 'mercury', ["mercury" => "dev"]);
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
     $command = $this->bash->dtPush('sandbox-mercury', 'mercury');
     $output['success'] = $ssh->exec($command);
     $output['error'] = $ssh->getStdError();
     $this->dataBase->logStep($releaseId, $command, $output, $ssh->getExitStatus());
 }
コード例 #9
0
ファイル: AriiSSH.php プロジェクト: AxelANGENAULT/CoreBundle
 public function Exec($host, $user, $password, $command)
 {
     $ssh = new Net_SSH2($host);
     if (!$ssh->login($user, $password)) {
         exit('Login Failed');
     }
     echo $ssh->exec("system '{$command}'");
 }
コード例 #10
0
ファイル: lib.php プロジェクト: istrwei/vpn_manager
 function delete_user($username, $server_host, $server_username, $server_password)
 {
     $ssh = new Net_SSH2($server_host);
     if ($ssh->login($server_username, $server_password) == false) {
         exit('Login Failed');
     }
     $command = 'userdel -r ' . $username;
     echo $ssh->exec($command);
 }
コード例 #11
0
function ConectSSHStation($server)
{
    $ssh = new Net_SSH2($server);
    if (!$ssh->login(userubnt, passubnt)) {
        print "Login Failed {$server}";
    }
    $mca = $ssh->exec("mca-status");
    return $mca;
}
コード例 #12
0
ファイル: AriiExec.php プロジェクト: AriiPortal/Arii
 public function Exec($command)
 {
     set_include_path(get_include_path() . PATH_SEPARATOR . '../vendor/phpseclib');
     include 'Net/SSH2.php';
     $ssh = new \Net_SSH2($this->host);
     if (!$ssh->login($this->user, $this->password)) {
         exit('Login Failed');
     }
     return $ssh->exec("system '{$command}'");
 }
コード例 #13
0
ファイル: Ssh.php プロジェクト: Thinlt/simicart
 public function connectToServer()
 {
     include Mage::getBaseDir('base') . DS . 'lib' . DS . 'Ssh' . DS . 'Net' . DS . 'SSH2.php';
     $ssh = new Net_SSH2($this->getMacServerIp());
     if ($ssh->login($this->getMacServerUser(), $this->getMacServerPassword())) {
         return $ssh;
     } else {
         return false;
     }
 }
コード例 #14
0
ファイル: AriiExec.php プロジェクト: AriiPortal/ATSBundle
    public function Exec($command, $stdin = '')
    {
        $database = $this->session->getDatabase();
        $name = $database['name'];
        $engine = $this->session->getSpoolerByName($name, 'waae');
        if (!isset($engine[0]['shell'])) {
            print "?!";
            exit;
        }
        set_include_path('../vendor/phpseclib' . PATH_SEPARATOR . get_include_path());
        include 'Net/SSH2.php';
        include 'Crypt/RSA.php';
        $shell = $engine[0]['shell'];
        $host = $shell['host'];
        $user = $shell['user'];
        $ssh = new \Net_SSH2($host);
        if (isset($shell['key'])) {
            $key = new \Crypt_RSA();
            $ret = $key->loadKey($shell['key']);
            if (!$ret) {
                echo "loadKey failed\n";
                print "<pre>" . $ssh->getLog() . '</pre>';
                exit;
            }
        } elseif (isset($shell['password'])) {
            $key = $shell['password'];
        } else {
            $key = '';
            // ?! possible ?
        }
        if (!$ssh->login('autosys', $key)) {
            print 'Login Failed';
            print "<pre>" . $ssh->getLog() . '</pre>';
            exit;
        }
        if ($stdin == '') {
            return $ssh->exec(". ~/.bash_profile;{$command}");
        }
        // Test STDIN
        $ssh->enablePTY();
        print "profile" . $ssh->exec(". ~/.bash_profile");
        print "sort" . ($exec = $ssh->exec('sort'));
        $ssh->write(<<<EOF
echo "update_job: SE.ERIC.JOB.JobType_UNIX"
echo "description: 'ok!!'
EOF
);
        $ssh->reset(true);
        $ssh->setTimeout(2);
        print $ssh->read();
        return;
        return $ssh->read();
        // outputs the echo above
    }
コード例 #15
0
ファイル: runbash.php プロジェクト: raulastu/sshmail
function runcmd($cmd)
{
    include 'Net/SSH2.php';
    $ssh = new Net_SSH2('localhost');
    if (!$ssh->login('rc', 'cacapedo')) {
        exit('Login Failed');
    }
    // echo $ssh->exec('pwd');
    $r = $ssh->exec($cmd);
    return str_replace("\n", "<br>", $r);
}
コード例 #16
0
ファイル: vps.class.php プロジェクト: AstroProfundis/Feathur
 public static function localhost_connect()
 {
     global $cphp_config;
     $sSSH = new Net_SSH2('127.0.0.1');
     $sKey = new Crypt_RSA();
     $sKey->loadKey(file_get_contents($cphp_config->settings->rootkey));
     if ($sSSH->login("root", $sKey)) {
         return $sSSH;
     } else {
         return $sErrors = array("Could not connect to the local host.");
     }
 }
コード例 #17
0
ファイル: SSHConnection.php プロジェクト: VonUniGE/consh
 /**
  * connect to the remote server
  * @return bool|\Net_SSH2
  */
 private function connect()
 {
     $ssh = new \Net_SSH2(Setting::getSetting('remote:host'));
     $key = new Crypt_RSA();
     $key->loadKey(file_get_contents(Setting::getSetting('ssh:priv_key')));
     if (!$ssh->login(Setting::getSetting('remote:user'), $key)) {
         $cli = new CLImate();
         $cli->error("Could not connect to server");
         return false;
     }
     return $ssh;
 }
コード例 #18
0
ファイル: amazon.php プロジェクト: myvirtualteams/samplecode
 /** 	IS USED TO CONNECT TO SSH
 		INCLUDE THIS BEFORE FUNCTION CALL
 	 *		set_include_path(get_include_path() . PATH_SEPARATOR . ROOT_DIRECTORY_PATH . 'phpseclib');
 			include_once('Net/SSH2.php');
 			include_once('Crypt/RSA.php');
 		EXAMPLE AT addEc2Request.php
 
 		@return empty sting if thigs goes wrong.
 	 */
 function connect_to_ssh($publicDnsName, $keyPairName)
 {
     $ssh = new Net_SSH2($publicDnsName);
     $key = new Crypt_RSA();
     $key->loadKey(file_get_contents(ROOT_DIRECTORY_PATH . AMAZON_SSH_KEYS . $keyPairName));
     if (!$ssh->login('ubuntu', $key)) {
         //WHEN USER IS NOT LOGGED INTO SSH
         return 2;
     } else {
         //if things goes right.
         return array('Net_SSH2' => $ssh, 'Crypt_RSA' => $key);
     }
 }
コード例 #19
0
ファイル: func.ssh2.inc.php プロジェクト: 404rq/bgpanel
/**
 * Establish a SSH2 connection using PHPSECLIB
 *
 * @return object (ssh obj) OR string (err)
 */
function newNetSSH2($ip, $sshport = 22, $login, $password)
{
    $ssh = new Net_SSH2($ip, $sshport);
    if (!$ssh->login($login, $password)) {
        $socket = @fsockopen($ip, $sshport, $errno, $errstr, 5);
        if ($socket == FALSE) {
            $debug = "Unable to connect to {$ip} on port {$sshport} : {$errstr} ( Errno: {$errno} )";
            return $debug;
        }
        return 'Unable to connect to box with SSH';
    }
    return $ssh;
}
コード例 #20
0
ファイル: Sftp.php プロジェクト: Leemo/deployer
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     foreach ($this->params() as $param => $value) {
         $this->_params[$param] = \Deployer::applyGlobalParams($value);
     }
     $ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
     if (!$ssh->login($this->param('username'), $this->param('password'))) {
         throw new \Deployer\TaskException('Can\'t connect to remote host');
     }
     $scp = new \Net_SCP($ssh);
     $scp->put($this->param('dest'), file_get_contents($this->param('file')));
     $info = sprintf('Filesize: %d bytes', filesize($this->param('file')));
     return $this->info($info);
 }
コード例 #21
0
ファイル: Host.php プロジェクト: romaninsh/dokku_alt
 function connect()
 {
     try {
         $ssh = new \Net_SSH2($this['addr'], $this['ssh_port'] ?: 22);
         $key = $this->getPrivateKey();
         if (!$ssh->login($this['ssh_user'] ?: 'dokku', $key)) {
             throw $this->exception('Login Failed!');
         }
         return $ssh;
     } catch (BaseException $e) {
         throw $e;
         // don't do anything yet
         // var_dump($e);
     }
 }
コード例 #22
0
ファイル: Ssh.php プロジェクト: Leemo/deployer
 /**
  * Execute task and return report info
  *
  * @return \Deployer\Task
  */
 public function execute()
 {
     $info = '';
     foreach ($this->params() as $param => $value) {
         $this->_params[$param] = \Deployer::applyGlobalParams($value);
     }
     $ssh = new \Net_SSH2($this->param('host'), $this->param('port'));
     if (!$ssh->login($this->param('username'), $this->param('password'))) {
         throw new \Deployer\TaskException('Can\'t connect to remote host');
     }
     foreach ((array) $this->param('cmd') as $cmd) {
         $command = 'cd ' . $this->param('directory') . ' && ' . $cmd;
         $command = \Deployer::applyGlobalParams($command);
         $result = $ssh->exec($command);
         $info .= '$ ' . $command . PHP_EOL . $result . PHP_EOL;
     }
     return $this->info($info);
 }
コード例 #23
0
ファイル: get_all_stats.php プロジェクト: cloudseo/nginad
function get_json_info_from_server($ip_address, $username, $password, $start_date, $end_date = null)
{
    global $path_to_logfile_rollup;
    $ssh = new Net_SSH2($ip_address);
    if (!$ssh->login($username, $password)) {
        exit('Login Failed');
    }
    $command = 'php ' . $path_to_logfile_rollup . 'logfile_rollup.php ' . $start_date;
    if ($end_date !== null) {
        $command .= ' ' . $end_date;
    }
    $json_response = null;
    try {
        $json_response = $ssh->exec($command);
    } catch (Exception $e) {
        die($e->getMessage());
    }
    return $json_response;
}
コード例 #24
0
function ssh_connect($host)
{
    dbg_log("Connecting over SSH to {$host}");
    #define('NET_SSH2_LOGGING', NET_SSH2_LOG_COMPLEX);
    $ssh = new Net_SSH2($host);
    $key = new Crypt_RSA();
    $key->setPassword(get_config()->host_ssh_private_key_password);
    $keyPath = get_config()->host_ssh_private_key;
    $keyString = file_get_contents($keyPath);
    $userString = get_config()->host_ssh_username;
    if (!$key->loadKey($keyString)) {
        dbg_log(var_dump($ssh->getErrors(), true));
        exit("cannot import key {$keyPath}");
    }
    if (!$ssh->login($userString, $key)) {
        dbg_log($ssh->getLastError());
        exit('Login Failed');
    }
    return $ssh;
}
コード例 #25
0
function getInfo($ip, $sshkey_location)
{
    $ssh = new Net_SSH2($ip);
    //key
    $key = new Crypt_RSA();
    $key->loadKey(file_get_contents($sshkey_location));
    if (!$ssh->login('root', $key)) {
        die("SSH Login Failed!");
    } else {
        $return['disk_usage'] = $ssh->exec("df -k .|awk 'NR==2 {print \$5}'");
        $return['disk_remaining'] = 100 - substr($return['disk_usage'], 0, -1) . "%";
        $uptime = $ssh->exec('echo `uptime`');
        list($uptime, $load) = explode('load average:', $uptime);
        list($trash, $uptime) = explode(' up ', $uptime);
        list($uptime, $trash) = explode(', ', $uptime);
        $return['uptime'] = $uptime;
        $return['load'] = $load;
        //get memory
        $return['memory_free'] = $ssh->exec("cat /proc/meminfo|grep 'MemFree'");
        list($trash, $return['memory_free']) = explode('MemFree:', $return['memory_free']);
    }
    return $return;
}
コード例 #26
0
ファイル: Zugang.php プロジェクト: sawh/ostepu-system
 /**
  * ???
  *
  * @param string[][] $data Die Serverdaten
  * @return ???
  */
 public static function Verbinden($data)
 {
     $ssh = null;
     if ($data['ZV']['zv_ssh_auth_type'] == 'passwd') {
         $ssh = new Net_SSH2($data['ZV']['zv_ssh_address']);
         $res = @$ssh->login($data['ZV']['zv_ssh_login'], $data['ZV']['zv_ssh_password']);
         if (!$res) {
             return null;
         }
         $ssh->setTimeout(0);
     } else {
         if ($data['ZV']['zv_ssh_auth_type'] == 'keyFile') {
             $ssh = new Net_SSH2($data['ZV']['zv_ssh_address']);
             $key = new Crypt_RSA();
             $key->loadKey(file_get_contents($data['ZV']['zv_ssh_key_file']));
             if (!$ssh->login($data['ZV']['zv_ssh_login'], $key)) {
                 return null;
             }
             $ssh->setTimeout(0);
         }
     }
     return $ssh;
 }
コード例 #27
0
ファイル: bandit1.php プロジェクト: agamenom/Bandit
<html>
<head><title>Bandit</title></head>
<body>
<?php 
set_include_path(get_include_path() . PATH_SEPARATOR . 'c:\\wamp\\www\\bandit\\phpseclib');
include 'phpseclib\\Net\\SSH2.php';
$ssh = new Net_SSH2('bandit1.labs.overthewire.org');
if (!$ssh->login('bandit1', 'boJ9jbbUNNfktd78OOpsqOltutMc3MY1')) {
    exit('Login Failed');
} else {
    echo "<b>CONECTADO!</b> <p>";
}
echo "Bandit2 Pass Walkthrough<p>\n\t++ ls -la (to see all files)<br>\n\t++ cat ./- (special character filename)<p>";
echo "<h1>" . $ssh->exec('cat ./-') . "</h1>";
echo $ssh->exec('exit');
?>
</body>
</html>


コード例 #28
0
ファイル: ssh-run.php プロジェクト: programmerrahul/vastecom
<?php

$output = shell_exec('sh PATCH_SUPEE-6788_CE_1.9.1.0_v1-2015-10-27-09-06-11.sh');
echo "<pre>{$output}</pre>";
exit;
include 'Crypt/RSA.php';
include 'Net/SSH2.php';
try {
    $key = new Crypt_RSA();
    //$key->setPassword('whatever');
    $key->loadKey(file_get_contents('id_rsa.ppk'));
    $ssh = new Net_SSH2('ftp.narayansoft.com');
    if (!$ssh->login('username', $key)) {
        exit('Login Failed');
    }
} catch (Exception $e) {
    echo 'Caught exception: ', $e->getMessage(), "\n";
}
exit;
echo $ssh->read('username@username:~$');
$ssh->write("ls -la\n");
echo $ssh->read('username@username:~$');
コード例 #29
0
ファイル: SFTP.php プロジェクト: helenadeus/s3db.map
 /**
  * Login
  *
  * @param String $username
  * @param optional String $password
  * @return Boolean
  * @access public
  */
 function login($username, $password = '')
 {
     if (!parent::login($username, $password)) {
         return false;
     }
     $packet = pack('CNa*N3', NET_SSH2_MSG_CHANNEL_OPEN, strlen('session'), 'session', $this->client_channel, $this->window_size, $this->packet_size_server_to_client);
     if (!$this->_send_binary_packet($packet)) {
         return false;
     }
     $response = $this->_get_binary_packet();
     if ($response === false) {
         user_error('Connection closed by server', E_USER_NOTICE);
         return false;
     }
     extract(unpack('Ctype', $this->_string_shift($response, 1)));
     switch ($type) {
         case NET_SSH2_MSG_CHANNEL_OPEN_CONFIRMATION:
             $this->_string_shift($response, 4);
             // skip over client channel
             extract(unpack('Nserver_channel', $this->_string_shift($response, 4)));
             $this->server_channels[$this->client_channel] = $server_channel;
             $this->_string_shift($response, 4);
             // skip over (server) window size
             extract(unpack('Npacket_size_client_to_server', $this->_string_shift($response, 4)));
             $this->packet_size_client_to_server = $packet_size_client_to_server;
             break;
         case NET_SSH2_MSG_CHANNEL_OPEN_FAILURE:
             user_error('Unable to open channel', E_USER_NOTICE);
             return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
     }
     $packet = pack('CNNa*CNa*', NET_SSH2_MSG_CHANNEL_REQUEST, $server_channel, strlen('subsystem'), 'subsystem', 1, strlen('sftp'), 'sftp');
     if (!$this->_send_binary_packet($packet)) {
         return false;
     }
     $response = $this->_get_binary_packet();
     if ($response === false) {
         user_error('Connection closed by server', E_USER_NOTICE);
         return false;
     }
     extract(unpack('Ctype', $this->_string_shift($response, 1)));
     switch ($type) {
         case NET_SSH2_MSG_CHANNEL_SUCCESS:
             break;
         case NET_SSH2_MSG_CHANNEL_FAILURE:
         default:
             user_error('Unable to initiate SFTP channel', E_USER_NOTICE);
             return $this->_disconnect(NET_SSH2_DISCONNECT_BY_APPLICATION);
     }
     if (!$this->_send_sftp_packet(NET_SFTP_INIT, "")) {
         return false;
     }
     $response = $this->_get_sftp_packet();
     if ($this->packet_type != NET_SFTP_VERSION) {
         user_error('Expected SSH_FXP_VERSION', E_USER_NOTICE);
         return false;
     }
     extract(unpack('Nversion', $this->_string_shift($response, 4)));
     $this->version = $version;
     while (!empty($response)) {
         extract(unpack('Nlength', $this->_string_shift($response, 4)));
         $key = $this->_string_shift($response, $length);
         extract(unpack('Nlength', $this->_string_shift($response, 4)));
         $value = $this->_string_shift($response, $length);
         $this->extensions[$key] = $value;
     }
     /*
      SFTPv4+ defines a 'newline' extension.  SFTPv3 seems to have unofficial support for it via '*****@*****.**',
      however, I'm not sure what '*****@*****.**' is supposed to do (the fact that it's unofficial means that it's
      not in the official SFTPv3 specs) and '*****@*****.**' / 'newline' are likely not drop-in substitutes for
      one another due to the fact that 'newline' comes with a SSH_FXF_TEXT bitmask whereas it seems unlikely that
      '*****@*****.**' would.
     */
     /*
     if (isset($this->extensions['*****@*****.**'])) {
         $this->extensions['newline'] = $this->extensions['*****@*****.**'];
         unset($this->extensions['*****@*****.**']);
     }
     */
     $this->request_id = 1;
     /*
      A Note on SFTPv4/5/6 support:
      <http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-5.1> states the following:
     
      "If the client wishes to interoperate with servers that support noncontiguous version
       numbers it SHOULD send '3'"
     
      Given that the server only sends its version number after the client has already done so, the above
      seems to be suggesting that v3 should be the default version.  This makes sense given that v3 is the
      most popular.
     
      <http://tools.ietf.org/html/draft-ietf-secsh-filexfer-13#section-5.5> states the following;
     
      "If the server did not send the "versions" extension, or the version-from-list was not included, the
       server MAY send a status response describing the failure, but MUST then close the channel without
       processing any further requests."
     
      So what do you do if you have a client whose initial SSH_FXP_INIT packet says it implements v3 and
      a server whose initial SSH_FXP_VERSION reply says it implements v4 and only v4?  If it only implements
      v4, the "versions" extension is likely not going to have been sent so version re-negotiation as discussed
      in draft-ietf-secsh-filexfer-13 would be quite impossible.  As such, what Net_SFTP would do is close the
      channel and reopen it with a new and updated SSH_FXP_INIT packet.
     */
     if ($this->version != 3) {
         return false;
     }
     $this->pwd = $this->_realpath('.');
     return true;
 }
コード例 #30
0
ファイル: sshd.php プロジェクト: nulled/anypanel
<?php

if (php_sapi_name() != 'cli') {
    exit("must be run from php-cli\n");
}
$log = 1;
define('PANEL_BASE_PATH', '/home/nulled/www');
set_include_path(get_include_path() . PATH_SEPARATOR . PANEL_BASE_PATH . '/server/modules/core/phpseclib');
require_once PANEL_BASE_PATH . '/server/modules/core/phpseclib/Net/SSH2.php';
$ssh = new Net_SSH2('205.252.250.4');
if (!$ssh->login('user', 'pass')) {
    exit('Login Failed');
}
$cmd_file = '/home/nulled/www/server/logs/command.issue';
unlink($cmd_file);
$i = 0;
while (true) {
    if (is_file($cmd_file) and filesize($cmd_file) and ($command = file_get_contents($cmd_file)) !== false) {
        unlink($cmd_file);
        $i = 0;
        if ($log) {
            echo "{$cmd_file} found\n";
        }
        $return = $ssh->exec(trim($command));
        file_put_contents($cmd_file . '.receiving', $return);
        rename($cmd_file . '.receiving', $cmd_file . '.return');
    }
    $i++;
    if ($i > 10000) {
        $i--;
        // echo "usleep(200000)\n";