• [^] # Re: 2 idées et 1 remarque

    Posté par . En réponse au message Probleme de calcul du Checksum TCP. Évalué à 1.

    J'utilise une autre fonction de calcul de checksum qui vient d'un article de phrack maintenant


    int checksum (unsigned short *buf, int nwords)
    {
    /*! Compute Internet Checksum for "count" bytes
    * beginning at location "addr".
    */
    register long sum = 0;

    while( nwords > 1 ) {
    /*! This is the inner loop */
    sum += *buf++;
    nwords -= 2;
    }

    /*! Add left-over byte, if any */
    if( nwords == 1 )
    {
    u_short oddbyte = 0;
    *((u_char *) &oddbyte) = *(u_char *)buf;
    sum += oddbyte;
    }

    /*! Fold 32-bit sum to 16 bits */
    sum = (sum >> 16) + (sum & 0xffff); /* add high-16 to low-16 */
    sum += (sum >> 16); /* add carry */
    return(~sum);
    }


    de fait, le code de creation devient


    /*! *******************
    * compute TCP checksum
    * ********************
    */
    int PSEUDO_SIZE = /*! 12 = size of the pseudoheader */
    PAYLOAD_SIZE + (replay_tcp->doff*4) + 12;

    char pseudo_tcp[ PSEUDO_SIZE ];

    /*! fill up the pseudo header
    */
    struct pseudo_header *ph = (struct pseudo_header *) pseudo_tcp;

    ph->saddr = iph->saddr;
    ph->daddr = iph->daddr;
    ph->mbz = 0;
    ph->ptcl = 6;
    ph->tcpl = htons(PSEUDO_SIZE - 12);

    /*! fill check field to 0 for checksum computation
    */
    replay_tcp->check = 0;

    /*! add tcp header + payload to the pseudo packet
    */
    memcpy((char *)&ph->tcp, (char *)&replay_tcp, PSEUDO_SIZE - 12);

    /*! compute the checksum and store it in the TCP structure
    */
    replay_tcp->check = checksum((unsigned short *) pseudo_tcp, PSEUDO_SIZE );

    g_print("check = %x, size = %u \n", ntohs(replay_tcp->check), PSEUDO_SIZE);


    mais ca marche toujours pas :'(