GetChallenge() public method

Returns the challenge for this message.
Returns the challenge for this message.
public GetChallenge ( ) : byte[]
return byte[]
Beispiel #1
0
 /// <summary>
 /// Constructs the NT response to the given Type-2 message using
 /// the supplied password.
 /// </summary>
 /// <remarks>
 /// Constructs the NT response to the given Type-2 message using
 /// the supplied password.
 /// </remarks>
 /// <param name="type2">The Type-2 message.</param>
 /// <param name="password">The password.</param>
 /// <returns>A <code>byte[]</code> containing the NT response.</returns>
 public static byte[] GetNTResponse(Type2Message type2, string password)
 {
     if (type2 == null || password == null)
     {
         return(null);
     }
     return(NtlmPasswordAuthentication.GetNtlmResponse(password, type2.GetChallenge()));
 }
Beispiel #2
0
        public static byte[] GetNtlMv2Response(Type2Message type2, byte[] responseKeyNt,
                                               byte[] clientChallenge)
        {
            if (type2 == null || responseKeyNt == null || clientChallenge == null)
            {
                return(null);
            }
            long nanos1601 = (Runtime.CurrentTimeMillis() + MillisecondsBetween1970And1601
                              ) * 10000L;

            return(NtlmPasswordAuthentication.GetNtlMv2Response(responseKeyNt, type2.GetChallenge
                                                                    (), clientChallenge, nanos1601, type2.GetTargetInformation()));
        }
Beispiel #3
0
 public static byte[] GetLMv2Response(Type2Message type2,
                                      string domain,
                                      string user,
                                      string password,
                                      byte[] clientChallenge)
 {
     if (type2 == null ||
         domain == null ||
         user == null ||
         password == null ||
         clientChallenge == null)
     {
         return(null);
     }
     return(NtlmPasswordAuthentication.GetLMv2Response(domain,
                                                       user,
                                                       password,
                                                       type2.GetChallenge(),
                                                       clientChallenge));
 }
Beispiel #4
0
        /// <summary>Creates a Type-3 message in response to the given Type-2 message.</summary>
        /// <remarks>Creates a Type-3 message in response to the given Type-2 message.</remarks>
        /// <param name="type2">The Type-2 message which this represents a response to.</param>
        /// <param name="password">The password to use when constructing the response.</param>
        /// <param name="domain">The domain in which the user has an account.</param>
        /// <param name="user">The username for the authenticating user.</param>
        /// <param name="workstation">
        /// The workstation from which authentication is
        /// taking place.
        /// </param>
        public Type3Message(Type2Message type2,
                            string password,
                            string domain,
                            string user,
                            string workstation,
                            int flags)
        {
            SetFlags(flags | GetDefaultFlags(type2));
            if (workstation == null)
            {
                workstation = GetDefaultWorkstation();
            }
            SetWorkstation(workstation);
            SetDomain(domain);
            SetUser(user);
            switch (LmCompatibility)
            {
            case 0:
            case 1:
            {
                if ((GetFlags() & NtlmsspNegotiateNtlm2) == 0)
                {
                    SetLmResponse(GetLMResponse(type2, password));
                    SetNtResponse(GetNTResponse(type2, password));
                }
                else
                {
                    // NTLM2 Session Response
                    byte[] clientChallenge = new byte[24];
                    //RANDOM.NextBytes(clientChallenge);
                    Arrays.Fill(clientChallenge, 8, 24, unchecked ((byte)unchecked (0x00)));
                    // NTLMv1 w/ NTLM2 session sec and key exch all been verified with a debug build of smbclient
                    byte[] responseKeyNt
                        = NtlmPasswordAuthentication.NtowFv1(password);
                    byte[] ntlm2Response
                        = NtlmPasswordAuthentication.GetNtlm2Response(responseKeyNt,
                                                                      type2.GetChallenge(),
                                                                      clientChallenge);
                    SetLmResponse(clientChallenge);
                    SetNtResponse(ntlm2Response);
                    if ((GetFlags() & NtlmsspNegotiateSign) == NtlmsspNegotiateSign)
                    {
                        byte[] sessionNonce = new byte[16];
                        Array.Copy(type2.GetChallenge(), 0, sessionNonce, 0, 8);
                        Array.Copy(clientChallenge, 0, sessionNonce, 8, 8);
                        Md4 md4 = new Md4();
                        md4.Update(responseKeyNt);
                        byte[]  userSessionKey = md4.Digest();
                        Hmact64 hmac           = new Hmact64(userSessionKey);
                        hmac.Update(sessionNonce);
                        byte[] ntlm2SessionKey = hmac.Digest();
                        if ((GetFlags() & NtlmsspNegotiateKeyExch) != 0)
                        {
                            _masterKey = new byte[16];
                            //RANDOM.NextBytes(masterKey);
                            byte[] exchangedKey = new byte[16];
                            Rc4    rc4          = new Rc4(ntlm2SessionKey);
                            rc4.Update(_masterKey, 0, 16, exchangedKey, 0);
                            SetSessionKey(exchangedKey);
                        }
                        else
                        {
                            _masterKey = ntlm2SessionKey;
                            SetSessionKey(_masterKey);
                        }
                    }
                }
                break;
            }

            case 2:
            {
                byte[] nt = GetNTResponse(type2, password);
                SetLmResponse(nt);
                SetNtResponse(nt);
                break;
            }

            case 3:
            case 4:
            case 5:
            {
                byte[] responseKeyNt1
                    = NtlmPasswordAuthentication.NtowFv2(domain, user, password);
                byte[] clientChallenge1 = new byte[8];
                //RANDOM.NextBytes(clientChallenge_1);
                SetLmResponse(GetLMv2Response(type2, domain, user, password, clientChallenge1));
                byte[] clientChallenge2 = new byte[8];
                //RANDOM.NextBytes(clientChallenge2);
                SetNtResponse(GetNtlMv2Response(type2, responseKeyNt1, clientChallenge2));
                if ((GetFlags() & NtlmsspNegotiateSign) == NtlmsspNegotiateSign)
                {
                    Hmact64 hmac = new Hmact64(responseKeyNt1);
                    hmac.Update(_ntResponse, 0, 16);
                    // only first 16 bytes of ntResponse
                    byte[] userSessionKey = hmac.Digest();
                    if ((GetFlags() & NtlmsspNegotiateKeyExch) != 0)
                    {
                        _masterKey = new byte[16];
                        //RANDOM.NextBytes(masterKey);
                        byte[] exchangedKey = new byte[16];
                        Rc4    rc4          = new Rc4(userSessionKey);
                        rc4.Update(_masterKey, 0, 16, exchangedKey, 0);
                        SetSessionKey(exchangedKey);
                    }
                    else
                    {
                        _masterKey = userSessionKey;
                        SetSessionKey(_masterKey);
                    }
                }
                break;
            }

            default:
            {
                SetLmResponse(GetLMResponse(type2, password));
                SetNtResponse(GetNTResponse(type2, password));
                break;
            }
            }
        }
Beispiel #5
0
        /// <exception cref="SharpCifs.Smb.SmbException"></exception>
        public virtual byte[] InitSecContext(byte[] token, int offset, int len)
        {
            switch (State)
            {
                case 1:
                {
                    Type1Message msg1 = new Type1Message(NtlmsspFlags, Auth.GetDomain(), Workstation);
                    token = msg1.ToByteArray();
                    if (Log.Level >= 4)
                    {
                        Log.WriteLine(msg1);
                        if (Log.Level >= 6)
                        {
                            Hexdump.ToHexdump(Log, token, 0, token.Length);
                        }
                    }
                    State++;
                    break;
                }

                case 2:
                {
                    try
                    {
                        Type2Message msg2 = new Type2Message(token);
                        if (Log.Level >= 4)
                        {
                            Log.WriteLine(msg2);
                            if (Log.Level >= 6)
                            {
                                Hexdump.ToHexdump(Log, token, 0, token.Length);
                            }
                        }
                        ServerChallenge = msg2.GetChallenge();
                        NtlmsspFlags &= msg2.GetFlags();
                        //                  netbiosName = getNtlmsspListItem(token, 0x0001);
                        Type3Message msg3 = new Type3Message(msg2, Auth.GetPassword(), Auth.GetDomain(),
                            Auth.GetUsername(), Workstation, NtlmsspFlags);
                        token = msg3.ToByteArray();
                        if (Log.Level >= 4)
                        {
                            Log.WriteLine(msg3);
                            if (Log.Level >= 6)
                            {
                                Hexdump.ToHexdump(Log, token, 0, token.Length);
                            }
                        }
                        if ((NtlmsspFlags & NtlmFlags.NtlmsspNegotiateSign) != 0)
                        {
                            SigningKey = msg3.GetMasterKey();
                        }
                        isEstablished = true;
                        State++;
                        break;
                    }
                    catch (Exception e)
                    {
                        throw new SmbException(e.Message, e);
                    }
                }

                default:
                {
                    throw new SmbException("Invalid state");
                }
            }
            return token;
        }
Beispiel #6
0
		/// <summary>
		/// Constructs the NT response to the given Type-2 message using
		/// the supplied password.
		/// </summary>
		/// <remarks>
		/// Constructs the NT response to the given Type-2 message using
		/// the supplied password.
		/// </remarks>
		/// <param name="type2">The Type-2 message.</param>
		/// <param name="password">The password.</param>
		/// <returns>A <code>byte[]</code> containing the NT response.</returns>
		public static byte[] GetNTResponse(Type2Message type2, string password)
		{
			if (type2 == null || password == null)
			{
				return null;
			}
			return NtlmPasswordAuthentication.GetNtlmResponse(password, type2.GetChallenge());
		}
Beispiel #7
0
		public static byte[] GetNtlMv2Response(Type2Message type2, byte[] responseKeyNt, 
			byte[] clientChallenge)
		{
			if (type2 == null || responseKeyNt == null || clientChallenge == null)
			{
				return null;
			}
			long nanos1601 = (Runtime.CurrentTimeMillis() + MillisecondsBetween1970And1601
				) * 10000L;
			return NtlmPasswordAuthentication.GetNtlMv2Response(responseKeyNt, type2.GetChallenge
				(), clientChallenge, nanos1601, type2.GetTargetInformation());
		}
Beispiel #8
0
		public static byte[] GetLMv2Response(Type2Message type2, string domain, string user
			, string password, byte[] clientChallenge)
		{
			if (type2 == null || domain == null || user == null || password == null || clientChallenge
				 == null)
			{
				return null;
			}
			return NtlmPasswordAuthentication.GetLMv2Response(domain, user, password, type2.GetChallenge
				(), clientChallenge);
		}
Beispiel #9
0
		/// <summary>Creates a Type-3 message in response to the given Type-2 message.</summary>
		/// <remarks>Creates a Type-3 message in response to the given Type-2 message.</remarks>
		/// <param name="type2">The Type-2 message which this represents a response to.</param>
		/// <param name="password">The password to use when constructing the response.</param>
		/// <param name="domain">The domain in which the user has an account.</param>
		/// <param name="user">The username for the authenticating user.</param>
		/// <param name="workstation">
		/// The workstation from which authentication is
		/// taking place.
		/// </param>
		public Type3Message(Type2Message type2, string password, string domain, string user
			, string workstation, int flags)
		{
			SetFlags(flags | GetDefaultFlags(type2));
			if (workstation == null)
			{
				workstation = GetDefaultWorkstation();
			}
			SetWorkstation(workstation);
			SetDomain(domain);
			SetUser(user);
			switch (LmCompatibility)
			{
				case 0:
				case 1:
				{
					if ((GetFlags() & NtlmsspNegotiateNtlm2) == 0)
					{
						SetLmResponse(GetLMResponse(type2, password));
						SetNtResponse(GetNTResponse(type2, password));
					}
					else
					{
						// NTLM2 Session Response
						byte[] clientChallenge = new byte[24];
						//RANDOM.NextBytes(clientChallenge);
						Arrays.Fill(clientChallenge, 8, 24, unchecked((byte)unchecked(0x00)));
						// NTLMv1 w/ NTLM2 session sec and key exch all been verified with a debug build of smbclient
						byte[] responseKeyNt = NtlmPasswordAuthentication.NtowFv1(password);
						byte[] ntlm2Response = NtlmPasswordAuthentication.GetNtlm2Response(responseKeyNt, 
							type2.GetChallenge(), clientChallenge);
						SetLmResponse(clientChallenge);
						SetNtResponse(ntlm2Response);
						if ((GetFlags() & NtlmsspNegotiateSign) == NtlmsspNegotiateSign)
						{
							byte[] sessionNonce = new byte[16];
							Array.Copy(type2.GetChallenge(), 0, sessionNonce, 0, 8);
							Array.Copy(clientChallenge, 0, sessionNonce, 8, 8);
							Md4 md4 = new Md4();
							md4.Update(responseKeyNt);
							byte[] userSessionKey = md4.Digest();
							Hmact64 hmac = new Hmact64(userSessionKey);
							hmac.Update(sessionNonce);
							byte[] ntlm2SessionKey = hmac.Digest();
							if ((GetFlags() & NtlmsspNegotiateKeyExch) != 0)
							{
								_masterKey = new byte[16];
								//RANDOM.NextBytes(masterKey);
								byte[] exchangedKey = new byte[16];
								Rc4 rc4 = new Rc4(ntlm2SessionKey);
								rc4.Update(_masterKey, 0, 16, exchangedKey, 0);
								SetSessionKey(exchangedKey);
							}
							else
							{
								_masterKey = ntlm2SessionKey;
								SetSessionKey(_masterKey);
							}
						}
					}
					break;
				}

				case 2:
				{
					byte[] nt = GetNTResponse(type2, password);
					SetLmResponse(nt);
					SetNtResponse(nt);
					break;
				}

				case 3:
				case 4:
				case 5:
				{
					byte[] responseKeyNt1 = NtlmPasswordAuthentication.NtowFv2(domain, user, password
						);
					byte[] clientChallenge1 = new byte[8];
					//RANDOM.NextBytes(clientChallenge_1);
					SetLmResponse(GetLMv2Response(type2, domain, user, password, clientChallenge1));
					byte[] clientChallenge2 = new byte[8];
					//RANDOM.NextBytes(clientChallenge2);
					SetNtResponse(GetNtlMv2Response(type2, responseKeyNt1, clientChallenge2));
					if ((GetFlags() & NtlmsspNegotiateSign) == NtlmsspNegotiateSign)
					{
						Hmact64 hmac = new Hmact64(responseKeyNt1);
						hmac.Update(_ntResponse, 0, 16);
						// only first 16 bytes of ntResponse
						byte[] userSessionKey = hmac.Digest();
						if ((GetFlags() & NtlmsspNegotiateKeyExch) != 0)
						{
							_masterKey = new byte[16];
							//RANDOM.NextBytes(masterKey);
							byte[] exchangedKey = new byte[16];
							Rc4 rc4 = new Rc4(userSessionKey);
							rc4.Update(_masterKey, 0, 16, exchangedKey, 0);
							SetSessionKey(exchangedKey);
						}
						else
						{
							_masterKey = userSessionKey;
							SetSessionKey(_masterKey);
						}
					}
					break;
				}

				default:
				{
					SetLmResponse(GetLMResponse(type2, password));
					SetNtResponse(GetNTResponse(type2, password));
					break;
				}
			}
		}