PHP Class phpseclib\Net\SSH1

Author: Jim Wigginton ([email protected])
ファイルを表示 Open project: phpseclib/phpseclib

Public Properties

Property Type Description
$bitmap integer 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.
$cipher integer Default cipher
$connectionTimeout integer 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.
$crypto object The cryptography object
$curTimeout Current Timeout
$fsock object The Socket Object
$host string Hostname
$host_key_public_exponent string Logged for debug purposes
$host_key_public_modulus string Logged for debug purposes
$identifier string The SSH identifier
$interactiveBuffer array Interactive Buffer
$log_boundary Log Boundary
$log_long_width Log Long Width
$log_short_width Log Short Width
$message_log array Message Log
$port integer Port Number
$protocol_flag_log array Protocol Flag Log
$protocol_flags array Protocol Flags
$realtime_log_file resource Real-time log file pointer
$realtime_log_size integer Real-time log file size
$realtime_log_wrap boolean Real-time log file wrap boolean
$server_identification string Server Identification
$server_key_public_exponent string Logged for debug purposes
$server_key_public_modulus string Logged for debug purposes
$supported_authentications array Logged for debug purposes
$supported_ciphers array Logged for debug purposes
$timeout Timeout

Public Methods

Method Description
__construct ( string $host, integer $port = 22, integer $timeout = 10, integer $cipher = self::CIPHER_3DES ) : SSH1 Default Constructor.
__destruct ( ) Destructor.
_append_log ( $protocol_flags, $message ) Logs data packets
_connect ( ) : boolean Connect to an SSHv1 server
_crc ( string $data ) : integer Cyclic Redundancy Check (CRC)
_define_array ( ) Define Array
_disconnect ( string $msg = 'Client Quit' ) Disconnect
_format_log ( array $message_log, array $message_number_log ) : string Formats a log for printing
_format_log_helper ( array $matches ) : string Helper function for _format_log
_get_binary_packet ( ) : array Gets Binary Packets
_initShell ( ) : boolean Creates an interactive shell
_rsa_crypt ( phpseclib\Math\BigInteger $m, array $key ) : phpseclib\Math\BigInteger RSA Encrypt
_send_binary_packet ( string $data ) : boolean Sends Binary Packets
disconnect ( ) Disconnect
exec ( string $cmd, $block = true ) : mixed Executes a command on a non-interactive shell, returns the output, and quits.
getHostKeyPublicExponent ( boolean $raw_output = false ) : string Return the host key public exponent
getHostKeyPublicModulus ( boolean $raw_output = false ) : string Return the host key public modulus
getLog ( ) : array | false | string Returns a log of the packets that have been sent and received.
getServerIdentification ( ) : string Return the server identification.
getServerKeyPublicExponent ( boolean $raw_output = false ) : string Return the server key public exponent
getServerKeyPublicModulus ( boolean $raw_output = false ) : string Return the server key public modulus
getSupportedAuthentications ( boolean $raw_output = false ) : array Return a list of authentications supported by SSH1 server.
getSupportedCiphers ( boolean $raw_output = false ) : array Return a list of ciphers supported by SSH1 server.
interactiveRead ( ) : string Returns the output of an interactive shell when no more output is available.
interactiveWrite ( string $cmd ) : boolean Inputs a command into an interactive shell.
login ( string $username, string $password = '' ) : boolean Login
read ( string $expect, integer $mode = self::READ__SIMPLE ) : boolean Returns the output of an interactive shell when there's a match for $expect
setTimeout ( mixed $timeout ) Set Timeout
write ( string $cmd ) : boolean Inputs a command into an interactive shell.

Method Details

__construct() public method

Connects to an SSHv1 server
public __construct ( string $host, integer $port = 22, integer $timeout = 10, integer $cipher = self::CIPHER_3DES ) : SSH1
$host string
$port integer
$timeout integer
$cipher integer
return SSH1

__destruct() public method

Will be called, automatically, if you're supporting just PHP5. If you're supporting PHP4, you'll need to call disconnect().
public __destruct ( )

_append_log() public method

Makes sure that only the last 1MB worth of packets will be logged
public _append_log ( $protocol_flags, $message )

_connect() public method

Connect to an SSHv1 server
public _connect ( ) : boolean
return boolean

_crc() public method

PHP's crc32 function is implemented slightly differently than the one that SSH v1 uses, so we've reimplemented it. A more detailed discussion of the differences can be found after $crc_lookup_table's initialization.
See also: self::_get_binary_packet()
See also: self::_send_binary_packet()
public _crc ( string $data ) : integer
$data string
return integer

_define_array() public method

Takes any number of arrays whose indices are integers and whose values are strings and defines a bunch of named constants from it, using the value as the name of the constant and the index as the value of the constant. If any of the constants that would be defined already exists, none of the constants will be defined.
public _define_array ( )

_disconnect() public method

Disconnect
public _disconnect ( string $msg = 'Client Quit' )
$msg string

_format_log() public method

Formats a log for printing
public _format_log ( array $message_log, array $message_number_log ) : string
$message_log array
$message_number_log array
return string

_format_log_helper() public method

For use with preg_replace_callback()
public _format_log_helper ( array $matches ) : string
$matches array
return string

_get_binary_packet() public method

See 'The Binary Packet Protocol' of protocol-1.5.txt for more info. Also, this function could be improved upon by adding detection for the following exploit: http://www.securiteam.com/securitynews/5LP042K3FY.html
See also: self::_send_binary_packet()
public _get_binary_packet ( ) : array
return array

_initShell() public method

Creates an interactive shell
See also: self::interactiveRead()
See also: self::interactiveWrite()
public _initShell ( ) : boolean
return boolean

_rsa_crypt() public method

Returns mod(pow($m, $e), $n), where $n should be the product of two (large) primes $p and $q and where $e should be a number with the property that gcd($e, ($p - 1) * ($q - 1)) == 1. Could just make anything that calls this call modexp, instead, but I think this makes things clearer, maybe...
See also: self::__construct()
public _rsa_crypt ( phpseclib\Math\BigInteger $m, array $key ) : phpseclib\Math\BigInteger
$m phpseclib\Math\BigInteger
$key array
return phpseclib\Math\BigInteger

_send_binary_packet() public method

Returns true on success, false on failure.
See also: self::_get_binary_packet()
public _send_binary_packet ( string $data ) : boolean
$data string
return boolean

disconnect() public method

Disconnect
public disconnect ( )

exec() public method

An SSH1 server will close the connection after a command has been executed on a non-interactive shell. SSH2 servers don't, however, this isn't an SSH2 client. The way this works, on the server, is by initiating a shell with the -s option, as discussed in the following links: {@link http://www.faqs.org/docs/bashman/bashref_65.html http://www.faqs.org/docs/bashman/bashref_65.html} {@link http://www.faqs.org/docs/bashman/bashref_62.html http://www.faqs.org/docs/bashman/bashref_62.html} To execute further commands, a new \phpseclib\Net\SSH1 object will need to be created. Returns false on failure and the output, otherwise.
See also: self::interactiveRead()
See also: self::interactiveWrite()
public exec ( string $cmd, $block = true ) : mixed
$cmd string
return mixed

getHostKeyPublicExponent() public method

Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, the raw bytes. This behavior is similar to PHP's md5() function.
public getHostKeyPublicExponent ( boolean $raw_output = false ) : string
$raw_output boolean
return string

getHostKeyPublicModulus() public method

Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, the raw bytes. This behavior is similar to PHP's md5() function.
public getHostKeyPublicModulus ( boolean $raw_output = false ) : string
$raw_output boolean
return string

getLog() public method

Returns a string if NET_SSH1_LOGGING == self::LOG_COMPLEX, an array if NET_SSH1_LOGGING == self::LOG_SIMPLE and false if !defined('NET_SSH1_LOGGING')
public getLog ( ) : array | false | string
return array | false | string

getServerIdentification() public method

Return the server identification.
public getServerIdentification ( ) : string
return string

getServerKeyPublicExponent() public method

Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, the raw bytes. This behavior is similar to PHP's md5() function.
public getServerKeyPublicExponent ( boolean $raw_output = false ) : string
$raw_output boolean
return string

getServerKeyPublicModulus() public method

Returns, by default, the base-10 representation. If $raw_output is set to true, returns, instead, the raw bytes. This behavior is similar to PHP's md5() function.
public getServerKeyPublicModulus ( boolean $raw_output = false ) : string
$raw_output boolean
return string

getSupportedAuthentications() public method

Just because a cipher is supported by an SSH1 server doesn't mean it's supported by this library. If $raw_output is set to true, returns, instead, an array of constants. ie. instead of array('password authentication'), you'll get array(self::AUTH_PASSWORD).
public getSupportedAuthentications ( boolean $raw_output = false ) : array
$raw_output boolean
return array

getSupportedCiphers() public method

Just because a cipher is supported by an SSH1 server doesn't mean it's supported by this library. If $raw_output is set to true, returns, instead, an array of constants. ie. instead of array('Triple-DES in CBC mode'), you'll get array(self::CIPHER_3DES).
public getSupportedCiphers ( boolean $raw_output = false ) : array
$raw_output boolean
return array

interactiveRead() public method

Requires PHP 4.3.0 or later due to the use of the stream_select() function. If you see stuff like "^[[00m", you're seeing ANSI escape codes. According to {@link http://support.microsoft.com/kb/101875 How to Enable ANSI.SYS in a Command Window}, "Windows NT does not support ANSI escape sequences in Win32 Console applications", so if you're a Windows user, there's not going to be much recourse.
See also: self::interactiveRead()
public interactiveRead ( ) : string
return string

interactiveWrite() public method

Inputs a command into an interactive shell.
See also: self::interactiveRead()
public interactiveWrite ( string $cmd ) : boolean
$cmd string
return boolean

login() public method

Login
public login ( string $username, string $password = '' ) : boolean
$username string
$password string
return boolean

read() public method

$expect can take the form of a string literal or, if $mode == self::READ__REGEX, a regular expression.
See also: self::write()
public read ( string $expect, integer $mode = self::READ__SIMPLE ) : boolean
$expect string
$mode integer
return boolean

setTimeout() public method

$ssh->exec('ping 127.0.0.1'); on a Linux host will never return and will run indefinitely. setTimeout() makes it so it'll timeout. Setting $timeout to false or 0 will mean there is no timeout.
public setTimeout ( mixed $timeout )
$timeout mixed

write() public method

Inputs a command into an interactive shell.
See also: self::interactiveWrite()
public write ( string $cmd ) : boolean
$cmd string
return boolean

Property Details

$bitmap public_oe property

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.
public int $bitmap
return integer

$cipher public_oe property

Default cipher
See also: self::__construct()
See also: self::_connect()
public int $cipher
return integer

$connectionTimeout public_oe property

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.
See also: self::__construct()
See also: self::_connect()
public int $connectionTimeout
return integer

$crypto public_oe property

The cryptography object
public object $crypto
return object

$curTimeout public_oe property

Current Timeout
See also: self::_get_channel_packet()
public $curTimeout

$fsock public_oe property

The Socket Object
public object $fsock
return object

$host public_oe property

Hostname
See also: self::__construct()
See also: self::_connect()
public string $host
return string

$host_key_public_exponent public_oe property

Logged for debug purposes
See also: self::getHostKeyPublicExponent()
public string $host_key_public_exponent
return string

$host_key_public_modulus public_oe property

Logged for debug purposes
See also: self::getHostKeyPublicModulus()
public string $host_key_public_modulus
return string

$identifier public_oe property

The SSH identifier
public string $identifier
return string

$interactiveBuffer public_oe property

Interactive Buffer
See also: self::read()
public array $interactiveBuffer
return array

$log_boundary public_oe property

Log Boundary
See also: self::_format_log()
public $log_boundary

$log_long_width public_oe property

Log Long Width
See also: self::_format_log()
public $log_long_width

$log_short_width public_oe property

Log Short Width
See also: self::_format_log()
public $log_short_width

$message_log public_oe property

Message Log
See also: self::getLog()
public array $message_log
return array

$port public_oe property

Port Number
See also: self::__construct()
See also: self::_connect()
public int $port
return integer

$protocol_flag_log public_oe property

Protocol Flag Log
See also: self::getLog()
public array $protocol_flag_log
return array

$protocol_flags public_oe property

Protocol Flags
See also: self::__construct()
public array $protocol_flags
return array

$realtime_log_file public_oe property

Real-time log file pointer
See also: self::_append_log()
public resource $realtime_log_file
return resource

$realtime_log_size public_oe property

Real-time log file size
See also: self::_append_log()
public int $realtime_log_size
return integer

$realtime_log_wrap public_oe property

Real-time log file wrap boolean
See also: self::_append_log()
public bool $realtime_log_wrap
return boolean

$server_identification public_oe property

Server Identification
See also: self::getServerIdentification()
public string $server_identification
return string

$server_key_public_exponent public_oe property

Logged for debug purposes
See also: self::getServerKeyPublicExponent()
public string $server_key_public_exponent
return string

$server_key_public_modulus public_oe property

Logged for debug purposes
See also: self::getServerKeyPublicModulus()
public string $server_key_public_modulus
return string

$supported_authentications public_oe property

Logged for debug purposes
See also: self::getSupportedAuthentications()
public array $supported_authentications
return array

$supported_ciphers public_oe property

Logged for debug purposes
See also: self::getSupportedCiphers()
public array $supported_ciphers
return array

$timeout public_oe property

Timeout
See also: self::setTimeout()
public $timeout