socks checker

Discussion in 'PHP' started by Mescalin, 27 Feb 2008.

  1. Mescalin

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

    Joined:
    4 Jul 2007
    Messages:
    37
    Likes Received:
    27
    Reputations:
    -8
    сабж ищу,может кто поможет желательно на php =)
     
  2. Flame of Soul

    Flame of Soul Elder - Старейшина

    Joined:
    25 May 2007
    Messages:
    185
    Likes Received:
    146
    Reputations:
    45
    прости не совсем понимаю вопрос(( тебе надо проверить запущен socks в системе, или тебе нужен скрипт управления socks-ом?

    если первое то вот скрипт для проверки статуса демонов, работающих на Linux сервере.
    PHP:
    <?php 
    function checkd($daemon,$name) { 
      
    $ps ="ps ax | grep $daemon | wc -l"
      
    $origps exec($ps); 
      
    $minone $origps-2
      if (
    $minone<1) { 
          
    $dataps "only [ $minone ] daemon for [ $daemon ] <br>[ $name ] TOTALY DOWN<br><hr>"
          } 
      if (
    $minone==1) { 
          
    $dataps "<font color=blue>up</font> only with [ $minone ] [ $daemon ] daemon<br><hr>"
          } 
      if (
    $minone>1) { 
          
    $dataps "<font color=blue>up</font> with [ $minone ] [ $daemon ] daemons<br>"
          } 
          return 
    $dataps
    }
    echo 
    checkd("socks","socks daemon"); 
    echo 
    checkd("mysqld","mysql daemon"); 
    echo 
    checkd("httpd","httpd daemon"); 
    ?> 
     
  3. lsass.exe

    lsass.exe Elder - Старейшина

    Joined:
    5 Aug 2007
    Messages:
    156
    Likes Received:
    161
    Reputations:
    24
    ему нужен скрипт, которому скармливаешь список соксов и который проверит их на валид.

    По сабжу, тему поднималась не раз, юзай поиск.
     
  4. a1ex

    a1ex Banned

    Joined:
    11 Oct 2006
    Messages:
    517
    Likes Received:
    130
    Reputations:
    -13
    1. Определяет тип прокси (SOCKS4/SOCKS5)
    2. Пытается проломится на него в гугл, принтит, если прокси валидный( читайте публичный), при остальных "ошибках"(таких как запрос авторизации, идента, GSSAPI авторизация итд) не принтит прокси.
    Юзать: ./socks.pl list.txt , где list.txt - файл с соксамив формате ип:порт

    Code:
    #!perl 
    # Simple SOCKS(4/5) sorter and checker 
    # Author: biophreak (s-teals.org) 
    # Todo: print results to text files, use threads 
    use warnings; 
    use strict; 
    use Socket; 
    use IO::Handle; 
    my $DEBUG = 0; 
    my $sockslist = shift || die '[ERROR] Specify sockslist!'; 
    (open S, $sockslist and my @socks = <S> and close S) 
    or die "Cannot open file $sockslist: $!\n"; 
    my %SOCKS4_CONNECT_RESPONSES = ( 
    90 => "request granted", 
    91 => "request rejected or failed", 
    92 => "request rejected, ident required", 
    93 => "request rejected, ident mismatch", 
    ); 
    my %SOCKS5_METHODS = ( 
    0 => "no authentication required", 
    1 => "GSSAPI", 
    2 => "username/password", 
    255 => "no acceptable methods", 
    ); 
    my %SOCKS5_CONNECT_RESPONSES = ( 
    0 => "succeeded", 
    1 => "general SOCKS server failure", 
    2 => "connection not allowed by ruleset", 
    3 => "Network unreachable", 
    4 => "Host unreachable", 
    5 => "Connection refused", 
    6 => "TTL expired", 
    7 => "Command not supported", 
    8 => "Address type not supported", 
    ); 
    my $answer; 
    for (my $i=0; $i < scalar @socks; $i++) 
    { 
    my ($server, $port) = split(/:/, $socks[$i]); 
    chomp($server, $port); 
    socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) 
    or (print "Cannot open socket: $!\n" and exit); 
    connect(SOCK, sockaddr_in($port, inet_aton($server))) 
    or (print "Cannot connect to $server $port: $!\n" and exit); 
    SOCK->autoflush(1); 
    print SOCK pack("CCC",5,1,0); 
    sysread(SOCK,$answer,1) 
    or die "Cannot read from socket: $!\n"; 
    close SOCK; 
    if ($answer eq pack('C',0)) 
    { 
    print "$server:$port is SOCKS4/SOCKS4a proxy.\nChecking...\n"if $DEBUG == 1; 
    checkSocks4($server,$port); 
    } elsif ($answer eq pack('C',5)) 
    { 
    print "$server:$port is SOCKS5 proxy.\nChecking...\n"if $DEBUG == 1; 
    checkSocks5($server,$port); 
    } else { 
    print "$server:$port is not SOCKS4/SOCKS5 proxy\n"; 
    } 
    } 
    sub checkSocks5 
    { 
    my($server,$port) = @_; 
    my($mssg, $repcode, $repmssg); 
    socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) 
    or (print "Cannot open socket: $!\n" and return 0); 
    connect(SOCK, sockaddr_in($port, inet_aton($server))) 
    or (print "Cannot connect to $server $port: $!\n" and return 0); 
    SOCK->autoflush(1); 
    print SOCK pack("CCC", 5, 1, 0) 
    or (print "Cannot send to socket: $!\n" and return 0);; 
    sysread(SOCK,$mssg,2) 
    or (print "Cannot read from socket: $!\n" and return 0); 
    $repcode = (unpack("C*", $mssg))[1]; 
    $repmssg = $SOCKS5_METHODS{$repcode} 
    || "unknown or reserved reply code"; 
    print "$server:$port reply code = $repcode ($repmssg)\n" 
    if $DEBUG == 1; 
    # print "[ERROR] $server:$port is alive,but isn't usable: $repcode ($repmssg)\n" 
    # if $repcode != 0; 
    (return 0 and close SOCK) unless($repcode == 0); 
    print SOCK pack("CCCCa4n", 5, 1, 0, 1, inet_aton('www.ya.ru'), 80) 
    or (warn "Cannot send to socket: $!\n" and return 0);; 
    sysread(SOCK,$mssg,10) 
    or (warn "Cannot read from socket: $!\n" and return 0); 
    $repcode = (unpack("C*", $mssg))[1]; 
    $repmssg = $SOCKS5_CONNECT_RESPONSES{$repcode} 
    || "unknown or reserved reply code"; 
    print "$server:$port reply code = $repcode ($repmssg)\n" 
    if $DEBUG == 1; 
    # print "[ERROR] $server:$port is alive,but isn't usable: $repcode ($repmssg)\n" 
    # if $repcode != 0; 
    (return 0 and close SOCK) unless($repcode == 0); 
    print "$server:$port is good SOCKS5 proxy\n"; # Print to file... 
    close SOCK; 
    return 1; 
    } 
    
    sub checkSocks4 
    { 
    my($server,$port) = @_; 
    my($mssg, $repcode, $repmssg); 
    socket(SOCK, AF_INET, SOCK_STREAM, getprotobyname('tcp')) 
    or (print "Cannot open socket: $!\n" and return 0); 
    connect(SOCK, sockaddr_in($port, inet_aton($server))) 
    or (print "Cannot connect to $server $port: $!\n" and return 0); 
    SOCK->autoflush(1); 
    print SOCK pack("CCnA4x", 4, 1, 80, inet_aton('www.google.com')); 
    sysread(SOCK,$mssg,8) 
    or (print "Cannot read from socket: $!\n" and return 0); 
    $repcode = (unpack("C*", $mssg))[1]; 
    $repmssg = $SOCKS4_CONNECT_RESPONSES{$repcode} 
    || "unknown reply code"; 
    print "$server:$port reply code = $repcode ($repmssg)\n" 
    if $DEBUG == 1; 
    # print "[ERROR] $server:$port is alive,but isn't usable: $repcode ($repmssg)\n" 
    # if $repcode != 90; 
    (return 0 and close SOCK) unless ($repcode == 90); 
    print "$server:$port is good SOCKS4/SOCKS4a proxy\n"; # Print to file... 
    close SOCK; 
    return 1; 
    }
    
     
  5. Mescalin

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

    Joined:
    4 Jul 2007
    Messages:
    37
    Likes Received:
    27
    Reputations:
    -8
    lsass.exe, юзал поиск по сабжу ничего ненашел,только проки чекеры :(

    a1ex, спасиб за копипаст =) это я уже видел хотелось бы на php
     
  6. a1ex

    a1ex Banned

    Joined:
    11 Oct 2006
    Messages:
    517
    Likes Received:
    130
    Reputations:
    -13
    Mescalin, а чё на perl не заюзаешь?
     
  7. t0tal

    t0tal Member

    Joined:
    30 Nov 2007
    Messages:
    12
    Likes Received:
    10
    Reputations:
    0
    Попробуй вотэтот скрипт, незнаю работает ли он вапще.
    PHP:
    <?
    /**************************************************    **************
    *                      *
    *                                                               *
    * This will perform a basic connectivity and anonymity test     *
    *                                                               *
    * Simply upload to a php enabled webserver and change the       *
    * configurable parameters below if you so desire                *
    *                                                               *
    * 2005-11-11   v0.1 - Compatible with Charon v0.5.3.5           *
    **************************************************    **************/
    ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    <head><title>Online proxy tester</title></head>
    <body bgcolor="black" text="white">

    <?php

    // Ensure that the timeouts from fsockopen don't get reported as errors (possible, depends on the php server config)
       
    error_reporting(0);
    // Limit the amount of proxies that can be tested at any one time
       
    $maximum_proxies_to_test 5;
    // Enter a password (if required) to protect the page
       
    $password '';

    // Actual proxyjudge part of the page
       
    function return_env_variables()
       {
          echo 
    '<pre>'."\n";
          foreach (
    $_SERVER as $header => $value )
          {
            if ((
    strpos($header 'REMOTE')!== false || strpos($header 'HTTP')!== false || strpos($header 'REQUEST')!== false) && ( strpos($header 'HTTP_HOST') !== 0))
            {
            echo 
    $header.' = '.$value."\n";
            }
          }
          echo 
    '</pre>';
       }

    // Function to go away and get the page (calls through the proxy back to itself)
       
    function get_judge_page($proxy)
       {
       
    // Depending on the server environment, this timeout setting may not be available.
          
    $timeout 15;
          
    $proxy_cont '';
          list(
    $proxy_host$proxy_port) = explode(":"$proxy);
          
    $proxy_fp fsockopen($proxy_host$proxy_port$errornumber$errorstring$timeout);
          if (
    $proxy_fp)
          {
             
    stream_set_timeout($proxy_fp$timeout);
             
    fputs($proxy_fp"GET " $_SERVER['SCRIPT_NAME'] . "?test HTTP/1.0\r\nHost: " $_SERVER['SERVER_NAME'] . "\r\n\r\n");
             while(!
    feof($proxy_fp))
             {
                   
    $proxy_cont .= fread($proxy_fp,4096);
             }
             
    fclose($proxy_fp);
             
    $proxy_cont substr($proxy_contstrpos($proxy_cont,"\r\n\r\n")+4);
          }
          return 
    $proxy_cont;
       }

    // Check for the control string to see if it's a valid fetch of the judge
       
    function check_valid_judge_response($page)
       {
          if(
    strlen($page) < 5)
             return 
    false;
          return 
    strpos($page'REMOTE_ADDR') !== false;
       }

    // Check for the IP addresses
       
    function check_anonymity($page)
       {
          if(
    strpos($page$_SERVER['LOCAL_ADDR']) !== false)
             return 
    false;
          return 
    true;
       }

    // Takes and tests a proxy
    // 0 - Bad proxy
    // 1 - Good (non anon) proxy
    // 2 - Good (anonymous) proxy
       
    function test_proxy($proxy)
       {
          
    $page get_judge_page($proxy);
          if(!
    check_valid_judge_response($page))
             return 
    0;
          if(!
    check_anonymity($page))
             return 
    1;
          return 
    2;
       }

    ////////// Main Page ////////////

    // If this is a judge request, just return the environmental variables
       
    if(getenv('QUERY_STRING') == "test")
       {
          
    return_env_variables();
       }
    // Else check whether we have been passed a list of proxies to test or not
    // Should really use $_POST but it's been left as $HTTP_POST_VARS for older versions of php (3.x)
       
    elseif( (isset($HTTP_POST_VARS['action']) && $HTTP_POST_VARS['action'] === 'fred') &&
               (isset(
    $HTTP_POST_VARS['proxies']) && $HTTP_POST_VARS['proxies'] != '') &&
               ( (
    strlen($password) == 0) || (isset($HTTP_POST_VARS['password']) && $HTTP_POST_VARS['password'] === $password) ))
       {
          
    $proxies explode("\n"str_replace("\r"""$HTTP_POST_VARS['proxies']), $maximum_proxies_to_test 1);

       
    // Set the overall time limit for the page execution to 10 mins
          
    set_time_limit(600);

       
    // Set up some arrays to hold the results
          
    $anon_proxies = array();
          
    $nonanon_proxies = array();
          
    $bad_proxies = array();

       
    // Loop through and test the proxies
          
    for($thisproxy 0$thisproxy < ($maximum_proxies_to_test count($proxies) ? count($proxies) : $maximum_proxies_to_test); $thisproxy += 1)
          {
             echo 
    'Testing ' $proxies[$thisproxy] . ' .....';
             
    flush();
             switch(
    test_proxy($proxies[$thisproxy]))
             {
                case 
    2:
                  echo 
    '.. Anon<br>' "\n";
                   
    $anon_proxies[count($anon_proxies)] = $proxies[$thisproxy];
                   break;
                case 
    1:
                  echo 
    '.. Non anon<br>' "\n";
                   
    $nonanon_proxies[count($nonanon_proxies)] = $proxies[$thisproxy];
                   break;
                case 
    0:
                  echo 
    '.. Dead<br>' "\n";
                   
    $bad_proxies[count($bad_proxies)] = $proxies[$thisproxy];
                   break;
             }
          }

          echo 
    '<pre>';
          echo 
    '<br><b>Anonymous proxies</b>' "\n";
          for(
    $thisproxy 0$thisproxy count($anon_proxies); $thisproxy += 1)
             echo 
    $anon_proxies[$thisproxy] . "\n";
          echo 
    '<br><b>Non-anonymous proxies</b>' "\n";
          for(
    $thisproxy 0$thisproxy count($nonanon_proxies); $thisproxy += 1)
             echo 
    $nonanon_proxies[$thisproxy] . "\n";
          echo 
    '<br><b>Dead proxies</b>' "\n";
          for(
    $thisproxy 0$thisproxy count($bad_proxies); $thisproxy += 1)
             echo 
    $bad_proxies[$thisproxy] . "\n";
          echo 
    '</pre>';
       }
    // Just a blank call of the page - show the form for the user to fill in
       
    else
       {
          echo 
    '<h2>Online Proxy checker</h2>' "\n";
          echo 
    '<h4>(http://' $_SERVER['SERVER_NAME'] . $_SERVER['SCRIPT_NAME'] . ')</h4>' "\n";
          echo 
    'Enter up to a maximum of ' $maximum_proxies_to_test ' prox' . ($maximum_proxies_to_test == 'y' 'ies') . ' to test' "\n";
          echo 
    '<form method="POST" action="' $_SERVER['SCRIPT_NAME'] . '">' "\n";
          echo 
    '<input type="hidden" name="action" value="fred">' "\n";
          echo 
    '<textarea name="proxies" cols=35 rows=' $maximum_proxies_to_test '></textarea><br>' "\n";
          if(
    strlen($password) > 0)
             echo 
    'Password: <input type="password" name="password" size="15"><br>' "\n";
          echo 
    '<input type="submit" value="Check proxies">' "\n";
          echo 
    '</form>' "\n";
       }
    ?>
    </body>
    </html>
     
  8. Mescalin

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

    Joined:
    4 Jul 2007
    Messages:
    37
    Likes Received:
    27
    Reputations:
    -8
    t0tal, это прокси чекер,а мне нужен сокс чекер
     
  9. Sharky

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

    Joined:
    1 May 2006
    Messages:
    487
    Likes Received:
    312
    Reputations:
    46
    А разница? Работает то всё равно через сокеты
     
  10. biophreak

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

    Joined:
    3 Aug 2007
    Messages:
    348
    Likes Received:
    63
    Reputations:
    15
    Разнца большая, как минимум в том что протоколы разные ;)
     
  11. tgbhu

    tgbhu New Member

    Joined:
    27 Nov 2007
    Messages:
    0
    Likes Received:
    0
    Reputations:
    -5

    а как запускать его? скопировал этот код в файл socks.pl , соксы залил в list.txt
    запускаю socks.pl но выдает текстом код :confused:
    сорри за нубизм)
     
  12. mailbrush

    mailbrush Well-Known Member

    Joined:
    24 Jun 2008
    Messages:
    1,997
    Likes Received:
    996
    Reputations:
    155
    .pl - это некомпилируемый файл, который понимает только интерпретатор - Active Perl, к примеру.