| Server IP : 67.20.76.190 / Your IP : 216.73.216.4 Web Server : Apache System : Linux host2028.hostmonster.com 5.14.0-611.47.1.el9_7.x86_64 #1 SMP PREEMPT_DYNAMIC Wed Apr 8 20:00:39 EDT 2026 x86_64 User : jegocaco ( 1556) PHP Version : 8.2.32 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : OFF | Sudo : ON | Pkexec : ON Directory : /usr/share/doc/perl-Net-OpenSSH/examples/ |
Upload File : |
#!/usr/bin/perl
use strict;
use warnings;
use Net::OpenSSH;
use Expect;
select STDOUT; $| = 1;
select STDERR; $| = 1;
my $password = $ARGV[0];
my $timeout = 20;
my $debug = 0;
my $ssh = Net::OpenSSH->new('test@127.0.0.1', password => $password);
# my ($pty, $pid) = $ssh->open2pty("sudo cat /etc/shadow")
# After a successful sudo operation, it doesn't request the password
# again until some time after, handling this undeterministic behaviour
# is a pain in the ass, so we just clear any cached credentials
# calling "sudo -k" first as follows:
my ($pty, $pid) = $ssh->open2pty("sudo -k; sudo cat /etc/shadow")
or die "open2pty failed: " . $ssh->error . "\n";
my $expect = Expect->init($pty);
$expect->raw_pty(1);
$debug and $expect->log_user(1);
$debug and print "waiting for password prompt\n";
$expect->expect($timeout, ':')
or die "expect failed\n";
$debug and print "prompt seen\n";
$expect->send("$password\n");
$debug and print "password sent\n";
$expect->expect($timeout, "\n")
or die "bad password\n";
$debug and print "password ok\n";
while(<$pty>) {
print "$. $_"
}