#!/usr/bin/perl -w #Proxyfinder v1.0 #by laramies_at_edge-security.com #TODO: Customize for other proxy pages, GET test via lwp/proxy, randomize proxys countrys. # check the timeout when connected. #use strict; use IO::Socket; use URI; use LWP::Simple qw/$ua get/; if (@ARGV<3){ print "\nUsage: proxyfinder.pl source needed outputfile [--full]\n"; print "where:\n\n"; print "-source: where to get the lists, [samair or multiproxy].\n"; print "-needed: number of working proxies needed.\n"; print "-outputfile: to store the results.\n"; print "-full: when this is enabled, it will check that the valid proxys permit the CONNECT method.\n"; print "\nExample: proxyfinder.pl samair results.txt 5\n"; exit; } $i=0; $hitcounter=0; $source=$ARGV[0]; $needed=$ARGV[1]; $sale=$ARGV[2]; print "Proxys needed: $needed\n"; open (OUT, ">$sale"); #######################proxy lists############################ if ($source eq 'samair'){ for ($y=2;$y<5;$y++){ my $content = get "http://www.samair.ru/proxy/proxy-0$y.htm"; $content=~s/\n//g; @res= ($content=~/
.*?<\/pre>/gim);
			@list= ($res[0]=~/(([0-9.]*):([0-9]*))/g);
			}
}elsif ($source eq 'multiproxy')
{
	my $content = get "http://www.multiproxy.org/txt_anon/proxy.txt";
	@list= ($content=~/(([0-9.a-zA-Z]*):([0-9]*))/g);
}else{print "Source not available\n";exit;}


##################Socket Test##################################
		for ($d=3;$d < $#list && $hitcounter < $needed;$d=$d+3){
			my $remote = IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>$list[$d-2],PeerPort =>$list[$d-1],Timeout=>"2");
			unless ($remote)
   				{
   				#warn "$list[$d] Fail \n";
   	    			next;
				}	
	 		#Change www.afip.gov.ar with a webpage with a fix ip number, a web like www.google.com could fail#	
			print $remote "GET http://www.afip.gov.ar HTTP/1.0\r\n\r\n\r\n\r\n";
				while (<$remote>){
					if(/200 /)
					{
						print "$list[$d] GET supported!\n";
						$hitcounter++;
						
						last;
					}
				}
			
			$listo[$i]=$d;
	 		$i++;
	 		print OUT "$list[$d]\n";
 	 		$remote->autoflush(1);
	 		close ($remote);	

		}

######################################Methods test##############
	if (@ARGV < 4){
	exit;	
	}
	else
	{
	if ($ARGV[3] eq '--full'){
		print "###################################\n";
		print "Checking Connect method\n";
		sleep(15);
			for ($u=0;$u<$i;$u++){
			my $remota = IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>$list[$listo[$u]-2],PeerPort =>$list[$listo[$u]-1],Timeout =>"2");
				unless($remota)
					{
					warn "Can't connect socket, maybe timeout error?\n";
					next; 
					}
			print $remota "CONNECT $list[$listo[$u]-2]:$list[$listo[$u]-1] HTTP/1.1\r\n\r\n";
			while (<$remota>)
			{
				if(/200 /)
				{
				print "$list[$listo[$u]] CONNECT supported!\n";
				last;
				}
			}
		$remota->autoflush(1);
		close $remota;	
		}
	}
}