Net::SSH::Perl

Discussion in 'Perl' started by get-fuzzy, Sep 5, 2003.

  1. get-fuzzy

    get-fuzzy Guest

    Sorry, I cant comment on the perl as yet but, are you not in the least bit
    worried that someone might hack into your base system - get the unencrypted
    password (old password) then log on - using ssh to the other box ?

    ssh is not 100% flawless

    From a security point of view it is a nightmare, from a SA point of view - I
    can see where you are coming from !

    Just curious is all
    "blob" <> wrote in message news:...
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws
    >
     
    get-fuzzy, Sep 5, 2003
    #1
    1. Advertising

  2. get-fuzzy

    blob Guest

    Hi all,

    Below is my script that will be used to connect to a remote host and
    change my password automatically:

    ===========================================
    #!/usr/bin/perl


    use strict();
    use Net::SSH::perl;


    $user="jaws";
    $pass="password";
    $host="xxx.xxx.xxx.xxx";
    $old_password="password";
    $new_password="newpass";


    my $ssh = Net::SSH::perl->new($host,debug=>1,use_pty=>1);
    $ssh->login($user, $pass);


    $ssh->register_handler("stderr", sub {
    my($channel, $buffer) = @_;
    my $str = $buffer->bytes;


    if ($str eq "Enter login password: ") {
    $channel->send_data($old_password);
    }


    elsif ($str eq "New password: ") {
    $channel->send_data($new_password);
    }

    elsif ($str eq "Re-enter new password: ") {
    $channel->send_data($new_password);
    }
    });
    $ssh->cmd('passwd');
    ==========================================

    After running the program, my password didnt changed I was still able to
    connect using the old password.

    Does anybody has an idea what's missing or wrong with my script?

    Thanks.

    Jaws
     
    blob, Sep 5, 2003
    #2
    1. Advertising

  3. On Fri, 05 Sep 2003 10:07:49 -0800
    blob <> wrote:
    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    >
    > change my password automatically:

    <sniped for brevity>
    >
    > After running the program, my password didnt changed I was still
    > able to connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?


    Just a suggestion - you may wish to use one of the Expect modules for
    what you're doing. Expect is, IMHO, better suited for this task. And
    in true Perl fashion, there is a module to interact with Expect :)

    HTH

    --
    Jim

    Copyright notice: all code written by the author in this post is
    released under the GPL. http://www.gnu.org/licenses/gpl.txt
    for more information.

    a fortune quote ...
    Hlade's Law: If you have a difficult task, give it to a lazy
    person -- they will find an easier way to do it.
     
    James Willmore, Sep 6, 2003
    #3
  4. get-fuzzy

    Nico Coetzee Guest

    On Fri, 05 Sep 2003 10:07:49 -0800, blob wrote:

    > Hi all,
    >
    > Below is my script that will be used to connect to a remote host and
    > change my password automatically:
    >
    > ===========================================
    > #!/usr/bin/perl
    >
    >
    > use strict();
    > use Net::SSH::perl;
    >
    >
    > $user="jaws";
    > $pass="password";
    > $host="xxx.xxx.xxx.xxx";
    > $old_password="password";
    > $new_password="newpass";
    >
    >
    > my $ssh = Net::SSH::perl->new($host,debug=>1,use_pty=>1);
    > $ssh->login($user, $pass);
    >
    >
    > $ssh->register_handler("stderr", sub {
    > my($channel, $buffer) = @_;
    > my $str = $buffer->bytes;
    >
    >
    > if ($str eq "Enter login password: ") {
    > $channel->send_data($old_password);
    > }
    >
    >
    > elsif ($str eq "New password: ") {
    > $channel->send_data($new_password);
    > }
    >
    > elsif ($str eq "Re-enter new password: ") {
    > $channel->send_data($new_password);
    > }
    > });
    > $ssh->cmd('passwd');
    > ==========================================
    >
    > After running the program, my password didnt changed I was still able to
    > connect using the old password.
    >
    > Does anybody has an idea what's missing or wrong with my script?
    >
    > Thanks.
    >
    > Jaws


    Instead of waiting for the exact string, why not use regular expresions,
    which might eliminate typo's. Something like:

    if ($str =~ /enter\s+login\s+password/i ) {
    $channel->send_data($old_password);
    }


    elsif ($str =~ /new\s+password/i ) {
    $channel->send_data($new_password);
    }

    elsif ($str =~ /re.enter\s+new\s+password/i ) {
    $channel->send_data($new_password);
    }

    Cheers

    --
    Nico Coetzee

    http://www.itfirms.co.za/
    http://za.pm.org/
    http://forums.databasejournal.com/

    To the systems programmer, users and applications serve only to provide a
    test load.
     
    Nico Coetzee, Sep 6, 2003
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. loial
    Replies:
    0
    Views:
    430
    loial
    Feb 3, 2009
  2. loial
    Replies:
    0
    Views:
    423
    loial
    Feb 10, 2009
  3. Tench Johnson
    Replies:
    1
    Views:
    318
    Biff Tannen
    Apr 23, 2010
  4. salamond

    net/ssh in ruby. ssh.exec fails

    salamond, Feb 17, 2011, in forum: Ruby
    Replies:
    0
    Views:
    269
    salamond
    Feb 17, 2011
  5. Replies:
    0
    Views:
    126
Loading...

Share This Page