RUBY 38
Proxy.txt Guest on 8th August 2020 04:12:56 AM
  1. #!/usr/bin/perl
  2.  
  3. # Anonymous proxy validation
  4. # by Pepelux - pepelux[at]enye-sec.org
  5. #
  6. # It checks a proxy list and save valid anonymous proxies
  7. #
  8. # Usage: perl proxy.pl [-p <proxy_list>] [-u <url_list>]
  9. #
  10. # You can use a file with a list of proxies, with the format:
  11. # --- proxy_file.txt ---
  12. #    IP:port
  13. #    domain:port
  14. #    IP:port
  15. #    domain:port
  16. # ------
  17. # Or you can use a file with a list of urls that shows a proxy list, with the format:
  18. # --- url_file.txt ---
  19. #    http://site.com/proxylist.txt
  20. #    http://site.com/path/proxies.txt
  21. # ------
  22.  
  23. print "\e[2J";
  24. system(($^O eq 'MSWin32') ? 'cls' : 'clear');
  25.  
  26. use warnings;
  27. use strict;
  28.  
  29. use Socket;
  30.  
  31. use LWP::UserAgent;
  32. my $ua = LWP::UserAgent->new() or die;
  33. my @proxys = ();
  34. my @urls = ();
  35.  
  36. sub load_data {
  37.    my $file = shift;
  38.    my $lin = 0;
  39.    @proxys = ();
  40.    
  41.    if (-e $file) {
  42.       syswrite(STDOUT, "[+] Loading data file ... ", 30);
  43.       open FDATOS, $file;
  44.      
  45.       while(<FDATOS>) {
  46.          chop();
  47.          
  48.          if ($_ =~ /:/) {
  49.             my @datos = split(/:/, $_);
  50.             my $ipaddr = gethostbyname($datos[0]);
  51.             if($ipaddr) {
  52.                my $ip = inet_ntoa($ipaddr);
  53.                push(@proxys, $ip.":".$datos[1]);
  54.             }
  55.          }
  56.       }
  57.      
  58.       close FDATOS;
  59.      
  60.       syswrite(STDOUT, "Ok\n", 5);
  61.       syswrite(STDOUT, "    [-] Loaded " . $#proxys . " proxies\n", 40);
  62.    }
  63.    else {
  64.       syswrite(STDOUT, "[-] Configuration file doesn't found: '".$file."'\n\n",80);
  65.       exit;
  66.    }
  67. }
  68.  
  69. sub load_urls {
  70.    my $file = "proxy_urls.txt";
  71.    my $lin = 0;
  72.    
  73.    if (-e $file) {
  74.       syswrite(STDOUT, "[+] Loading URLs file ... ", 26);
  75.  
  76.       open FDATOS, $file;
  77.       while(<FDATOS>) { push(@urls, $_); }
  78.       close FDATOS;
  79.      
  80.       syswrite(STDOUT, "Ok\n", 5);
  81.    }
  82.    else {
  83.       syswrite(STDOUT, "[-] proxy_urls.txt doesn't found: '".$file."'\n\n",80);
  84.       exit;
  85.    }
  86. }
  87.  
  88. sub load_proxy {
  89.    my $url = shift;
  90.    @proxys = ();
  91.    
  92.    chop($url);
  93.    syswrite(STDOUT, "[+] Downloading data from: " . $url . "\n", 150);
  94.    
  95.    $ua->proxy('http', "");
  96.    $ua->timeout(10);
  97.    my $request = HTTP::Request->new(GET => $url);
  98.    my $response = $ua->request($request);
  99.    my $content = $response->content();
  100.    
  101.    @proxys = split(/\n/, $content);
  102.    syswrite(STDOUT, "    [-] Loaded " . $#proxys . " proxies\n", 40);
  103. }
  104.  
  105. sub check {
  106.    my $content = shift;
  107.    my $ip_real = shift;
  108.    my $proxy = shift;
  109.    my $timeout = shift;
  110.    my $ini = index($content, "Tu IP real es")+17;
  111.    
  112.    if ($ini > 17) {
  113.       $content = substr($content, $ini, length($content)-$ini);
  114.       my $fin = index($content, "</b>");
  115.       $content = substr($content, 0, $fin);
  116.      
  117.       if ($content =~ /$ip_real/) {
  118.          syswrite(STDOUT, "    [-] Not an anonymous proxy\n", 25);
  119.          return 1;
  120.       }
  121.       else {
  122.          syswrite(STDOUT, "    [-] Response: " . $content . " (timeout = " . $timeout . ")\n", 115);
  123.          syswrite(FLOG, $proxy . "\n", 25);
  124.          return 1;
  125.       }
  126.    }
  127.    else {
  128.       syswrite(STDOUT, "    [-] Response error (timeout = " . $timeout . ")\n", 40);
  129.       return 0;
  130.    }
  131. }
  132.  
  133. sub check_file {
  134.    my $web_url = shift;
  135.    my $ip_real = shift;
  136.    my $type = shift;
  137.    
  138.    open(FLOG, ">log.txt");
  139.    
  140.    my $total = $#proxys;
  141.    
  142.    for (my $i=0; $i <= $total; $i++) {
  143.       my $proxy_url = $proxys[$i];
  144.      
  145.       if ($type == 1) {
  146.          chop($proxy_url);
  147.          $proxy_url =~ s/\s*//g;
  148.          $proxy_url =~ s/\n//g;
  149.       }
  150.      
  151.       my $tmp = $proxy_url;
  152.       syswrite(STDOUT, "[+] Analyzing " . $proxy_url . " ...\n", 40);
  153.       $proxy_url = "http://".$proxy_url if ($proxy_url !~ /^http:/);
  154.       $proxy_url = $proxy_url."/" if ($proxy_url !~ /\/$/);
  155.      
  156.       $ua->proxy('http', $proxy_url); ## proxy_url contains something like http://10.10.10.10:1234/
  157.       $ua->timeout(10);
  158.      
  159.       my $request = HTTP::Request->new(GET => $web_url);
  160.       my $response = $ua->request($request);
  161.       my $content = $response->content();
  162.  
  163.       if (check($content, $ip_real, $tmp, 10) == 0) { # 1st try
  164.          $ua->timeout(15);
  165.          my $request = HTTP::Request->new(GET => $web_url);
  166.          my $response = $ua->request($request);
  167.          my $content = $response->content();
  168.          
  169.          if (check($content, $ip_real, $tmp, 15) == 0) { # 2sd try
  170.             $ua->timeout(20);
  171.             my $request = HTTP::Request->new(GET => $web_url);
  172.             my $response = $ua->request($request);
  173.             my $content = $response->content();
  174.            
  175.             check($content, $ip_real, $tmp, 20); # 3th try
  176.          }
  177.       }
  178.    }
  179.    
  180.    close(FLOG);
  181. }
  182.  
  183.  
  184. my ($type, $pfile) = @ARGV ;
  185.  
  186. if ($#ARGV != 1 || ($type !~ /-p/ &&  $type !~ /-u/)) {
  187.    print "\nUsage: perl $0 [-p <proxy_list>] [-u <url_list>]\n";
  188.    print "\n   [-] -u <url_list> load urls from the file and check each proxy\n";
  189.    print "\n   [-] -p <proxy_list> load proxies to check from the file\n";
  190.    print "                       file format must be: xx.xx.xx.xx:yyyy\n";
  191.    print "                                            host.com:yyyy\n";
  192.    print "\n   [-] Examples: perl $0 -p my_proxies.txt\n";
  193.    print "                 perl $0 -u urls_with_proxies.txt\n\n";
  194.    exit 1;
  195. }
  196.  
  197. #my ($pfile) = @ARGV if ($#ARGV == 0);
  198.  
  199. my $web_url = "http://www.cualesmiip.com/";
  200.  
  201. $ua->proxy('http', "");
  202. $ua->timeout(10);
  203. my $request = HTTP::Request->new(GET => $web_url);
  204. my $response = $ua->request($request);
  205. my $content = $response->content();
  206.  
  207. my $ini = index($content, "Tu IP real es")+17;
  208. $content = substr($content, $ini, length($content)-$ini);
  209. my $fin = index($content, "</b>");
  210. $content = substr($content, 0, $fin);
  211.  
  212. $fin = index($content, "(");
  213. my $ip_real = substr($content, 0, $fin);
  214.  
  215. syswrite(STDOUT, "[+] Your real IP is: " . $ip_real . "\n", 100);
  216.  
  217. if ($type eq "-p") {
  218.    load_data($pfile);
  219.    check_file($web_url, $ip_real, 0);
  220. }
  221. else {
  222.       load_urls();
  223.      
  224.       my $total = $#urls;
  225.      
  226.       for (my $j=0; $j <= $total; $j++) {
  227.          load_proxy($urls[$j]);
  228.          check_file($web_url, $ip_real, 1);
  229.       }
  230. }
  231.  
  232. print " Log file with the valid proxies has save in 'log.txt'\n";
  233. print " -- END -- \n\n";
  234.  
  235. __END__

Paste is for source code and general debugging text.

Login or Register to edit, delete and keep track of your pastes and more.

Raw Paste

Login or Register to edit or fork this paste. It's free.