RE: [Ssh-sftp-perl-users] Interfacing with network appliance through ssh
Brought to you by:
dbrobins
From: Matthew J. S. <vag...@ya...> - 2006-03-23 14:52:40
|
If I use Data::Dumper to view the buffer, I see that what gets returned is an already failed authentication attempt. Is there anything else I should check? Thanks, Matt my $i = 0; $ssh->register_handler("stdout", sub { $i++; my($channel, $buffer) = @_; print Dumper $buffer; my $str = $buffer->bytes; my $getsrt = $buffer->get_str; print "\nSTR $i: $str\nEND\n\n"; if ($str =~ /Username: $/) { print "USER $i\n"; $channel->send_data("$user\n"); } elsif ($str =~ /Password/i) { print "\nPASSWORD $i\n"; $channel->send_data("$pw"); } }); my ($stdout, $stderr, $exit) = $ssh->cmd($user); Output: Logging In $VAR1 = bless( { '_get_mp_int' => sub { "DUMMY" }, '_put_mp_int' => sub { "DUMMY" }, 'buf' => 'Welcome to Webstream Server Username: ', 'offset' => 0 }, 'Net::SSH::Perl::Buffer' ); STR 1: Welcome to Webstream Server Username: END USER 1 $VAR1 = bless( { '_get_mp_int' => sub { "DUMMY" }, '_put_mp_int' => sub { "DUMMY" }, 'buf' => 'Password: Could not read password. Authenticating [username2]..... Authentication Failed. Good bye. [0x9] ', 'offset' => 0 }, 'Net::SSH::Perl::Buffer' ); STR 2: Password: Could not read password. Authenticating [username2]..... Authentication Failed. Good bye. [0x9] END PASSWORD 2 EXIT 255 --- Eric Langheinrich <er...@er...> wrote: > What happens if instead of: > > $ssh->register_handler("stdout", sub { > my($channel, $buffer) = @_; > my $str = $buffer->bytes; > print "\nSTR: $str\nEND\n\n"; > > if ($str =~ /Username: $/) { > print "USER2\n"; > $channel->send_data("$user\n$pw\n"); > } > > elsif ($str =~ /Password/i) { > print "\nPASSWORD2\n"; > $channel->send_data($pw,"\n"); > } > > You use: > > $ssh->register_handler("stdout", sub { > my($channel, $buffer) = @_; > my $str = $buffer->bytes; > print "\nSTR: $str\nEND\n\n"; > > if ($str =~ /Username: $/) { > print "USER2\n"; > $channel->send_data("$user"); > } > > elsif ($str =~ /Password/i) { > print "\nPASSWORD2\n"; > $channel->send_data($pw,"\n"); > } > > > -----Original Message----- > > From: > ssh...@li... > > > [mailto:ssh...@li...] > On > > Behalf Of Matthew J. Salerno > > Sent: Wednesday, March 22, 2006 10:24 AM > > To: Eric Langheinrich; > ssh...@li... > > Subject: RE: [Ssh-sftp-perl-users] Interfacing > with network > > appliance through ssh > > > > What really confuses me, is when I am printing my > $str = > > $buffer->bytes; > > > > When I print print "STR: $str\nEND"; looking for > the username > > prompt, it looks normal, I get: > > > > STR: Welcome to Raritan Dominion Server > > > > Username: > > END > > > > > > But when I print "STR: $str\nEND"; looking for the > password > > prompt, I get: > > > > STR: Password: > > Could not read password. > > Authenticating []..... > > Authentication Failed. Good bye. [0x9] > > > > END > > > > > > I'm not sure why the buffer would contain failed > attempts. > > Shouldn't it just contain the Passowrd: > > line? > > > > > > > > --- Eric Langheinrich <net...@er...> > > wrote: > > > > > Wouldn't it just be simpler to use public key > auth? > > > Do you really want to > > > have scripts with your passwords hard coded? > > > > > > Have you tried doing the login as a single step, > like so: > > > $ssh->login($user, $pass); > > > > > > Here's a sample of one I have working using > public > > > key: > > > > > > #!/usr/bin/perl > > > > > > Use strict; > > > Use Net::SSH::Perl; > > > My @ident = ("/home/user/.ssh/id_dsa"); my > %params = ( > > > protocol => 2, > > > interactive => 0, > > > identity_files => [@ident], > > > debug => 0, > > > options => [ > > > "BatchMode yes", > > > "AuthenticationSuccessMsg no", > > > "ForwardX11 no", > > > "ForwardAgent no" > > > ] > > > ); > > > > > > my $server = $ARGV[0]; > > > &sshconnect($server); > > > > > > my ($stdout, $stderr, $exit) = $ssh->cmd("ls"); > > > > > > print "$stdout\n"; > > > > > > if (! $ssh) { > > > print "Unable to establish ssh > connection > > > to: $server\n"; > > > } else { > > > print "Successfully established ssh > connection to: > > $server\n"; > > > } > > > > > > sub sshconnect { > > > my $server = $_[0]; > > > our $ssh = > Net::SSH::Perl->new("$server", %params); > > > $ssh->login("user"); > > > } > > > > > > Here is an example using username/password > login: > > > > > > #/usr/bin/perl > > > > > > use strict; > > > use Net::SSH::Perl; > > > use vars qw($ssh); > > > > > > > > > my %params = ( > > > protocol => 2, > > > interactive => 0, > > > debug => 0, > > > options => [ > > > "BatchMode yes", > > > "AuthenticationSuccessMsg no", > > > "ForwardX11 no", > > > "ForwardAgent no" > > > ] > > > ); > > > > > > my $pass = "password"; > > > > > > my $server = $ARGV[0]; > > > &sshconnect($server); > > > my ($stdout, $stderr, $exit) = $ssh->cmd("ls"); > print > > "$stdout\n"; if > > > (! $ssh) { > > > print "Unable to establish ssh > connection > > > to: $server\n"; > > > } else { > > > print "Successfully established ssh > connection to: > > $server\n"; > > > } > > > > > > sub sshconnect { > > > my $server = $_[0]; > > > our $ssh = > Net::SSH::Perl->new("$server", %params); > > > $ssh->login("user", $pass); > > > } > > > > > > > > > Hope this helps. > > > > > > > > > > -----Original Message----- > > > > From: > > > ssh...@li... > > > > > > > > > > [mailto:ssh...@li...] > > > On > > > > Behalf Of Matthew J. Salerno > > > > Sent: Wednesday, March 22, 2006 8:55 AM > > > > To: ssh...@li... > > > > Subject: [Ssh-sftp-perl-users] Interfacing > with > > > network > > > > appliance through ssh > > > > > > > > I have been going nuts trying to get this to > work. > > > > > > > Any help is appreciated. > > > > > > > > > > > > I need to automate the process of logging in > to a > > > network > > > > appliance and executing a few commands. The > > > network > > > > appliance uses: OpenSSH 3.8.1 > > > > > > > > The system I am executing from is using: > > > > Redhat Linux > > > > Net::SSH::Perl 1.30 > > > > Perl 5.8.5 > > > > > > > > Here is the login process, step-by-step: > > > > # ssh username1@10.10.10.15 > > > > > > > > Then I get prompted for another username as > > > expected. > > > > > > > > Welcome to Webstream Server > > > > > > > > Username: <Enter Username> > > > > > > > > Get prompted for > > > > Password: <Enter Password> > > > > > > > > This is where I am stuck. I have been working > on > > > the login > > > > process for a few days now, and I still cant > pass > > > the server > > > > the password. I can easily get to the point > where > > > it prompts > > > > for the password, but it does not work. Any > help > > > would be > > > > greatly appreciated. > > > > Here is what I have so far: > > > > > > > > #!/usr/bin/perl -w > > > > use strict; > > > > use Net::SSH::Perl; > > > > > > > > my %params; > > > > $params{"debug"} = 0; > > > > $params{"port"} = 22; > > > > $params{"protocol"} = 2; > > > > $params{"interactive"} = 0; > > > > $params{"compression"} = 0; > > > > $params{"PreferredAuthentications"} = > 'password'; > > > > $params{"PubkeyAuthentication"} = 'no'; > > $params{"RSAAuthentication"} > > > > = 'no'; > > > $params{"use_pty"} = 0; > > > > > > > > my $host = "10.10.10.15"; > > > > my $ruser = "username1"; > > > > my $user = 'username2'; > > > > my $pw = 'mypassword'; > > > > > > > > my $ssh = new Net::SSH::Perl($host, %params) > || > > > > die "Cannot Connect to system $! > $@\n"; > > > > > > > > print "Logging In\n"; > > > > $ssh->login($ruser) || die "Cannot Login $! > $@\n"; > > > > > > > > $ssh->register_handler("stdout", sub { > > > > my($channel, $buffer) = @_; > > > > my $str = $buffer->bytes; > > > > print "\nSTR: $str\nEND\n\n"; > > > > > > > > if ($str =~ /Username: $/) { > > > > print "USER2\n"; > > > > $channel->send_data("$user\n$pw\n"); > > > > } > > > > > > > > elsif ($str =~ /Password/i) { > > > > print "\nPASSWORD2\n"; > > > > $channel->send_data($pw,"\n"); > > > > } > > > > }); > > > > > > > > my ($stdout, $stderr, $exit) = > $ssh->cmd($user); > > > > > > > > print "\n\nSTDOUT - $stdout\n" if $stdout; > print > > > "STDERR - > > > > $stderr\n" if $stderr; print "EXIT $exit\n" if > > > $exit; > > > > > > > > exit; > > > > > > > > ---------- > > > > The results are: > > > > > > > > Logging In > > > > > > > > STR: Welcome to Webstream Server > > > > > > > > Username: > > > > END > > > > > > > > USER2 > > > > > > > > STR: Password: > > > > Could not read password. > > > > Authenticating [username2]..... > > > > Authentication Failed. Good bye. [0x9] > > > > > > > > END > > > > > > > > PASSWORD2 > > > > EXIT 255 > > > > > > > > > __________________________________________________ > > > > Do You Yahoo!? > > > > Tired of spam? Yahoo! Mail has the best spam > > > protection > > > > around http://mail.yahoo.com > > > > > > > > > > > > > > > > > > ------------------------------------------------------- > > > > This SF.Net email is sponsored by xPML, a > > > groundbreaking > > > > scripting language > > > > that extends applications into web and mobile > > > media. Attend > > > > the live webcast > > > > and join the prime developer group breaking > into > > > this new > > > > coding territory! > > > > > > > > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720& > > > dat=121642 > > > > > _______________________________________________ > > > > Ssh-sftp-perl-users mailing list > > > > Ssh...@li... > > > > > > > > > > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > > > > > > > > > > > > > > __________________________________________________ > > Do You Yahoo!? > > Tired of spam? Yahoo! Mail has the best spam > protection > > around http://mail.yahoo.com > > > > > > > ------------------------------------------------------- > > This SF.Net email is sponsored by xPML, a > groundbreaking > > scripting language > > that extends applications into web and mobile > media. Attend > > the live webcast > > and join the prime developer group breaking into > this new > > coding territory! > > > http://sel.as-us.falkag.net/sel?cmd=lnk&kid=110944&bid=241720& > dat=121642 > > _______________________________________________ > > Ssh-sftp-perl-users mailing list > > Ssh...@li... > > > https://lists.sourceforge.net/lists/listinfo/ssh-sftp-perl-users > > > > __________________________________________________ Do You Yahoo!? Tired of spam? Yahoo! Mail has the best spam protection around http://mail.yahoo.com |