HEX
Server: Apache
System: Linux br1102.hostgator.com.br 5.14.0-687.17.1.el9_8.x86_64 #1 SMP PREEMPT_DYNAMIC Mon Jun 22 07:21:26 EDT 2026 x86_64
User: rkcent87 (3754)
PHP: 8.3.32
Disabled: NONE
Upload Files
File: //usr/share/doc/perl-Net-OpenSSH/examples/login_handler.pl
#!/usr/bin/perl

# This script contains a rude implementation of a custom login handler
# for password authentication.

use strict;
use warnings;

use Net::OpenSSH;

my ($host, $user, $passwd) = @ARGV;

sub mi_login_handler {
    my ($ssh, $pty, $data) = @_;
    # print "custom login handler called!";
    my $read = sysread($pty, $$data, 1024, length $$data);
    if ($read) {
        # print "buffer: >$$data<\n";
        if ($$data =~ s/.*://s) {
            print $pty "$passwd\n";
            return 1;
        }
    }
    return 0;
}

my $ssh = Net::OpenSSH->new($host, user => $user,
                            master_opts => [-o => 'NumberOfPasswordPrompts=1',
                                            -o => 'PreferredAuthentications=keyboard-interactive,password'],
                            login_handler => \&mi_login_handler);
$ssh->error and die "Unable to connect to remote machine" . $ssh->error;
$ssh->system("ls");