Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions SMBLibrary/Client/Authentication/IAuthenticationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,7 @@ public interface IAuthenticationClient
byte[] InitializeSecurityContext(byte[] securityBlob);

byte[] GetSessionKey();

void ResetSecurityContext(string host);
}
}
8 changes: 8 additions & 0 deletions SMBLibrary/Client/Authentication/NTLMAuthenticationClient.cs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,14 @@ public virtual byte[] GetSessionKey()
return m_sessionKey;
}

public virtual void ResetSecurityContext(string host)
{
m_spn = string.Format("cifs/{0}", host);
m_isNegotiationMessageAcquired = false;
m_negotiateMessageBytes = null;
m_sessionKey = null;
}

private static bool ContainsMechanism(SimpleProtectedNegotiationTokenInit token, byte[] mechanismIdentifier)
{
for (int index = 0; index < token.MechanismTypeList.Count; index++)
Expand Down
15 changes: 15 additions & 0 deletions SMBLibrary/Client/SMB2Client.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,7 @@ public class SMB2Client : ISMBClient
private byte[] m_preauthIntegrityHashValue; // SMB 3.1.1
private ushort m_availableCredits = 1;
private bool m_connectionSupportsMultiCredit = false;
private IAuthenticationClient m_authenticationClient;

public SMB2Client() : this(DefaultResponseTimeoutInMilliseconds)
{
Expand Down Expand Up @@ -202,6 +203,7 @@ public void Disconnect()
m_sessionID = 0;
m_availableCredits = 1;
m_connectionSupportsMultiCredit = false;
m_authenticationClient = null;
}
}

Expand Down Expand Up @@ -298,6 +300,7 @@ public NTStatus Login(IAuthenticationClient authenticationClient)
{
m_sessionID = response.Header.SessionID;
m_sessionKey = authenticationClient.GetSessionKey();
m_authenticationClient = authenticationClient;
SessionFlags sessionFlags = finalSessionSetupResponse.SessionFlags;
if ((sessionFlags & SessionFlags.IsGuest) > 0)
{
Expand Down Expand Up @@ -339,6 +342,10 @@ public NTStatus Logoff()
if (response != null)
{
m_isLoggedIn = (response.Header.Status != NTStatus.STATUS_SUCCESS);
if (!m_isLoggedIn)
{
m_authenticationClient = null;
}
return response.Header.Status;
}
return NTStatus.STATUS_INVALID_SMB;
Expand Down Expand Up @@ -770,6 +777,14 @@ public bool IsConnected
}
}

public SMBTransportType Transport
{
get
{
return m_transport;
}
}

private void TrySendCommand(Socket socket, SMB2Command request, byte[] encryptionKey)
{
SessionMessagePacket packet = new SessionMessagePacket();
Expand Down