Beispiel #1
0
        /// <summary>
        /// compute response
        /// </summary>
        /// <param name="flags">the flags for challenge</param>
        /// <param name="serverChallenge">the server challenge</param>
        /// <param name="targetInfo">the target info contains avpairs</param>
        /// <param name="responseKeyNT">the response nt key</param>
        /// <param name="responseKeyLM">the response lm key</param>
        /// <param name="lmChallengeResponse">the challenge response lm</param>
        /// <param name="ntChallengeResponse">the challenge response nt</param>
        private void ComputeResponse(
            NegotiateTypes flags,
            ulong serverChallenge,
            ICollection <AV_PAIR> targetInfo,
            byte[] responseKeyNT,
            byte[] responseKeyLM,
            out byte[] lmChallengeResponse,
            out byte[] ntChallengeResponse
            )
        {
            // clientChallenge, a random 8 bytes.
            ulong clientChallenge = NlmpUtility.BytesToSecurityUInt64(NlmpUtility.Nonce(8));

            // time
            ulong time = 0;

            if (!NlmpUtility.IsNtlmV1(this.client.Config.Version))
            {
                time = NlmpUtility.GetTime(targetInfo);
            }

            byte[] sessionBaseKey = null;

            // compute response
            NlmpUtility.ComputeResponse(
                this.client.Config.Version, flags, responseKeyNT, responseKeyLM, serverChallenge, clientChallenge,
                time, NlmpUtility.AvPairCollectionGetBytes(targetInfo), out ntChallengeResponse,
                out lmChallengeResponse, out sessionBaseKey);

            // save key to context
            this.client.Context.SessionBaseKey = sessionBaseKey;
        }
Beispiel #2
0
        /// <summary>
        /// accept the negotiate packet, generated the challenge packet.
        /// </summary>
        /// <param name="negotiatePacket">the negotiate packet</param>
        private void AcceptNegotiatePacket(NlmpNegotiatePacket negotiatePacket)
        {
            // save the negotiate, to valid the mic when authenticate.
            this.negotiate = negotiatePacket;

            // generated negotiate flags for challenge packet
            NegotiateTypes negotiateFlags = GeneratedNegotiateFlags(negotiatePacket);

            // initialize target name
            string targetName = GenerateTargetName();

            // initialize av pairs.
            ICollection <AV_PAIR> targetInfo = GenerateTargetInfo();

            VERSION sspiVersion = NlmpUtility.GetVersion();
            // the serverChallenge is 8 bytes.
            ulong serverChallenge = BitConverter.ToUInt64(NlmpUtility.Nonce(8), 0);

            NlmpChallengePacket challengePacket = this.nlmpServer.CreateChallengePacket(
                negotiateFlags, sspiVersion, serverChallenge, targetName, targetInfo);

            this.challenge = challengePacket;
            this.token     = challengePacket.ToBytes();
        }
Beispiel #3
0
        public void GetSecurityToken(
            NlmpVersion ntlmVersion,
            string domainName,
            string userName,
            string password,
            ulong serverTime,
            ulong serverChallenge,
            out byte[] caseInsensitivePassword,
            out byte[] caseSensitivePassword)
        {
            if (ntlmVersion != NlmpVersion.v1 && ntlmVersion != NlmpVersion.v2)
            {
                throw new ArgumentException(
                          string.Format("the ntlmVersion({0}) must be valid NlmpVersion value", ntlmVersion), "ntlmVersion");
            }

            caseInsensitivePassword = null;
            caseSensitivePassword   = null;

            #region Prepare the TargetInfo

            byte[] targetInfo = null;

            List <AV_PAIR> pairs = new List <AV_PAIR>();
            NlmpUtility.AddAVPair(pairs, AV_PAIR_IDs.MsvAvEOL, 0x00, null);

            targetInfo = NlmpUtility.AvPairCollectionGetBytes(pairs);
            #endregion

            #region Prepare the Nlmp Negotiate Flags

            // the flags for negotiate
            NegotiateTypes nlmpFlags = NegotiateTypes.NTLMSSP_NEGOTIATE_NTLM | NegotiateTypes.NTLM_NEGOTIATE_OEM;

            #endregion

            // exported to application for the SessionKey.
            byte[] sessionBaseKey = null;

            #region Prepare the keys

            // responseKeyNT
            byte[] responseKeyNT = NlmpUtility.GetResponseKeyNt(ntlmVersion, domainName, userName, password);

            // responseKeyLM
            byte[] responseKeyLM = NlmpUtility.GetResponseKeyLm(ntlmVersion, domainName, userName, password);

            #endregion

            #region Compute Response

            // clientChallenge, a 8 bytes random number.
            ulong clientChallenge = BitConverter.ToUInt64(NlmpUtility.Nonce(8), 0);

            // compute response
            NlmpUtility.ComputeResponse(
                ntlmVersion, nlmpFlags, responseKeyNT, responseKeyLM, serverChallenge, clientChallenge, serverTime,
                targetInfo, out caseSensitivePassword, out caseInsensitivePassword, out sessionBaseKey);

            #endregion
        }