SQL Authentifizierung



  • Also, ich bin dabei per tcp mich an nem lokalen SQL Server anzumelden.

    Habe folgende Seite als Hilfe:
    http://www.redferni.uklinux.net/mysql/MySQL-Protocol.html

    Und hab mich bis zum password-hash algo vorgearbeitet, aber komme da einfach nicht weiter, und ich weiss nicht ob ich einfach den text nicht verstehe oder sonst irgendwas mich dabei stört die aufgabe richtig zu erledigen und zwar gibt es da folgende Zeilen:

    Password algorithm
    The protocol 9 and protocol 10 password algorithms are different. In both cases, a seed is provided by the server and a password is provided by the user, and together they are used to generate a scrambled message of the same length as the seed.

    Hashing mechanism
    A string is hashed to a pair of unsigned longs using the following algorithm:

    n1 = 1345345333
    n2 = 305419889
    add = 7
    foreach c in password (ignoring space or tab)
    n1 = n1 EOR (((n1 & 63) + add) * c + n1 * 256)
    n2 = (n2 * 256) EOR n1
    add = add + c

    Only the bottom 31 bits of the unsigned longs are used.

    Protocol 10
    First the password, then the salt are hashed to give two pairs of longs: p1, p2, s1 and s2. These are then used to generate the two seeds of a random number generator, which takes values between 0 and 230-2.

    seed1 = p1 EOR s1
    seed2 = p2 EOR s2

    The random number generator algorithm is:

    seed1 = (seed1 * 3 + seed2) mod 230 - 1
    seed2 = (seed1 + seed2 + 33) mod 230 - 1
    return seed1 / (230 - 1)

    The random number generator is called once for each byte of the salt, and the number given is multiplied by 31 and added to 64 to give an ASCII character between '@' and '^'.

    msg[i] = chr(64 + rng()*31)

    The string just given then has each character exclusive-ored with the random number generator multiplied by 31.

    msg[i] = msg[i] eor(rng()*31)

    Daraus hab ich nun folgenden Code verstanden:

    #include <windows.h> 
    #include "dll.h" 
    #include <stdio.h>
    #include <stdlib.h>
    #include <math.h>
    
    unsigned long seed1,seed2;
    int rng();
    
    EXPORT char* CALLBACK scramble_pw(char* password, char* salt)
    {
        int i;
        int len_pw=strlen(password);
        int c[7];
    
        unsigned long p1,p2,s1,s2;
    
        // HASH PW
        unsigned long n1=1345345333;
        unsigned long n2=305419889;
        int add=7;
    
        char* msg;
    
        for (i=1; i<=len_pw; i++ )
        {
            c[i-1]=password[i-1];
    
            n1=n1 ^ (((n1 && 63)+add)* c[i-1]+n1*256);
            n2=(n2 * 256) ^ n1;
            add=add+c[i-1];   
        }
        p1=n1;
        p2=n2;
    
        /*
        char* ret1;
        char* ret2;
    
        ultobstr(p2,ret1);
    
        return ret1;//ret2;*/
    
        // HASH SALT
        n1=1345345333;
        n2=305419889;
        add=7;
    
        for (i=1; i<=8; i++)
        {
            c[i-1]=salt[i-1];
    
            n1=n1 ^ (((n1 & 63)+add)* c[i-1]+n1*256);
            n2=(n2 * 256) ^ n1;
            add=add+c[i-1];   
    
            s1=n1;
            s2=n2;
        }
    
        seed1=p1 ^ s1;
        seed2=p2 ^ s2;
    
        for (i=1; i<=8; i++)    
        {
            msg[i-1]=(64 +rng()*31);
            msg[i-1]= msg[i-1]^(rng()*31);
        }
    
        return msg;
    
    }
    
    int rng()
    {
        seed1=(seed1 *3 +seed2) % int(pow(2,30)) -1;
        seed2=(seed1 + seed2 + 33) % int(pow(2,30)) -1;
        return seed1/(int(pow(2,30))-1);
    }
    

    Aber wenn ich msg mir anschaue´, sind da lauter @ Zeichen.

    Ich mach mir kaum Hoffnung das mir jemand helfen kann der das Problem nicht selber gehabt hat, da wahrscheinlich keiner sich damit auseinandersetzen wird.

    Aber ich hab schon alles mögliche versucht, google stundenlang genutzt, nach codes gesucht, versucht diesen code in anderen sprachen umzusetzen, aber ich denke das problem liegt einfach daran das ich aus dem text keinen richtigen code zu machen verstehe. 😞


Anmelden zum Antworten