
Lo que hace basicamente es leer de un fichero (que pasamos como parametro) en el que hay una lista de proxies a testear y te dice cuales son validos, guardando en un fichero los buenos
El formato del fichero debe ser:
IP:puerto
host:puerto
IP:puerto
IP:puerto
host:puerto
La utilidad es obvia, coges un listado de proxies de Internet y te filtra los buenos

Código
#!/usr/bin/perl
# Anonymous proxy validation
# by Pepelux - pepelux[at]enye-sec.org
#
# It checks a proxy list and save valid anonymous proxies
#
# Usage: perl proxy.pl [-p <proxy_list>] [-u <url_list>]
#
# You can use a file with a list of proxies, with the format:
# --- proxy_file.txt ---
# IP:port
# domain:port
# IP:port
# domain:port
# ------
# Or you can use a file with a list of urls that shows a proxy list, with the format:
# --- url_file.txt ---
# http://site.com/proxylist.txt
# http://site.com/path/proxies.txt
# ------
print "\e[2J";
system(($^O eq 'MSWin32') ? 'cls' : 'clear');
use warnings;
use strict;
use Socket;
use LWP::UserAgent;
my $ua = LWP::UserAgent->new() or die;
my @proxys = ();
my @urls = ();
sub load_data {
my $file = shift;
my $lin = 0;
@proxys = ();
if (-e $file) {
syswrite(STDOUT, "[+] Loading data file ... ", 30);
open FDATOS, $file;
while(<FDATOS>) {
chop();
if ($_ =~ /:/) {
my @datos = split(/:/, $_);
my $ipaddr = gethostbyname($datos[0]);
if($ipaddr) {
my $ip = inet_ntoa($ipaddr);
push(@proxys, $ip.":".$datos[1]);
}
}
}
close FDATOS;
syswrite(STDOUT, "Ok\n", 5);
syswrite(STDOUT, " [-] Loaded " . $#proxys . " proxies\n", 40);
}
else {
syswrite(STDOUT, "[-] Configuration file doesn't found: '".$file."'\n\n",80);
exit;
}
}
sub load_urls {
my $file = "proxy_urls.txt";
my $lin = 0;
if (-e $file) {
syswrite(STDOUT, "[+] Loading URLs file ... ", 26);
open FDATOS, $file;
while(<FDATOS>) { push(@urls, $_); }
close FDATOS;
syswrite(STDOUT, "Ok\n", 5);
}
else {
syswrite(STDOUT, "[-] proxy_urls.txt doesn't found: '".$file."'\n\n",80);
exit;
}
}
sub load_proxy {
my $url = shift;
@proxys = ();
chop($url);
syswrite(STDOUT, "[+] Downloading data from: " . $url . "\n", 150);
$ua->proxy('http', "");
$ua->timeout(10);
my $request = HTTP::Request->new(GET => $url);
my $response = $ua->request($request);
my $content = $response->content();
@proxys = split(/\n/, $content);
syswrite(STDOUT, " [-] Loaded " . $#proxys . " proxies\n", 40);
}
sub check {
my $content = shift;
my $ip_real = shift;
my $proxy = shift;
my $timeout = shift;
my $ini = index($content, "Tu IP real es")+17;
if ($ini > 17) {
$content = substr($content, $ini, length($content)-$ini);
my $fin = index($content, "</b>");
$content = substr($content, 0, $fin);
if ($content =~ /$ip_real/) {
syswrite(STDOUT, " [-] Not an anonymous proxy\n", 25);
return 1;
}
else {
syswrite(STDOUT, " [-] Response: " . $content . " (timeout = " . $timeout . ")\n", 115);
syswrite(FLOG, $proxy . "\n", 25);
return 1;
}
}
else {
syswrite(STDOUT, " [-] Response error (timeout = " . $timeout . ")\n", 40);
return 0;
}
}
sub check_file {
my $web_url = shift;
my $ip_real = shift;
my $type = shift;
open(FLOG, ">log.txt");
my $total = $#proxys;
for (my $i=0; $i <= $total; $i++) {
my $proxy_url = $proxys[$i];
if ($type == 1) {
chop($proxy_url);
$proxy_url =~ s/\s*//g;
$proxy_url =~ s/\n//g;
}
my $tmp = $proxy_url;
syswrite(STDOUT, "[+] Analyzing " . $proxy_url . " ...\n", 40);
$proxy_url = "http://".$proxy_url if ($proxy_url !~ /^http:/);
$proxy_url = $proxy_url."/" if ($proxy_url !~ /\/$/);
$ua->proxy('http', $proxy_url); ## proxy_url contains something like http://10.10.10.10:1234/
$ua->timeout(10);
my $request = HTTP::Request->new(GET => $web_url);
my $response = $ua->request($request);
my $content = $response->content();
if (check($content, $ip_real, $tmp, 10) == 0) { # 1st try
$ua->timeout(15);
my $request = HTTP::Request->new(GET => $web_url);
my $response = $ua->request($request);
my $content = $response->content();
if (check($content, $ip_real, $tmp, 15) == 0) { # 2sd try
$ua->timeout(20);
my $request = HTTP::Request->new(GET => $web_url);
my $response = $ua->request($request);
my $content = $response->content();
check($content, $ip_real, $tmp, 20); # 3th try
}
}
}
close(FLOG);
}
my ($type, $pfile) = @ARGV ;
if ($#ARGV != 1 || ($type !~ /-p/ && $type !~ /-u/)) {
print "\nUsage: perl $0 [-p <proxy_list>] [-u <url_list>]\n";
print "\n [-] -u <url_list> load urls from the file and check each proxy\n";
print "\n [-] -p <proxy_list> load proxies to check from the file\n";
print " file format must be: xx.xx.xx.xx:yyyy\n";
print " host.com:yyyy\n";
print "\n [-] Examples: perl $0 -p my_proxies.txt\n";
print " perl $0 -u urls_with_proxies.txt\n\n";
exit 1;
}
#my ($pfile) = @ARGV if ($#ARGV == 0);
my $web_url = "http://www.cualesmiip.com/";
$ua->proxy('http', "");
$ua->timeout(10);
my $request = HTTP::Request->new(GET => $web_url);
my $response = $ua->request($request);
my $content = $response->content();
my $ini = index($content, "Tu IP real es")+17;
$content = substr($content, $ini, length($content)-$ini);
my $fin = index($content, "</b>");
$content = substr($content, 0, $fin);
$fin = index($content, "(");
my $ip_real = substr($content, 0, $fin);
syswrite(STDOUT, "[+] Your real IP is: " . $ip_real . "\n", 100);
if ($type eq "-p") {
load_data($pfile);
check_file($web_url, $ip_real, 0);
}
else {
load_urls();
my $total = $#urls;
for (my $j=0; $j <= $total; $j++) {
load_proxy($urls[$j]);
check_file($web_url, $ip_real, 1);
}
}
print " Log file with the valid proxies has save in 'log.txt'\n";
print " -- END -- \n\n";
__END__










Autor




En línea







