/// <summary> /// create the implicit NTLM SessionSetup request packet. /// </summary> /// <param name = "implicitNtlmVersion"> /// the version of smb to using: PlainTextPassword: transport password as plain-text. the /// NEGOTIATE_ENCRYPT_PASSWORDS of SecurityMode in negotiate response should set to 0. NtlmVersion1:using ntlm /// v1 NtlmVersion2:using ntlm v2 /// </param> /// <param name = "domainName">the domain name of user credential </param> /// <param name = "userName">the name of user credential </param> /// <param name = "password">the password of user credential </param> /// <returns>A session setup packet. </returns> public virtual SmbSessionSetupImplicitNtlmAndxRequestPacket CreateSessionSetupImplicitNtlmRequest( ImplicitNtlmVersion implicitNtlmVersion, string domainName, string userName, string password) { SmbHeader_Flags2_Values flags2 = this.capability.Flags2; // the second time, must add sign-require to server if sign is enabled if ((Capability.ClientSignState & SignState.ENABLED) == SignState.ENABLED || (Capability.ClientSignState & SignState.REQUIRED) == SignState.REQUIRED) { flags2 |= SmbHeader_Flags2_Values.SMB_FLAGS2_SMB_SECURITY_SIGNATURE_REQUIRED; } return CreateSessionSetupImplicitNtlmRequest( this.MessageId, this.capability.Flag, flags2, this.Capabilities, this.MaxBufferSize, this.MaxMpxCount, implicitNtlmVersion, domainName, userName, password); }
/// <summary> /// create the implicit NTLM SessionSetup request packet /// </summary> /// <param name = "messageId">the id of message, used to identity the request and the server response. </param> /// <param name = "flags"> /// The Flags field contains individual flags, as specified in [CIFS] sections 2.4.2 and 3.1.1. /// </param> /// <param name = "flags2"> /// The Flags2 field contains individual bit flags that, depending on the negotiated SMB dialect, indicate /// various client and server capabilities. /// </param> /// <param name = "capabilities"> /// A set of client capabilities. These flags are a subset of those specified in section for the server /// capabilities returned in the SMB_COM_NEGOTIATE response. /// </param> /// <param name = "maxBufferSize"> /// The maximum size, in bytes, of the client buffer for sending and receiving SMB messages. /// </param> /// <param name = "maxMpxCount"> /// The maximum number of pending multiplexed requests supported by the client. This value MUST be less than /// or equal to the MaxMpxCount value provided by the server in the SMB_COM_NEGOTIATE response /// </param> /// <param name = "implicitNtlmVersion"> /// the version of smb to using: PlainTextPassword: transport password as plain-text. the /// NEGOTIATE_ENCRYPT_PASSWORDS of SecurityMode in negotiate response should set to 0. NtlmVersion1:using ntlm /// v1 NtlmVersion2:using ntlm v2 /// </param> /// <param name = "domainName">the domain name of user credential </param> /// <param name = "userName">the name of user credential </param> /// <param name = "password">the password of user credential </param> /// <returns>A session setup packet. </returns> /// <exception cref = "InvalidOperationException"> /// the implicit NTLM only support when ExtendedSessionSecurity is set to 0 /// </exception> private SmbSessionSetupImplicitNtlmAndxRequestPacket CreateSessionSetupImplicitNtlmRequest( ushort messageId, SmbHeader_Flags_Values flags, SmbHeader_Flags2_Values flags2, Capabilities capabilities, ushort maxBufferSize, ushort maxMpxCount, ImplicitNtlmVersion implicitNtlmVersion, string domainName, string userName, string password) { if (Capability.IsSupportsExtendedSecurity) { throw new InvalidOperationException( "the implicit NTLM only support when ExtendedSessionSecurity is set to 0"); } NTLMAuthenticationPolicyValues ntlmAuthenticationPolicyValues; LMAuthenticationPolicyValues lmAuthenticationPolicyValues; if (implicitNtlmVersion == ImplicitNtlmVersion.PlainTextPassword) { ntlmAuthenticationPolicyValues = NTLMAuthenticationPolicyValues.Disabled; lmAuthenticationPolicyValues = LMAuthenticationPolicyValues.Disabled; } else if (implicitNtlmVersion == ImplicitNtlmVersion.NtlmVersion1) { ntlmAuthenticationPolicyValues = NTLMAuthenticationPolicyValues.Disabled; lmAuthenticationPolicyValues = LMAuthenticationPolicyValues.LmEnabled; } // ntlm version 2 else { ntlmAuthenticationPolicyValues = NTLMAuthenticationPolicyValues.NtlmV2Enabled; lmAuthenticationPolicyValues = LMAuthenticationPolicyValues.LmV2Enabled; } return new SmbSessionSetupImplicitNtlmAndxRequestPacket( this.cifsClient.CreateSessionSetupAndxRequest( messageId, (SmbFlags)flags, (SmbFlags2)flags2, maxBufferSize, maxMpxCount, 0, 0, (Cifs.Capabilities)capabilities, new CifsUserAccount(domainName, userName, password), "\0", "\0", null, ntlmAuthenticationPolicyValues, lmAuthenticationPolicyValues)); }