[ Index ]

PHP Cross Reference of DokuWiki

title

Body

[close]

/vendor/phpseclib/phpseclib/phpseclib/Net/ -> SSH1.php (summary)

Pure-PHP implementation of SSHv1. PHP version 5

Author: Jim Wigginton
Copyright: 2007 Jim Wigginton
License: http://www.opensource.org/licenses/mit-license.html MIT License
Link: http://phpseclib.sourceforge.net
File Size: 1662 lines (53 kb)
Included or required:0 times
Referenced: 0 times
Includes or requires: 0 files

Defines 1 class

SSH1:: (30 methods):
  __construct()
  _connect()
  login()
  setTimeout()
  exec()
  _initShell()
  write()
  read()
  interactiveWrite()
  interactiveRead()
  disconnect()
  __destruct()
  _disconnect()
  _get_binary_packet()
  _send_binary_packet()
  _crc()
  _string_shift()
  _rsa_crypt()
  _define_array()
  getLog()
  _format_log()
  _format_log_helper()
  getServerKeyPublicExponent()
  getServerKeyPublicModulus()
  getHostKeyPublicExponent()
  getHostKeyPublicModulus()
  getSupportedCiphers()
  getSupportedAuthentications()
  getServerIdentification()
  _append_log()


Class: SSH1  - X-Ref

Pure-PHP implementation of SSHv1.

__construct($host, $port = 22, $timeout = 10, $cipher = self::CIPHER_3DES)   X-Ref
Default Constructor.

Connects to an SSHv1 server

return: \phpseclib\Net\SSH1
param: string $host
param: int $port
param: int $timeout
param: int $cipher

_connect()   X-Ref
Connect to an SSHv1 server

return: bool

login($username, $password = '')   X-Ref
Login

return: bool
param: string $username
param: string $password

setTimeout($timeout)   X-Ref
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.

param: mixed $timeout

exec($cmd, $block = true)   X-Ref
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 \phpseclib\Net\SSH1 object will need to be created.

Returns false on failure and the output, otherwise.

see: self::interactiveRead()
see: self::interactiveWrite()
return: mixed
param: string $cmd
param: bool $block

_initShell()   X-Ref
Creates an interactive shell

see: self::interactiveRead()
see: self::interactiveWrite()
return: bool

write($cmd)   X-Ref
Inputs a command into an interactive shell.

see: self::interactiveWrite()
return: bool
param: string $cmd

read($expect, $mode = self::READ_SIMPLE)   X-Ref
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.

see: self::write()
return: bool
param: string $expect
param: int $mode

interactiveWrite($cmd)   X-Ref
Inputs a command into an interactive shell.

see: self::interactiveRead()
return: bool
param: string $cmd

interactiveRead()   X-Ref
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.

see: self::interactiveRead()
return: string

disconnect()   X-Ref
Disconnect


__destruct()   X-Ref
Destructor.

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


_disconnect($msg = 'Client Quit')   X-Ref
Disconnect

param: string $msg

_get_binary_packet()   X-Ref
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

see: self::_send_binary_packet()
return: array

_send_binary_packet($data)   X-Ref
Sends Binary Packets

Returns true on success, false on failure.

see: self::_get_binary_packet()
return: bool
param: string $data

_crc($data)   X-Ref
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.

see: self::_get_binary_packet()
see: self::_send_binary_packet()
return: int
param: string $data

_string_shift(&$string, $index = 1)   X-Ref
String Shift

Inspired by array_shift

return: string
param: string $string
param: int $index

_rsa_crypt($m, $key)   X-Ref
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...

see: self::__construct()
return: BigInteger
param: BigInteger $m
param: array $key

_define_array()   X-Ref
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()   X-Ref
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')

return: array|false|string

_format_log($message_log, $message_number_log)   X-Ref
Formats a log for printing

return: string
param: array $message_log
param: array $message_number_log

_format_log_helper($matches)   X-Ref
Helper function for _format_log

For use with preg_replace_callback()

return: string
param: array $matches

getServerKeyPublicExponent($raw_output = false)   X-Ref
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.

return: string
param: bool $raw_output

getServerKeyPublicModulus($raw_output = false)   X-Ref
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.

return: string
param: bool $raw_output

getHostKeyPublicExponent($raw_output = false)   X-Ref
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.

return: string
param: bool $raw_output

getHostKeyPublicModulus($raw_output = false)   X-Ref
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.

return: string
param: bool $raw_output

getSupportedCiphers($raw_output = false)   X-Ref
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).

return: array
param: bool $raw_output

getSupportedAuthentications($raw_output = false)   X-Ref
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).

return: array
param: bool $raw_output

getServerIdentification()   X-Ref
Return the server identification.

return: string

_append_log($protocol_flags, $message)   X-Ref
Logs data packets

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

param: int $protocol_flags
param: string $message