Constants

CIPHER_NONE

CIPHER_NONE

No encryption

Not supported.

CIPHER_IDEA

CIPHER_IDEA

IDEA in CFB mode

Not supported.

CIPHER_DES

CIPHER_DES

DES in CBC mode

CIPHER_3DES

CIPHER_3DES

Triple-DES in CBC mode

All implementations are required to support this

CIPHER_BROKEN_TSS

CIPHER_BROKEN_TSS

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)

CIPHER_BLOWFISH

CIPHER_BLOWFISH

Blowfish

Not supported nor is it defined in the official SSH1 specs. OpenSSH, however, defines it (see cipher.h) and uses it (see cipher.c)

AUTH_RHOSTS

AUTH_RHOSTS

.rhosts or /etc/hosts.equiv

AUTH_RSA

AUTH_RSA

pure RSA authentication

AUTH_PASSWORD

AUTH_PASSWORD

password authentication

This is the only method that is supported by this library.

AUTH_RHOSTS_RSA

AUTH_RHOSTS_RSA

.rhosts with RSA host authentication

TTY_OP_END

TTY_OP_END

RESPONSE_TYPE

RESPONSE_TYPE

The Response Type

RESPONSE_DATA

RESPONSE_DATA

The Response Data

MASK_CONSTRUCTOR

MASK_CONSTRUCTOR

MASK_CONNECTED

MASK_CONNECTED

MASK_LOGIN

MASK_LOGIN

MASK_SHELL

MASK_SHELL

LOG_SIMPLE

LOG_SIMPLE

Returns the message numbers

LOG_COMPLEX

LOG_COMPLEX

Returns the message content

LOG_REALTIME

LOG_REALTIME

Outputs the content real-time

LOG_REALTIME_FILE

LOG_REALTIME_FILE

Dumps the content real-time to a file

READ_SIMPLE

READ_SIMPLE

Returns when a string matching $expect exactly is found

READ_REGEX

READ_REGEX

Returns when a string matching the regular expression $expect is found

Properties

$identifier

$identifier : string

The SSH identifier

Type

string

$fsock

$fsock : object

The Socket Object

Type

object

$crypto

$crypto : object

The cryptography object

Type

object

$bitmap

$bitmap : integer

Execution Bitmap

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.

Type

integer

$server_key_public_exponent

$server_key_public_exponent : string

The Server Key Public Exponent

Logged for debug purposes

Type

string

$server_key_public_modulus

$server_key_public_modulus : string

The Server Key Public Modulus

Logged for debug purposes

Type

string

$host_key_public_exponent

$host_key_public_exponent : string

The Host Key Public Exponent

Logged for debug purposes

Type

string

$host_key_public_modulus

$host_key_public_modulus : string

The Host Key Public Modulus

Logged for debug purposes

Type

string

$supported_ciphers

$supported_ciphers : array

Supported Ciphers

Logged for debug purposes

Type

array

$supported_authentications

$supported_authentications : array

Supported Authentications

Logged for debug purposes

Type

array

$server_identification

$server_identification : string

Server Identification

Type

string

$protocol_flags

$protocol_flags : array

Protocol Flags

Type

array

$protocol_flag_log

$protocol_flag_log : array

Protocol Flag Log

Type

array

$message_log

$message_log : array

Message Log

Type

array

$realtime_log_file

$realtime_log_file : resource

Real-time log file pointer

Type

resource

$realtime_log_size

$realtime_log_size : integer

Real-time log file size

Type

integer

$realtime_log_wrap

$realtime_log_wrap : boolean

Real-time log file wrap boolean

Type

boolean

$interactiveBuffer

$interactiveBuffer : array

Interactive Buffer

Type

array

$timeout

$timeout : 

Timeout

Type

$curTimeout

$curTimeout : 

Current Timeout

Type

$log_boundary

$log_boundary : 

Log Boundary

Type

$log_long_width

$log_long_width : 

Log Long Width

Type

$log_short_width

$log_short_width : 

Log Short Width

Type

$host

$host : string

Hostname

Type

string

$port

$port : integer

Port Number

Type

integer

$connectionTimeout

$connectionTimeout : integer

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.

Type

integer

$cipher

$cipher : integer

Default cipher

Type

integer

Methods

__construct()

__construct(string  $host, integer  $port = 22, integer  $timeout = 10, integer  $cipher = self::CIPHER_3DES) : \phpseclib\Net\SSH1

Default Constructor.

Connects to an SSHv1 server

Parameters

string $host
integer $port
integer $timeout
integer $cipher

Returns

\phpseclib\Net\SSH1

_connect()

_connect() : boolean

Connect to an SSHv1 server

Returns

boolean

login()

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

Login

Parameters

string $username
string $password

Returns

boolean

setTimeout()

setTimeout(mixed  $timeout) 

Set Timeout

$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.

Parameters

mixed $timeout

exec()

exec(string  $cmd,   $block = true) : mixed

Executes a command on a non-interactive shell, returns the output, and quits.

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:

http://www.faqs.org/docs/bashman/bashref_65.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.

Parameters

string $cmd
$block

Returns

mixed

_initShell()

_initShell() : boolean

Creates an interactive shell

Returns

boolean

write()

write(string  $cmd) : boolean

Inputs a command into an interactive shell.

Parameters

string $cmd

Returns

boolean

read()

read(string  $expect, integer  $mode = self::READ_SIMPLE) : boolean

Returns the output of an interactive shell when there's a match for $expect

$expect can take the form of a string literal or, if $mode == self::READ_REGEX, a regular expression.

Parameters

string $expect
integer $mode

Returns

boolean

interactiveWrite()

interactiveWrite(string  $cmd) : boolean

Inputs a command into an interactive shell.

Parameters

string $cmd

Returns

boolean

interactiveRead()

interactiveRead() : string

Returns the output of an interactive shell when no more output is available.

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 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.

Returns

string

disconnect()

disconnect() 

Disconnect

__destruct()

__destruct() 

Destructor.

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

_disconnect()

_disconnect(string  $msg = 'Client Quit') 

Disconnect

Parameters

string $msg

_get_binary_packet()

_get_binary_packet() : array

Gets Binary Packets

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

Returns

array

_send_binary_packet()

_send_binary_packet(string  $data) : boolean

Sends Binary Packets

Returns true on success, false on failure.

Parameters

string $data

Returns

boolean

_crc()

_crc(string  $data) : integer

Cyclic Redundancy Check (CRC)

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.

Parameters

string $data

Returns

integer

_string_shift()

_string_shift(string  $string, integer  $index = 1) : string

String Shift

Inspired by array_shift

Parameters

string $string
integer $index

Returns

string

_rsa_crypt()

_rsa_crypt(\phpseclib\Math\BigInteger  $m, array  $key) : \phpseclib\Math\BigInteger

RSA Encrypt

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...

Parameters

\phpseclib\Math\BigInteger $m
array $key

Returns

\phpseclib\Math\BigInteger

_define_array()

_define_array() 

Define Array

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.

getLog()

getLog() : array|false|string

Returns a log of the packets that have been sent and received.

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')

Returns

array|false|string

_format_log()

_format_log(array  $message_log, array  $message_number_log) : string

Formats a log for printing

Parameters

array $message_log
array $message_number_log

Returns

string

_format_log_helper()

_format_log_helper(array  $matches) : string

Helper function for _format_log

For use with preg_replace_callback()

Parameters

array $matches

Returns

string

getServerKeyPublicExponent()

getServerKeyPublicExponent(boolean  $raw_output = false) : string

Return the server key public exponent

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.

Parameters

boolean $raw_output

Returns

string

getServerKeyPublicModulus()

getServerKeyPublicModulus(boolean  $raw_output = false) : string

Return the server key public modulus

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.

Parameters

boolean $raw_output

Returns

string

getHostKeyPublicExponent()

getHostKeyPublicExponent(boolean  $raw_output = false) : string

Return the host key public exponent

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.

Parameters

boolean $raw_output

Returns

string

getHostKeyPublicModulus()

getHostKeyPublicModulus(boolean  $raw_output = false) : string

Return the host key public modulus

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.

Parameters

boolean $raw_output

Returns

string

getSupportedCiphers()

getSupportedCiphers(boolean  $raw_output = false) : array

Return a list of ciphers supported by SSH1 server.

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).

Parameters

boolean $raw_output

Returns

array

getSupportedAuthentications()

getSupportedAuthentications(boolean  $raw_output = false) : array

Return a list of authentications supported by SSH1 server.

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).

Parameters

boolean $raw_output

Returns

array

getServerIdentification()

getServerIdentification() : string

Return the server identification.

Returns

string

_append_log()

_append_log(  $protocol_flags,   $message) 

Logs data packets

Makes sure that only the last 1MB worth of packets will be logged

Parameters

$protocol_flags
$message