Kerberos ticket decryption with C#, checksums do NOT match


hi,

 

i'm trying decrypt encrypted part of kerberos ticket with c# using classical crypto classes. guideline follow pseudo code found in rfc 4757 (section 5 decrypt)

 

i included in c# code fragment portions ot pseudo code implemented. i'm still struggling fact checksums not match.

 

questions:

 

  • is password salted? somewhere read in kerberos 5 password salted pricipal name, format (just concatenated?), case applied (case sensitivity)
  • is exportable encryption used or not?

i must missing since said checksums not match.

 

code fragment (utility functions , classes not included)

the encryptedticket.dat exported via wireshark

====================================================================================== 

  byte[] k  = new byte[16];
  byte[] k1 = new byte[16];
  byte[] k2 = new byte[16];
  byte[] k3 = new byte[16];

            rc4 rc4 = null;
            icryptotransform decryptor;

            byte[] cypher = file.readallbytes(@"c:\documents , settings\administrator\desktop\encryptedticket.dat");

            md4 md4 = new md4();

            k = md4.getbytehashfrombytes("password of account under service runs");

 

            #region retrieve checksum

            byte[] checksum = new byte[16];

            bytearraycopy(cypher, 0, checksum, 0, 16);

            #endregion

 

            #region retrieve confounder

            byte[] confounder = new bytemusic;

            bytearraycopy(cypher, 16, confounder, 0, 8);

            #endregion

 

            #region retrieve edata

            byte[] edata = new byte[cypher.length - 24];

            bytearraycopy(cypher, 24, edata, 0, cypher.length - 24);

            #endregion

 

            //if (export)
            //{
            //    *((dword*)(l40 + 10)) = t;
            //    hmac(k, l40, 14, k1);
            //}
            //else
            //{
            //    hmac(k, &t, 4, k1);
            //}
            #region part 1

            bool isexportable = true;

            int messagetype = 14;

            byte[] messagetypebuffer = new byte[4];

            messagetypebuffer[3] = (byte)messagetype; //ap_req little endian         

            hmacmd5 hmac = new hmacmd5(k);

            if (isexportable)
            {
                byte[] l40 = new byte[14];

                bytearraycopy(encoding.ascii.getbytes("fortybits"), 0, l40, 0, 9);

                bytearraycopy(messagetypebuffer, 0, l40, 10, 4);

                k1 = hmac.computehash(l40, 0, 14);
            }
            else
            {
                k1 = hmac.computehash(messagetypebuffer, 0, 4);
            }

            #endregion

 

            //memcpy (k2, k1, 16);
            #region part 2
           
            bytearraycopy(k1, 0, k2, 0, k1.length);

            #endregion

 

            //if (export) memset (k1+7, 0xab, 9);
            #region part 3

            if (isexportable)
            {
                bytearraycopy(new byte[] { 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab, 0xab }, 0, k1, 7, 9);
            }

            #endregion

 

            //k3 = hmac(k1, edata.checksum);
            #region part 4

            hmac = new hmacmd5(k1);

            k3 = hmac.computehash(checksum, 0, checksum.length);

            #endregion

 

            //rc4 (k3, edata.confounder);
            #region part 5

            rc4 = rc4.create();

            decryptor = rc4.createdecryptor(k3, null);

            byte[] decryptedconfounder = decryptor.transformfinalblock(confounder, 0, confounder.length);

            #endregion

 

            //rc4 (k3, edata.data);
            #region part 6

            rc4 = rc4.create();

            decryptor = rc4.createdecryptor(k3, null);

            byte[] decrypteddata = decryptor.transformfinalblock(edata, 0, edata.length);

            #endregion

 

            //checksum = hmac(k2, concat(edata.confounder, edata.data));
            #region part 7

            hmac = new hmacmd5(k2);

            byte[] test = new byte[decryptedconfounder.length + decrypteddata.length];

            bytearraycopy(decryptedconfounder, 0, test, 0, decryptedconfounder.length);

            bytearraycopy(decrypteddata, 0, test, decryptedconfounder.length, decrypteddata.length);

            byte[] computedchecksum = hmac.computehash(test, 0, test.length);

            #endregion

 

            //if (checksum != edata.checksum)
            //    printf("checksum error  !!!!!!\n");
            #region part 8

            if (!comparebytearrays(computedchecksum, checksum))
            {
                console.writeline("no match");
            }

            #endregion

======================================================================================

 

this problem bugging me quite time, appreciate if me out here.

either directly pointing mistake (fantastic) or pointing me reference me (also good).

 

kind regards,

 

wilke

 

hi,

 

this issue appears related development.we recommend you posting in msdn forum qualified pool of respondents.for reference, have included link msdn forum below:

 

msdn forum

http://forums.microsoft.com/msdn/default.aspx?siteid=1

 

i hope issue resolved soon.

 

best wishes

--------------
morgan che

microsoft online community support

 



Windows Server  >  Security



Comments

Popular posts from this blog

more indexes

ActiveDirectory

Virtual Channel