Home: Perl Programming Help: Beginner:
Net::SSH::Perl ( Complex Password Fails? )



ezilagel
Novice

Oct 31, 2012, 10:01 AM


Views: 4821
Net::SSH::Perl ( Complex Password Fails? )

I'm attempting to write a script that logins via ssh and provides an output of a command. However, it seems that when I try to login using a complex password, it fails to authenticate. Here is an example...


The below will fail to authenticate.
If I change the password on the remote user to simple word or a word with numbers it works fine.

Any idea?


Code
#!/usr/bin/perl 

use Net::SSH::Perl;

my $host = 'x.x.x.x';
my $user = 'user';
my $password = 'P@ssw@rd!';

#-- set up a new connection
my $ssh = Net::SSH::Perl->new($host);
#-- authenticate
$ssh->login($user, $password);
#-- execute the command
my($stdout, $stderr, $exit) = $ssh->cmd("uname -a");
print "$stdout\n";


Thanks.


Edit: Output of running the script when failing..

Permission denied at script.pl line 12

(This post was edited by ezilagel on Oct 31, 2012, 12:09 PM)


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:28 AM


Views: 4812
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )

Which line is 12, the $ssh->login statement or the $ssh->cmd statement?

Enable debug and then post the complete message.


(This post was edited by FishMonger on Oct 31, 2012, 11:28 AM)


ezilagel
Novice

Oct 31, 2012, 11:43 AM


Views: 4807
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )

$ssh->login($user, $password);


Its not accepting the password because of the @.
Not sure how to use @ symbols in the pasword when using SSH in perl.

If I change the user password on the remote server to something like " newpass1 " it works. It just fails with the special characters.


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:48 AM


Views: 4805
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )

Are you using single quotes or double quotes around the password?

If you're using double quotes, then that would be the problem, because they enable variable interpolation and the @ symbol denotes a perl array. Use single quotes when you don't need/want interpolation.


ezilagel
Novice

Oct 31, 2012, 11:49 AM


Views: 4803
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )

I used single quotes. You can see it on my code in the first post.


FishMonger
Veteran / Moderator

Oct 31, 2012, 11:55 AM


Views: 4800
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )

Please enable debug as I previously requested and post the complete output.


ezilagel
Novice

Oct 31, 2012, 12:06 PM


Views: 4795
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )


Code
$ perl script.pl  
Permission denied at script.pl line 12 (#1)
(F) The setuid emulator in suidperl decided you were up to no good.

Uncaught exception from user code:
Permission denied at script.pl line 12
at /usr/local/share/perl5/Net/SSH/Perl.pm line 255
Net::SSH::Perl::fatal_disconnect('Net::SSH::Perl::SSH2=HASH(0x14d4d48)', 'Permission denied') called at /usr/local/share/perl5/Net/SSH/Perl/SSH2.pm line 69
Net::SSH::Perl::SSH2::login('Net::SSH::Perl::SSH2=HASH(0x14d4d48)', 'user', 'proper password displayed') called at script.pl line 12



(This post was edited by ezilagel on Oct 31, 2012, 12:08 PM)


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:08 PM


Views: 4791
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )

Are you able to connect from the command line using the same password?


ezilagel
Novice

Oct 31, 2012, 12:09 PM


Views: 4789
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )

Yes.


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:34 PM


Views: 4784
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )

Is the setuid bit set on the script?

Do you have root access and if so, do you get the same error when running the script as root?


ezilagel
Novice

Oct 31, 2012, 12:49 PM


Views: 4780
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )

Nothing set in the script.

If I execute the script with root privileges, it has the same error.

Been doing reading, it seems to be an issue with @ in the password. Can't figure out how to pass it to the ssh function in perl properly. Will update if I find something. The error is simply stating the password is not working. When it passes the password, its missing characters because of the @ symbols.


FishMonger
Veteran / Moderator

Oct 31, 2012, 12:58 PM


Views: 4778
Re: [ezilagel] Net::SSH::Perl ( Complex Password Fails? )


Quote
When it passes the password, its missing characters because of the @ symbols.

Since you're using single quotes that should not happen, unless the module is passing it thru eval before passing it to ssh.

I no longer have this module installed, but it sounds like this might be a bug in the module.

The normal recommendation by most would be to use the Net::SSH2 module instead. It is faster, and does not suffer from the enormous amount of dependencies.

http://search.cpan.org/~rkitover/Net-SSH2-0.45/lib/Net/SSH2.pm


ezilagel
Novice

Oct 31, 2012, 1:03 PM


Views: 4776
Re: [FishMonger] Net::SSH::Perl ( Complex Password Fails? )

Thanks for you help.

Unfortunately, it fails using Net::SSH2 module as well. It was actually the first script I wrote. I resorted to Net::SSH::Perl after trying other examples I found online. They all resulted the same. If the user has an @ symbol in the required password, it fails to authenticate.

Anyways, I appreciate you looking into this for me.

Edit: I'm actually thinking it might have to do with the double @ and !. (the password in the first post) I tried a password with just one @ and it seemed to work. However unfortunately for my use, the passwords are more complicated.


(This post was edited by ezilagel on Oct 31, 2012, 1:09 PM)