lib/3rdParty/phpseclib/Net/SSH1.php

Properties

Description

Pure-PHP implementation of SSHv1.

PHP versions 4 and 5 Here's a short example of how to use this library: login('username', 'password')) { exit('Login Failed'); } echo $ssh->exec('ls -la'); ?> Here's another short example: login('username', 'password')) { exit('Login Failed'); } 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 THE SOFTWARE.

Constants

  NET_SSH1_CIPHER_NONE = 0

No encryption
Not supported.

  NET_SSH1_CIPHER_IDEA = 1

IDEA in CFB mode
Not supported.

  NET_SSH1_CIPHER_DES = 2

DES in CBC mode


  NET_SSH1_CIPHER_3DES = 3

Triple-DES in CBC mode
All implementations are required to support this

  NET_SSH1_CIPHER_BROKEN_TSS = 4

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)

  NET_SSH1_CIPHER_BLOWFISH = 6

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)

  NET_SSH1_AUTH_RHOSTS = 1




  NET_SSH1_AUTH_RSA = 2

pure RSA authentication


  NET_SSH1_AUTH_PASSWORD = 3

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

  NET_SSH1_AUTH_RHOSTS_RSA = 4




  NET_SSH1_TTY_OP_END = 0




  NET_SSH1_RESPONSE_TYPE = 1

The Response Type


  NET_SSH1_RESPONSE_DATA = 2

The Response Data


  NET_SSH1_MASK_CONSTRUCTOR = 1




  NET_SSH1_MASK_LOGIN = 2




  NET_SSH1_MASK_SHELL = 4




  NET_SSH1_LOG_SIMPLE = 1

Returns the message numbers


  NET_SSH1_LOG_COMPLEX = 2

Returns the message content


  NET_SSH1_READ_SIMPLE = 1

Returns when a string matching $expect exactly is found


  NET_SSH1_READ_REGEX = 2

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


  $value = $key




Classes

Net_SSH1

Properties

 
 
public  
0.1.0  
No 
No 

Description

Pure-PHP implementation of SSHv1.

Methods

Net_SSH1, __destruct, _crc, _define_array, _disconnect, _format_log, _get_binary_packet, _initShell, _rsa_crypt, _send_binary_packet, _string_shift, disconnect, exec, getHostKeyPublicExponent, getHostKeyPublicModulus, getLog, getServerIdentification, getServerKeyPublicExponent, getServerKeyPublicModulus, getSupportedAuthentications, getSupportedCiphers, interactiveRead, interactiveWrite, login, read, write,

Net_SSH1( String   $host,   $port = 22,   $timeout = 10,   $cipher = NET_SSH1_CIPHER_3DES, ) : \Net_SSH1

Description

Default Constructor.
Connects to an SSHv1 server

Arguments

Name Type Description Default
$host String
$port n/a 22
$timeout n/a 10
$cipher n/a NET_SSH1_CIPHER_3DES

Return value

Type Description
\Net_SSH1

Tags

Name Description
access public

__destruct( ) : n/a

Description

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

Return value

Type Description
n/a n/a

Tags

Name Description
access public

_crc( String   $data, ) : Integer

Description

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.

Arguments

Name Type Description Default
$data String

Return value

Type Description
Integer

Tags

Name Description
see
see
access private

_define_array( ) : n/a

Description

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.

Return value

Type Description
n/a n/a

Tags

Name Description
access private

_disconnect( String   $msg = 'Client Quit', ) : n/a

Description

Disconnect

Arguments

Name Type Description Default
$msg String 'Client Quit'

Return value

Type Description
n/a n/a

Tags

Name Description
access private

_format_log( Array   $message_log, Array   $message_number_log, ) : String

Description

Formats a log for printing

Arguments

Name Type Description Default
$message_log Array
$message_number_log Array

Return value

Type Description
String

Tags

Name Description
access private

_get_binary_packet( ) : Array

Description

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

Return value

Type Description
Array

Tags

Name Description
see
access private

_initShell( ) : Boolean

Description

Creates an interactive shell

Return value

Type Description
Boolean

Tags

Name Description
see
see
access private

_rsa_crypt( \Math_BigInteger   $m, Array   $key, ) : \Math_BigInteger

Description

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

Arguments

Name Type Description Default
$m \Math_BigInteger
$key Array

Return value

Type Description
\Math_BigInteger

Tags

Name Description
see
access private

_send_binary_packet( String   $data, ) : Boolean

Description

Sends Binary Packets
Returns true on success, false on failure.

Arguments

Name Type Description Default
$data String

Return value

Type Description
Boolean

Tags

Name Description
see
access private

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

Description

String Shift
Inspired by array_shift

Arguments

Name Type Description Default
$string String
$index n/a 1

Return value

Type Description
String

Tags

Name Description
access private

disconnect( ) : n/a

Description

Disconnect

Return value

Type Description
n/a n/a

Tags

Name Description
access public

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

Description

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: {@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 Net_SSH1 object will need to be created. Returns false on failure and the output, otherwise.

Arguments

Name Type Description Default
$cmd String
$block n/a true

Return value

Type Description
mixed

Tags

Name Description
see
see
access public

getHostKeyPublicExponent(   $raw_output = false, ) : String

Description

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.

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
String

Tags

Name Description
access public

getHostKeyPublicModulus(   $raw_output = false, ) : String

Description

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.

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
String

Tags

Name Description
access public

getLog( ) : String

Description

Returns a log of the packets that have been sent and received.
Returns a string if NET_SSH2_LOGGING == NET_SSH2_LOG_COMPLEX, an array if NET_SSH2_LOGGING == NET_SSH2_LOG_SIMPLE and false if !defined('NET_SSH2_LOGGING')

Return value

Type Description
String or Array

Tags

Name Description
access public

getServerIdentification( ) : String

Description

Return the server identification.

Return value

Type Description
String

Tags

Name Description
access public

getServerKeyPublicExponent(   $raw_output = false, ) : String

Description

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.

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
String

Tags

Name Description
access public

getServerKeyPublicModulus(   $raw_output = false, ) : String

Description

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.

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
String

Tags

Name Description
access public

getSupportedAuthentications(   $raw_output = false, ) : Array

Description

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

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
Array

Tags

Name Description
access public

getSupportedCiphers(   $raw_output = false, ) : Array

Description

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

Arguments

Name Type Description Default
$raw_output n/a false

Return value

Type Description
Array

Tags

Name Description
access public

interactiveRead( ) : String

Description

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

Return value

Type Description
String

Tags

Name Description
see
access public

interactiveWrite( String   $cmd, ) : Boolean

Description

Inputs a command into an interactive shell.

Arguments

Name Type Description Default
$cmd String

Return value

Type Description
Boolean

Tags

Name Description
see
access public

login( String   $username,   $password = '', ) : Boolean

Description

Login

Arguments

Name Type Description Default
$username String
$password n/a ''

Return value

Type Description
Boolean

Tags

Name Description
access public

read( String   $expect, Integer   $mode = NET_SSH1_READ_SIMPLE, ) : Boolean

Description

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 == NET_SSH1_READ_REGEX, a regular expression.

Arguments

Name Type Description Default
$expect String
$mode Integer NET_SSH1_READ_SIMPLE

Return value

Type Description
Boolean

Tags

Name Description
see
access public

write( String   $cmd, ) : Boolean

Description

Inputs a command into an interactive shell.

Arguments

Name Type Description Default
$cmd String

Return value

Type Description
Boolean

Tags

Name Description
see
access public

Properties

$bitmap, $crypto, $fsock, $host_key_public_exponent, $host_key_public_modulus, $identifier, $interactive_buffer, $message_log, $protocol_flag_log, $protocol_flags, $server_identification, $server_key_public_exponent, $server_key_public_modulus, $supported_authentications, $supported_ciphers,

Integer  public  $bitmap = 0

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.

Object  public  $crypto = false

The cryptography object


Object  public  $fsock =

The Socket Object


String  public  $host_key_public_exponent =

The Host Key Public Exponent
Logged for debug purposes

String  public  $host_key_public_modulus =

The Host Key Public Modulus
Logged for debug purposes

String  public  $identifier = 'SSH-1.5-phpseclib'

The SSH identifier


Array  public  $interactive_buffer = ''

Interactive Buffer


Array  public  $message_log = array()

Message Log


Array  public  $protocol_flag_log = array()

Protocol Flag Log


Array  public  $protocol_flags = array()

Protocol Flags


String  public  $server_identification = ''

Server Identification


String  public  $server_key_public_exponent =

The Server Key Public Exponent
Logged for debug purposes

String  public  $server_key_public_modulus =

The Server Key Public Modulus
Logged for debug purposes

Array  public  $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')

Supported Authentications
Logged for debug purposes

Array  public  $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 Ciphers
Logged for debug purposes

Documentation was generated by phpDocumentor 2.1.0 .

Namespaces

  • global

    Packages