* Pure-PHP implementation of SSHv1.
* Here's a short example of how to use this library:
* include 'Net/SSH1.php';
* $ssh = new Net_SSH1('www.domain.tld');
* if (!$ssh->login('username', 'password')) {
* echo $ssh->exec('ls -la');
* Here's another short example:
* include 'Net/SSH1.php';
* $ssh = new Net_SSH1('www.domain.tld');
* if (!$ssh->login('username', 'password')) {
* echo $ssh->read('username@username:~$');
* $ssh->write("ls -la\n");
* echo $ssh->read('username@username:~$');
* More information on the SSHv1 specification can be found by reading
* {@link http://www.snailbook.com/docs/protocol-1.5.txt protocol-1.5.txt}.
* LICENSE: Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
* The above copyright notice and this permission notice shall be included in
* all copies or substantial portions of the Software.
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
* @author Jim Wigginton <terrafrost@php.net>
* @copyright 2007 Jim Wigginton
* @license http://www.opensource.org/licenses/mit-license.html MIT License
* @link http://phpseclib.sourceforge.net
* @see self::getSupportedCiphers()
define('NET_SSH1_CIPHER_NONE', 0);
define('NET_SSH1_CIPHER_IDEA', 1);
define('NET_SSH1_CIPHER_DES', 2);
* All implementations are required to support this
define('NET_SSH1_CIPHER_3DES', 3);
* TRI's Simple Stream encryption CBC
* Not supported nor is it defined in the official SSH1 specs. OpenSSH, however, does define it (see cipher.h),
* although it doesn't use it (see cipher.c)
define('NET_SSH1_CIPHER_BROKEN_TSS', 4);
* @internal According to the SSH1 specs:
* "The first 16 bytes of the session key are used as the key for
* the server to client direction. The remaining 16 bytes are used
* as the key for the client to server direction. This gives
* independent 128-bit keys for each direction."
* This library currently only supports encryption when the same key is being used for both directions. This is
* because there's only one $crypto object. Two could be added ($encrypt and $decrypt, perhaps).
define('NET_SSH1_CIPHER_RC4', 5);
* Not supported nor is it defined in the official SSH1 specs. OpenSSH, however, defines it (see cipher.h) and
define('NET_SSH1_CIPHER_BLOWFISH', 6);
* @see self::getSupportedAuthentications()
* .rhosts or /etc/hosts.equiv
define('NET_SSH1_AUTH_RHOSTS', 1);
* pure RSA authentication
define('NET_SSH1_AUTH_RSA', 2);
* password authentication
* This is the only method that is supported by this library.
define('NET_SSH1_AUTH_PASSWORD', 3);
* .rhosts with RSA host authentication
define('NET_SSH1_AUTH_RHOSTS_RSA', 4);
* @link http://3sp.com/content/developer/maverick-net/docs/Maverick.SSH.PseudoTerminalModesMembers.html
define('NET_SSH1_TTY_OP_END', 0);
* @see self::_get_binary_packet()
define('NET_SSH1_RESPONSE_TYPE', 1);
* @see self::_get_binary_packet()
define('NET_SSH1_RESPONSE_DATA', 2);
define('NET_SSH1_MASK_CONSTRUCTOR', 0x00000001);
define('NET_SSH1_MASK_CONNECTED', 0x00000002);
define('NET_SSH1_MASK_LOGIN', 0x00000004);
define('NET_SSH1_MASK_SHELL', 0x00000008);
* Returns the message numbers
define('NET_SSH1_LOG_SIMPLE', 1);
* Returns the message content
define('NET_SSH1_LOG_COMPLEX', 2);
* Outputs the content real-time
define('NET_SSH1_LOG_REALTIME', 3);
* Dumps the content real-time to a file
define('NET_SSH1_LOG_REALTIME_FILE', 4);
* Returns when a string matching $expect exactly is found
define('NET_SSH1_READ_SIMPLE', 1);
* Returns when a string matching the regular expression $expect is found
define('NET_SSH1_READ_REGEX', 2);
* Pure-PHP implementation of SSHv1.
* @author Jim Wigginton <terrafrost@php.net>
var $identifier = 'SSH-1.5-phpseclib';
* The cryptography object
* The bits that are set represent functions that have been called already. This is used to determine
* if a requisite function has been successfully executed. If not, an error should be thrown.
* The Server Key Public Exponent
* Logged for debug purposes
* @see self::getServerKeyPublicExponent()
var $server_key_public_exponent;
* The Server Key Public Modulus
* Logged for debug purposes
* @see self::getServerKeyPublicModulus()
var $server_key_public_modulus;
* The Host Key Public Exponent
* Logged for debug purposes
* @see self::getHostKeyPublicExponent()
var $host_key_public_exponent;
* The Host Key Public Modulus
* Logged for debug purposes
* @see self::getHostKeyPublicModulus()
var $host_key_public_modulus;
* Logged for debug purposes
* @see self::getSupportedCiphers()
var $supported_ciphers = array(
NET_SSH1_CIPHER_NONE => 'No encryption',
NET_SSH1_CIPHER_IDEA => 'IDEA in CFB mode',
NET_SSH1_CIPHER_DES => 'DES in CBC mode',
NET_SSH1_CIPHER_3DES => 'Triple-DES in CBC mode',
NET_SSH1_CIPHER_BROKEN_TSS => 'TRI\'s Simple Stream encryption CBC',
NET_SSH1_CIPHER_RC4 => 'RC4',
NET_SSH1_CIPHER_BLOWFISH => 'Blowfish'
* Supported Authentications
* Logged for debug purposes
* @see self::getSupportedAuthentications()
var $supported_authentications = array(
NET_SSH1_AUTH_RHOSTS => '.rhosts or /etc/hosts.equiv',
NET_SSH1_AUTH_RSA => 'pure RSA authentication',
NET_SSH1_AUTH_PASSWORD => 'password authentication',
NET_SSH1_AUTH_RHOSTS_RSA => '.rhosts with RSA host authentication'
* @see self::getServerIdentification()
var $server_identification = '';
var $protocol_flags = array();
var $protocol_flag_log = array();
var $message_log = array();
* Real-time log file pointer
* @see self::_append_log()
* Real-time log file size
* @see self::_append_log()
* Real-time log file wrap boolean
* @see self::_append_log()
var $interactiveBuffer = '';
* @see self::setTimeout()
* @see self::_get_channel_packet()
* @see self::_format_log()
* @see self::_format_log()
var $log_long_width = 65;
* @see self::_format_log()
var $log_short_width = 16;
* Timeout for initial connection
* Set by the constructor call. Calling setTimeout() is optional. If it's not called functions like
* exec() won't timeout unless some PHP setting forces it too. The timeout specified in the constructor,
* however, is non-optional. There will be a timeout, whether or not you set it. If you don't it'll be
* 10 seconds. It is used by fsockopen() in that function.