briandfoy / net-ssh-perl

Development on the Net::SSH::Perl module to support latest ciphers, key exchange mechanisms, etc.
Other
4 stars 1 forks source link

Hung when connecting Linux SSH servier on Windows(win7, winxp) #36

Open briandfoy opened 1 year ago

briandfoy commented 1 year ago

This ticket was imported from rt.cpan.org 67729

Steps to reproduce the problem: Run following testing script. It will hang on the lines.

Testing Scripts:

! /usr/bin/perl

use strict;
use warnings;

use Socket qw{ :crlf };
use Net::SSH::Perl;

my $ssh = Net::SSH::Perl->new(
                              "192.168.22.170",
                              (
                               debug => 1,
                               protocol => '2,1',
                              )
                             );

$ssh->login("root", "rootpassword");

my ($o, $e, $rv) = $ssh->cmd("ls", "\n");

print STDERR "\$o = $o\n";
print STDERR "\$e = $e\n";
print STDERR "\$rv = $rv\n";

Trace of the testing script:

    alphatan-x200: Reading configuration data C:\Users\alphatan/.ssh/config
    alphatan-x200: Reading configuration data /etc/ssh_config
    alphatan-x200: Connecting to sdf.org, port 22.
    alphatan-x200: Remote protocol version 1.99, remote software version
OpenSSH_5.8
    alphatan-x200: Net::SSH::Perl Version 1.34, protocol version 2.0.
    alphatan-x200: No compat match: OpenSSH_5.8.
    alphatan-x200: Connection established.
    alphatan-x200: Sent key-exchange init (KEXINIT), wait response.
    alphatan-x200: Algorithms, c->s: 3des-cbc hmac-sha1 none
    alphatan-x200: Algorithms, s->c: 3des-cbc hmac-sha1 none
    alphatan-x200: Entering Diffie-Hellman Group 1 key exchange.
    alphatan-x200: Sent DH public key, waiting for reply.
    alphatan-x200: Received host key, type 'ssh-dss'.
    alphatan-x200: Host 'sdf.org' is known and matches the host key.
    alphatan-x200: Computing shared secret key.
    alphatan-x200: Verifying server signature.
    alphatan-x200: Waiting for NEWKEYS message.
    alphatan-x200: Send NEWKEYS.
    alphatan-x200: Enabling encryption/MAC/compression.
    alphatan-x200: Sending request for user-authentication service.
    alphatan-x200: Service accepted: ssh-userauth.
    alphatan-x200: Trying empty user-authentication request.
    alphatan-x200: Authentication methods that can continue:
publickey,password,keyboard-interactive,hostbased.
    alphatan-x200: Next method to try is publickey.
    alphatan-x200: Next method to try is password.
    alphatan-x200: Trying password authentication.
    alphatan-x200: Login completed, opening dummy shell channel.
    alphatan-x200: channel 0: new [client-session]
    alphatan-x200: Requesting channel_open for channel 0.
    alphatan-x200: channel 0: open confirm rwindow 0 rmax 32768
    alphatan-x200: Got channel open confirmation, requesting shell.
    alphatan-x200: Requesting service shell on channel 0.
    alphatan-x200: channel 1: new [client-session]
    alphatan-x200: Requesting channel_open for channel 1.
    alphatan-x200: Entering interactive session.
    alphatan-x200: Sending command: ls
    alphatan-x200: Sending command: ls
    alphatan-x200: Requesting service exec on channel 1.
    alphatan-x200: channel 1: send eof
    alphatan-x200: channel 1: open confirm rwindow 2097151 rmax 32768

Guess on the reason(May not be right, but just a hint): It may be caused by the CRLF notions on socket operations. After creating a new socket, call 'binmode(SOCK, ":raw:perlio")' to make it raw mode and setting 'local $/=CRLF;' before reading and append $CRLF as line separator;

Distribution Name and Version: Net::SSH::Perl 1.34

Perl Version osname=MSWin32, osvers=5.1, archname=MSWin32-x86-multi-thread uname='Win32 strawberryperl 5.12.2.0 #1 Fri Nov 5 05:17:27 2010 i386'

Operating System vendor and version WinXP and Win7