| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | # This is proxysuite, written in GNU/PURL |
|---|
| 4 | # by Jmax, of bantown and the GNAA. |
|---|
| 5 | # It gathers and tests http proxies |
|---|
| 6 | |
|---|
| 7 | # This product is licensed under the BPL. |
|---|
| 8 | # You should have recieved a copy of the |
|---|
| 9 | # license with this program, along with |
|---|
| 10 | # the README, sockssuite.pl, sites.txt, |
|---|
| 11 | # and sockssites.txt |
|---|
| 12 | |
|---|
| 13 | # el8 tr0ll c0dez by Jmax [ BANTOWN irc.bantown.com #bantown ] [ GNAA irc.gnaa.us #gnaa ] |
|---|
| 14 | |
|---|
| 15 | use warnings; |
|---|
| 16 | use strict; |
|---|
| 17 | # for forking |
|---|
| 18 | use POSIX qw(:signal_h :sys_wait_h); |
|---|
| 19 | my ($forkcount, $pid, $dead_nigger_storage, $maxfork) = (0, undef, 0, 50); |
|---|
| 20 | $SIG{INT} = sub { kill('INT', (getpgrp(0) * -1)) && exit; }; |
|---|
| 21 | $SIG{CHLD} = sub { $dead_nigger_storage++ while(($pid = waitpid(-1, WNOHANG)) > 0); }; |
|---|
| 22 | # end |
|---|
| 23 | use LWP; |
|---|
| 24 | use IO::Handle; |
|---|
| 25 | use Getopt::Long; |
|---|
| 26 | use HTML::Form; |
|---|
| 27 | use vars qw($VERSION); |
|---|
| 28 | $VERSION = "2.5.1-http"; |
|---|
| 29 | |
|---|
| 30 | #------------------------------------------------ |
|---|
| 31 | # variables |
|---|
| 32 | #------------------------------------------------ |
|---|
| 33 | |
|---|
| 34 | # time in seconds to wait for a proxy to timeout |
|---|
| 35 | my $timeout = 2; |
|---|
| 36 | |
|---|
| 37 | # query to google for |
|---|
| 38 | my $query = "gnaa"; |
|---|
| 39 | |
|---|
| 40 | # user agent to use |
|---|
| 41 | my $agent = "JEW/Lunix FireFAKE 1.5.101"; |
|---|
| 42 | |
|---|
| 43 | #------------------------------------------------ |
|---|
| 44 | # check arguments |
|---|
| 45 | #------------------------------------------------ |
|---|
| 46 | |
|---|
| 47 | my ($gather_only, $test_only, $gather_and_test, $print_version_message, $print_help_message); |
|---|
| 48 | GetOptions('gather-only|g' => \$gather_only, |
|---|
| 49 | 'test-only|t' => \$test_only, |
|---|
| 50 | 'gather-and-test|both|b' => \$gather_and_test, |
|---|
| 51 | 'version' => \$print_version_message, |
|---|
| 52 | 'help|h|?' => \$print_help_message); |
|---|
| 53 | |
|---|
| 54 | #------------------------------------------------ |
|---|
| 55 | # determines action to perform |
|---|
| 56 | #------------------------------------------------ |
|---|
| 57 | if ($gather_only) { |
|---|
| 58 | my @URLS; |
|---|
| 59 | open (SITES, "sites.txt") or die "!!!! couldn't open sites.txt: $!"; |
|---|
| 60 | while (<SITES>) { |
|---|
| 61 | chomp; |
|---|
| 62 | next if /^\s*$/; |
|---|
| 63 | next if /^#/; |
|---|
| 64 | push(@URLS, $_); |
|---|
| 65 | } |
|---|
| 66 | close (SITES) or warn "!!!! couldn't close sites.txt: $!"; |
|---|
| 67 | my @proxies = gather_proxies(@URLS); |
|---|
| 68 | open(PROXIESFILE, ">proxies.untested.txt") or die "!!!! couldn't open proxies.untested.txt: $!\n"; |
|---|
| 69 | foreach my $proxy (@proxies) { |
|---|
| 70 | print PROXIESFILE "$proxy\n"; |
|---|
| 71 | } |
|---|
| 72 | close(PROXIESFILE) or warn "!!!! couldn't close proxies.untested.txt: $!\n"; |
|---|
| 73 | } elsif ($test_only) { |
|---|
| 74 | my @proxies; |
|---|
| 75 | open(PROXIESFILE, "proxies.untested.txt") or die "!!!! couldn't open proxies.untested.txt: $!\n"; |
|---|
| 76 | while(<PROXIESFILE>) { |
|---|
| 77 | chomp; |
|---|
| 78 | push(@proxies,$_); |
|---|
| 79 | } |
|---|
| 80 | @proxies = keys ( %{ { map { $_ => 1 } @proxies } } ); |
|---|
| 81 | my $total_uniq_proxies = @proxies; |
|---|
| 82 | print ">>>> acquired $total_uniq_proxies total unique proxies.\n"; |
|---|
| 83 | close(PROXIESFILE) or warn "!!!! couldn't close proxies.untested.txt: $!\n"; |
|---|
| 84 | test_proxies(@proxies); |
|---|
| 85 | } elsif ($gather_and_test) { |
|---|
| 86 | my @URLS; |
|---|
| 87 | open (SITES, "sites.txt") or die "!!!! couldn't open sites.txt: $!"; |
|---|
| 88 | while (<SITES>) { |
|---|
| 89 | chomp; |
|---|
| 90 | next if /^\s*$/; |
|---|
| 91 | next if /^#/; |
|---|
| 92 | push(@URLS, $_); |
|---|
| 93 | } |
|---|
| 94 | close (SITES) or warn "!!!! couldn't close sites.txt: $!"; |
|---|
| 95 | my @proxies = gather_proxies(@URLS); |
|---|
| 96 | test_proxies(@proxies); |
|---|
| 97 | } elsif ($print_help_message) { |
|---|
| 98 | print "proxysuite version $VERSION by Jmax\n". |
|---|
| 99 | "\n". |
|---|
| 100 | "\n". |
|---|
| 101 | "options:\n". |
|---|
| 102 | "\n". |
|---|
| 103 | "-g : gather proxies\n". |
|---|
| 104 | " gathers proxies from a list of sites (that have proxies in ip:port format).\n". |
|---|
| 105 | " stores the un-tested proxies in proxies.untested.txt\n". |
|---|
| 106 | "-t : test proxies\n". |
|---|
| 107 | " tests proxies from a list of proxies in ip:port format titled proxies.untested.txt\n". |
|---|
| 108 | " for speed (by GET'ing google in under $timeout seconds) and against a blacklist, and\n". |
|---|
| 109 | " stores the proxies that can POST in proxies.canpost.txt and the proxies that can only\n". |
|---|
| 110 | " GET in proxies.getonly.txt. If you do not know what GET or POST means, read the README.\n". |
|---|
| 111 | "-b : both\n". |
|---|
| 112 | " does both testing and gathering of proxies. stores proxies as with the -t flag, but does NOT\n". |
|---|
| 113 | " store the un-tested proxies.\n"; |
|---|
| 114 | } elsif ($print_version_message) { |
|---|
| 115 | print "proxysuite version $VERSION by Jmax\n"; |
|---|
| 116 | } else { |
|---|
| 117 | print "!!!! please run 'perl proxysuite.pl --help' for more information\n"; |
|---|
| 118 | } |
|---|
| 119 | |
|---|
| 120 | exit 0; |
|---|
| 121 | |
|---|
| 122 | #------------------------------------------------ |
|---|
| 123 | # subroutines |
|---|
| 124 | #------------------------------------------------ |
|---|
| 125 | |
|---|
| 126 | sub gather_proxies { |
|---|
| 127 | my @URLS = @_; |
|---|
| 128 | # create pseudo web browser |
|---|
| 129 | my $slurper = LWP::UserAgent->new; |
|---|
| 130 | $slurper->agent( $agent ); |
|---|
| 131 | $slurper->timeout( 10 ); |
|---|
| 132 | # slurp proxies from sites |
|---|
| 133 | my $total_proxies_acquired = 0; |
|---|
| 134 | my @proxies; |
|---|
| 135 | PROXYSLURP: foreach my $URL ( @URLS ) { |
|---|
| 136 | my $proxies_acquired = 0; |
|---|
| 137 | print ">>>> slurping proxies from $URL ... \n"; |
|---|
| 138 | my $response = $slurper->get( $URL ); |
|---|
| 139 | if (!($response->is_success)) { |
|---|
| 140 | print STDERR "!!!! could not slurp from $URL : " . $response->status_line . "\n"; |
|---|
| 141 | next PROXYSLURP; |
|---|
| 142 | } |
|---|
| 143 | my $content = $response->content; |
|---|
| 144 | foreach ($content =~ /(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\.){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?):\d+/ig) { |
|---|
| 145 | $proxies_acquired++; |
|---|
| 146 | chomp; |
|---|
| 147 | push(@proxies,$_); |
|---|
| 148 | } |
|---|
| 149 | print ">>>> slurped $proxies_acquired proxies from $URL \n"; |
|---|
| 150 | $total_proxies_acquired += $proxies_acquired; |
|---|
| 151 | } |
|---|
| 152 | print ">>>> slurped $total_proxies_acquired total proxies\n"; |
|---|
| 153 | print ">>>> uniq'ing ...\n"; |
|---|
| 154 | @proxies = keys ( %{ { map { $_ => 1 } @proxies } } ); |
|---|
| 155 | my $total_uniq_proxies = @proxies; |
|---|
| 156 | print ">>>> acquired $total_uniq_proxies unique proxies\n"; |
|---|
| 157 | return @proxies; |
|---|
| 158 | } |
|---|
| 159 | |
|---|
| 160 | sub test_proxies { |
|---|
| 161 | my @proxies = @_; |
|---|
| 162 | # divide array @proxies into $maxfork different seperate lists |
|---|
| 163 | my $n_per_proxies = int $#proxies / $maxfork; |
|---|
| 164 | my @array_of_proxies; |
|---|
| 165 | foreach my $current_proxy_array ( 0 .. ($maxfork - 1) ) { |
|---|
| 166 | foreach my $current_proxy_number ( 0 .. $n_per_proxies ) { |
|---|
| 167 | if (scalar @proxies == 0) { |
|---|
| 168 | last; |
|---|
| 169 | } |
|---|
| 170 | my $current_proxy = shift(@proxies); |
|---|
| 171 | $array_of_proxies[$current_proxy_array][$current_proxy_number] = $current_proxy; |
|---|
| 172 | } |
|---|
| 173 | } |
|---|
| 174 | print ">>>> initializing (forking) proxy testers\n"; |
|---|
| 175 | open(GETONLY, ">proxies.getonly.txt") or die "!!!! couldn't open proxies.getonly.txt: $!\n"; |
|---|
| 176 | open(CANPOST, ">proxies.canpost.txt") or die "!!!! couldn't open proxies.canpost.txt: $!\n"; |
|---|
| 177 | GETONLY->autoflush(1); |
|---|
| 178 | CANPOST->autoflush(1); |
|---|
| 179 | for ($forkcount = 0; $forkcount < $maxfork; $forkcount++) { # $forkcount must _not_ be local to here |
|---|
| 180 | sleep 1; # so we don't overload ourselves |
|---|
| 181 | if (!defined(my $pid = fork())) { # fork |
|---|
| 182 | die "couldn't fork: $!"; # die if fork fails |
|---|
| 183 | } elsif ($pid == 0) { # fork successful, in child, do stuff |
|---|
| 184 | test_proxy( @{ $array_of_proxies[$forkcount] } ); |
|---|
| 185 | sleep 1; |
|---|
| 186 | exit 0; # kills child |
|---|
| 187 | } else { # this is the parent |
|---|
| 188 | } |
|---|
| 189 | } |
|---|
| 190 | sleep while ($dead_nigger_storage < $maxfork); |
|---|
| 191 | close(GETONLY) or warn "!!!! couldn't close proxies.getonly.txt: $!\n"; |
|---|
| 192 | close(CANPOST) or warn "!!!! couldn't close proxies.canpost.txt: $!\n"; |
|---|
| 193 | print ">>>> Testing complete.\n"; |
|---|
| 194 | } |
|---|
| 195 | |
|---|
| 196 | sub test_proxy { |
|---|
| 197 | PROXYTEST: foreach my $proxy (@_) { |
|---|
| 198 | if (is_blacklisted($proxy)) { |
|---|
| 199 | printf '%-25s', $proxy; |
|---|
| 200 | print "FAILURE - BLACKLISTED PROXY\n"; |
|---|
| 201 | next PROXYTEST; |
|---|
| 202 | } |
|---|
| 203 | # create pseudo-web-browser with user-agent of firefux |
|---|
| 204 | my $pseudo_browser = LWP::UserAgent->new; |
|---|
| 205 | $pseudo_browser->agent( $agent ); |
|---|
| 206 | # set up proxy |
|---|
| 207 | $pseudo_browser->proxy('http', "http://$proxy/"); |
|---|
| 208 | $pseudo_browser->timeout($timeout); |
|---|
| 209 | # set up GET |
|---|
| 210 | my $GET_page = HTTP::Request->new(GET => 'http://www.google.com/webhp'); |
|---|
| 211 | # GET |
|---|
| 212 | my $GET_result = $pseudo_browser->request($GET_page); |
|---|
| 213 | # check GET result |
|---|
| 214 | my $POST_result; |
|---|
| 215 | if (($GET_result->is_success) && ($GET_result->content =~ /©\d* Google/)) { |
|---|
| 216 | # POST |
|---|
| 217 | my $form = HTML::Form->parse($GET_result); |
|---|
| 218 | $form->value(q => $query); |
|---|
| 219 | $POST_result = $pseudo_browser->request($form->click); |
|---|
| 220 | } else { |
|---|
| 221 | printf '%-25s', $proxy; |
|---|
| 222 | print "FAILURE - COULD NOT GET\n"; |
|---|
| 223 | next PROXYTEST; |
|---|
| 224 | } |
|---|
| 225 | # check POST result |
|---|
| 226 | if ($POST_result->is_success) { |
|---|
| 227 | if ($POST_result->decoded_content !~ /Results.*for <b>$query<\/b>/i) { |
|---|
| 228 | printf '%-25s', $proxy; |
|---|
| 229 | print "FAILURE - UNKNOWN\n"; |
|---|
| 230 | } else { |
|---|
| 231 | printf '%-25s', $proxy; |
|---|
| 232 | print "SUCCESS !\n"; |
|---|
| 233 | print CANPOST "$proxy\n"; |
|---|
| 234 | } |
|---|
| 235 | } else { |
|---|
| 236 | printf '%-25s', $proxy; |
|---|
| 237 | print "FAILURE - COULD NOT POST\n"; |
|---|
| 238 | print GETONLY "$proxy\n"; |
|---|
| 239 | } |
|---|
| 240 | } |
|---|
| 241 | } |
|---|
| 242 | |
|---|
| 243 | sub is_blacklisted { |
|---|
| 244 | my $full_proxy = $_[0]; |
|---|
| 245 | my ($first_octet, $second_octet, $third_octet, $fourth_octet, $port) = $full_proxy =~ /(\d+)\.(\d+)\.(\d+)\.(\d+):(\d+)/; |
|---|
| 246 | # check against my blacklist |
|---|
| 247 | if ($first_octet =~ /^(?:6|7|11|21|22|25|26|29|30|49|50|55|164|155|147|144|143|140|138|137|132|131|128|129|134|136|138|139|205|216|160|150)$/) { |
|---|
| 248 | return 1; |
|---|
| 249 | } elsif ($first_octet == 207 && $second_octet =~ /60|61|120/) { |
|---|
| 250 | return 1; |
|---|
| 251 | } elsif ($first_octet == 204 && $second_octet == 34) { |
|---|
| 252 | return 1; |
|---|
| 253 | } elsif ($first_octet == 163 && $second_octet =~ /205|206/) { |
|---|
| 254 | return 1; |
|---|
| 255 | } elsif ($first_octet == 158 && $second_octet =~ /(?:[0-9]|1[0-9]|2[0-9]|30)/) { |
|---|
| 256 | return 1; |
|---|
| 257 | } elsif ($first_octet == 158 && $second_octet =~ /(?:23[5-9]|24[0-9]|25[0-5])/) { |
|---|
| 258 | return 1; |
|---|
| 259 | } elsif ($first_octet == 153 && $second_octet =~ /(?:2[1-9]|3[0-1])/) { |
|---|
| 260 | return 1; |
|---|
| 261 | } elsif ($first_octet == 24 && $second_octet == 198) { |
|---|
| 262 | return 1; |
|---|
| 263 | } elsif ($first_octet == 62 && $second_octet =~ /(?:[0-9]|2[0-9]|30)/) { |
|---|
| 264 | return 1; |
|---|
| 265 | } elsif ($first_octet == 64 && $second_octet =~ /70|224|225|226/) { |
|---|
| 266 | return 1; |
|---|
| 267 | } elsif ($first_octet == 212 && $second_octet =~ /56|143|149|159|179|208/) { |
|---|
| 268 | return 1; |
|---|
| 269 | } elsif ($first_octet == 158 && $second_octet =~ /(?:23[5-9]|24[0-9]|25[0-5])/) { |
|---|
| 270 | return 1; |
|---|
| 271 | } elsif ($first_octet == 146 && $second_octet =~ /17|80|98|154|165/) { |
|---|
| 272 | return 1; |
|---|
| 273 | } elsif ($first_octet == 148 && $second_octet == 114) { |
|---|
| 274 | return 1; |
|---|
| 275 | } elsif ($first_octet == 152 && $second_octet =~ /82|151|152|154|229/) { |
|---|
| 276 | return 1; |
|---|
| 277 | } elsif ($first_octet == 156 && $second_octet == 9) { |
|---|
| 278 | return 1; |
|---|
| 279 | } elsif ($first_octet == 159 && $second_octet == 120) { |
|---|
| 280 | return 1; |
|---|
| 281 | } elsif ($first_octet == 161 && $second_octet == 124) { |
|---|
| 282 | return 1; |
|---|
| 283 | } elsif ($first_octet == 167 && $second_octet == 44) { |
|---|
| 284 | return 1; |
|---|
| 285 | } elsif ($first_octet == 169 && $second_octet =~ /252|253/) { |
|---|
| 286 | return 1; |
|---|
| 287 | } elsif ($first_octet == 195 && $second_octet == 10) { |
|---|
| 288 | return 1; |
|---|
| 289 | } elsif ($first_octet == 199 && $second_octet == 122) { |
|---|
| 290 | return 1; |
|---|
| 291 | } elsif ($first_octet == 203 && $second_octet == 59) { |
|---|
| 292 | return 1; |
|---|
| 293 | } elsif ($first_octet == 207 && $second_octet == 30) { |
|---|
| 294 | return 1; |
|---|
| 295 | } elsif ($first_octet == 208 && $second_octet == 240) { |
|---|
| 296 | return 1; |
|---|
| 297 | } elsif ($first_octet == 209 && $second_octet == 35) { |
|---|
| 298 | return 1; |
|---|
| 299 | } elsif ($first_octet == 213 && $second_octet == 8) { |
|---|
| 300 | return 1; |
|---|
| 301 | } elsif ($first_octet == 157 && $second_octet =~ /150|153|202|217/) { |
|---|
| 302 | return 1; |
|---|
| 303 | } elsif ($first_octet == 162 && $second_octet =~ /32|45|46/) { |
|---|
| 304 | return 1; |
|---|
| 305 | } elsif ($first_octet == 168 && $second_octet =~ /68|85|102/) { |
|---|
| 306 | return 1; |
|---|
| 307 | } else { |
|---|
| 308 | return 0; |
|---|
| 309 | } |
|---|
| 310 | } |
|---|