| 1 | #!/usr/bin/perl |
|---|
| 2 | |
|---|
| 3 | use strict; |
|---|
| 4 | use warnings; |
|---|
| 5 | use WWW::Mechanize; |
|---|
| 6 | use HTTP::Request::Common; |
|---|
| 7 | use JSON; |
|---|
| 8 | use List::Util qw/shuffle/; |
|---|
| 9 | |
|---|
| 10 | require 'gen_nick.pl'; |
|---|
| 11 | |
|---|
| 12 | my $proxyfile = "proxies.txt"; |
|---|
| 13 | my $debug = 0; |
|---|
| 14 | our $channel = '#freenode'; |
|---|
| 15 | our $troll = "Did you know? The_Thing AKA \"The Thing That Should Not Be\" calls himself as such because he survived THREE separate abortion attempts!"; |
|---|
| 16 | our $random = 0; #1 will use trolldb, 0 will use message above |
|---|
| 17 | |
|---|
| 18 | my @proxies; |
|---|
| 19 | if (-e $proxyfile) { |
|---|
| 20 | print "Loading proxies from $proxyfile\n"; |
|---|
| 21 | my $fh; open $fh, $proxyfile or die $!; |
|---|
| 22 | local $/; |
|---|
| 23 | my $proxies = <$fh>; |
|---|
| 24 | close $fh; |
|---|
| 25 | @proxies = split("\n", $proxies); |
|---|
| 26 | } |
|---|
| 27 | |
|---|
| 28 | while (1) { |
|---|
| 29 | if (fork) { |
|---|
| 30 | sleep 1; |
|---|
| 31 | } else { |
|---|
| 32 | h8(); |
|---|
| 33 | exit; |
|---|
| 34 | } |
|---|
| 35 | } |
|---|
| 36 | |
|---|
| 37 | sub pick_proxy { |
|---|
| 38 | return unless @proxies; |
|---|
| 39 | my @p = shuffle @proxies; |
|---|
| 40 | return shift @p; |
|---|
| 41 | } |
|---|
| 42 | |
|---|
| 43 | sub h8 { |
|---|
| 44 | my $nick = gen_nick(); |
|---|
| 45 | my $count = 0; |
|---|
| 46 | my $mech = new WWW::Mechanize( |
|---|
| 47 | stack_depth => 0, |
|---|
| 48 | agent => 'Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10.6; en-US; rv:1.9.1.8) Gecko/20100202 Firefox/3.5.8', |
|---|
| 49 | ); |
|---|
| 50 | |
|---|
| 51 | my $proxy = pick_proxy(); |
|---|
| 52 | if ($proxy) { |
|---|
| 53 | $proxy = "http://$proxy" unless $proxy =~ /^\w+:\/\//; |
|---|
| 54 | $mech->proxy('http', $proxy); |
|---|
| 55 | } |
|---|
| 56 | |
|---|
| 57 | print "Connecting with nick $nick"; |
|---|
| 58 | print " and proxy $proxy" if $proxy; |
|---|
| 59 | print "...\n"; |
|---|
| 60 | |
|---|
| 61 | my $base = "http://webchat.freenode.net/dynamic/two"; |
|---|
| 62 | |
|---|
| 63 | my $t = 0; |
|---|
| 64 | my $s; |
|---|
| 65 | my $r = time(); |
|---|
| 66 | |
|---|
| 67 | my $post_req = sub { |
|---|
| 68 | my ($url, @params) = @_; |
|---|
| 69 | |
|---|
| 70 | push @params, 's' => $s if $s; |
|---|
| 71 | |
|---|
| 72 | my $req_url = "$base$url?r=$r"; |
|---|
| 73 | $req_url .= "&t=$t" if $t; |
|---|
| 74 | $t++; |
|---|
| 75 | |
|---|
| 76 | my $req = POST $req_url, \@params; |
|---|
| 77 | my $res = eval { $mech->request($req); }; |
|---|
| 78 | if (! $res || ! $res->is_success || $res->content =~ /You have a host listed in the DroneBL./ |
|---|
| 79 | || $res->content =~ /Your reported IP \[[\.\d\:]+\] is banned/) { |
|---|
| 80 | my $failure = ""; |
|---|
| 81 | $failure .= $res->status_line if $res; |
|---|
| 82 | $failure .= ' ' . $@ if $@; |
|---|
| 83 | warn "request failed ($failure): " . $res->content . "\n"; |
|---|
| 84 | if ($proxy) { |
|---|
| 85 | warn "proxy $proxy is probably bad\n"; |
|---|
| 86 | } |
|---|
| 87 | return; |
|---|
| 88 | } |
|---|
| 89 | |
|---|
| 90 | my $info = JSON::from_json($res->content); |
|---|
| 91 | unless ($info) { |
|---|
| 92 | die "Failed, response: " . $res->content; |
|---|
| 93 | } |
|---|
| 94 | |
|---|
| 95 | unless ($s) { |
|---|
| 96 | $s = $info->[1] or die "didn't get session token"; |
|---|
| 97 | } |
|---|
| 98 | |
|---|
| 99 | if ($debug) { |
|---|
| 100 | print $res->content . "\n----\n"; |
|---|
| 101 | } |
|---|
| 102 | return 1; |
|---|
| 103 | }; |
|---|
| 104 | |
|---|
| 105 | $post_req->('/e/n', nick => $nick); |
|---|
| 106 | $post_req->('/e/s'); # t=2 |
|---|
| 107 | $post_req->('/e/p', c => 'JOIN '.$channel); # t=3 |
|---|
| 108 | $post_req->('/e/s'); # t=4 |
|---|
| 109 | $post_req->('/e/s'); # t=5 |
|---|
| 110 | for ($count=1; $count<11; $count++) { |
|---|
| 111 | if($random==1) { |
|---|
| 112 | $mech->get('http://rolloffle.churchburning.org/troll_me_text.php'); |
|---|
| 113 | $troll=$mech->content( format => 'text' ); |
|---|
| 114 | } |
|---|
| 115 | $post_req->('/e/p', c => 'PRIVMSG '.$channel.' :'.$troll.' '.gen_nick()); # t=8++ |
|---|
| 116 | $post_req->('/e/s'); # t=9++ |
|---|
| 117 | |
|---|
| 118 | } |
|---|
| 119 | } |
|---|
| 120 | |
|---|