mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-06 17:43:17 +02:00
Client: Added support for single-stage and triple-stage session setup
Applicable when working with custom IAuthenticationClient
This commit is contained in:
parent
8b795d5233
commit
ab876da50f
2 changed files with 72 additions and 75 deletions
|
@ -316,9 +316,7 @@ namespace SMBLibrary.Client
|
||||||
TrySendMessage(request);
|
TrySendMessage(request);
|
||||||
|
|
||||||
SMB1Message reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
SMB1Message reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
||||||
if (reply != null)
|
while (reply != null && reply.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
||||||
{
|
|
||||||
if (reply.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
|
||||||
{
|
{
|
||||||
SessionSetupAndXResponseExtended response = (SessionSetupAndXResponseExtended)reply.Commands[0];
|
SessionSetupAndXResponseExtended response = (SessionSetupAndXResponseExtended)reply.Commands[0];
|
||||||
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(response.SecurityBlob);
|
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(response.SecurityBlob);
|
||||||
|
@ -326,7 +324,6 @@ namespace SMBLibrary.Client
|
||||||
{
|
{
|
||||||
return NTStatus.SEC_E_INVALID_TOKEN;
|
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||||
}
|
}
|
||||||
m_sessionKey = authenticationClient.GetSessionKey();
|
|
||||||
|
|
||||||
m_userID = reply.Header.UID;
|
m_userID = reply.Header.UID;
|
||||||
request = new SessionSetupAndXRequestExtended();
|
request = new SessionSetupAndXRequestExtended();
|
||||||
|
@ -337,20 +334,23 @@ namespace SMBLibrary.Client
|
||||||
TrySendMessage(request);
|
TrySendMessage(request);
|
||||||
|
|
||||||
reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
reply = WaitForMessage(CommandName.SMB_COM_SESSION_SETUP_ANDX);
|
||||||
if (reply != null)
|
}
|
||||||
|
|
||||||
|
if (reply != null && reply.Commands[0] is SessionSetupAndXResponseExtended)
|
||||||
{
|
{
|
||||||
m_isLoggedIn = (reply.Header.Status == NTStatus.STATUS_SUCCESS);
|
m_isLoggedIn = (reply.Header.Status == NTStatus.STATUS_SUCCESS);
|
||||||
return reply.Header.Status;
|
if (m_isLoggedIn)
|
||||||
|
{
|
||||||
|
m_sessionKey = authenticationClient.GetSessionKey();
|
||||||
}
|
}
|
||||||
|
return reply.Header.Status;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return reply.Header.Status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NTStatus.STATUS_INVALID_SMB;
|
return NTStatus.STATUS_INVALID_SMB;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public NTStatus Logoff()
|
public NTStatus Logoff()
|
||||||
{
|
{
|
||||||
|
|
|
@ -257,16 +257,13 @@ namespace SMBLibrary.Client
|
||||||
request.SecurityBuffer = negotiateMessage;
|
request.SecurityBuffer = negotiateMessage;
|
||||||
TrySendCommand(request);
|
TrySendCommand(request);
|
||||||
SMB2Command response = WaitForCommand(request.MessageID);
|
SMB2Command response = WaitForCommand(request.MessageID);
|
||||||
if (response != null)
|
while (response is SessionSetupResponse && response.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED)
|
||||||
{
|
|
||||||
if (response.Header.Status == NTStatus.STATUS_MORE_PROCESSING_REQUIRED && response is SessionSetupResponse)
|
|
||||||
{
|
{
|
||||||
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(((SessionSetupResponse)response).SecurityBuffer);
|
byte[] authenticateMessage = authenticationClient.InitializeSecurityContext(((SessionSetupResponse)response).SecurityBuffer);
|
||||||
if (authenticateMessage == null)
|
if (authenticateMessage == null)
|
||||||
{
|
{
|
||||||
return NTStatus.SEC_E_INVALID_TOKEN;
|
return NTStatus.SEC_E_INVALID_TOKEN;
|
||||||
}
|
}
|
||||||
m_sessionKey = authenticationClient.GetSessionKey();
|
|
||||||
|
|
||||||
m_sessionID = response.Header.SessionID;
|
m_sessionID = response.Header.SessionID;
|
||||||
request = new SessionSetupRequest();
|
request = new SessionSetupRequest();
|
||||||
|
@ -274,11 +271,14 @@ namespace SMBLibrary.Client
|
||||||
request.SecurityBuffer = authenticateMessage;
|
request.SecurityBuffer = authenticateMessage;
|
||||||
TrySendCommand(request);
|
TrySendCommand(request);
|
||||||
response = WaitForCommand(request.MessageID);
|
response = WaitForCommand(request.MessageID);
|
||||||
if (response != null)
|
}
|
||||||
|
|
||||||
|
if (response is SessionSetupResponse)
|
||||||
{
|
{
|
||||||
m_isLoggedIn = (response.Header.Status == NTStatus.STATUS_SUCCESS);
|
m_isLoggedIn = (response.Header.Status == NTStatus.STATUS_SUCCESS);
|
||||||
if (m_isLoggedIn)
|
if (m_isLoggedIn)
|
||||||
{
|
{
|
||||||
|
m_sessionKey = authenticationClient.GetSessionKey();
|
||||||
SessionFlags sessionFlags = ((SessionSetupResponse)response).SessionFlags;
|
SessionFlags sessionFlags = ((SessionSetupResponse)response).SessionFlags;
|
||||||
if ((sessionFlags & SessionFlags.IsGuest) > 0)
|
if ((sessionFlags & SessionFlags.IsGuest) > 0)
|
||||||
{
|
{
|
||||||
|
@ -300,14 +300,11 @@ namespace SMBLibrary.Client
|
||||||
}
|
}
|
||||||
return response.Header.Status;
|
return response.Header.Status;
|
||||||
}
|
}
|
||||||
}
|
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return response.Header.Status;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return NTStatus.STATUS_INVALID_SMB;
|
return NTStatus.STATUS_INVALID_SMB;
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
public NTStatus Logoff()
|
public NTStatus Logoff()
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue