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