mirror of
https://github.com/TalAloni/SMBLibrary.git
synced 2025-07-14 05:15:03 +02:00
Properly handle NegotiateRequest
This commit is contained in:
parent
4722555728
commit
30ce7ff79c
2 changed files with 33 additions and 7 deletions
|
@ -15,17 +15,25 @@ namespace SMBLibrary.Server
|
||||||
{
|
{
|
||||||
public delegate void LogDelegate(Severity severity, string message);
|
public delegate void LogDelegate(Severity severity, string message);
|
||||||
|
|
||||||
|
public enum SMBDialect
|
||||||
|
{
|
||||||
|
NotSet,
|
||||||
|
NTLM012, // NT LM 0.12
|
||||||
|
}
|
||||||
|
|
||||||
public class ConnectionState
|
public class ConnectionState
|
||||||
{
|
{
|
||||||
public Socket ClientSocket;
|
public Socket ClientSocket;
|
||||||
public IPEndPoint ClientEndPoint;
|
public IPEndPoint ClientEndPoint;
|
||||||
public NBTConnectionReceiveBuffer ReceiveBuffer;
|
public NBTConnectionReceiveBuffer ReceiveBuffer;
|
||||||
protected LogDelegate LogToServerHandler;
|
protected LogDelegate LogToServerHandler;
|
||||||
|
public SMBDialect ServerDialect;
|
||||||
|
|
||||||
public ConnectionState(LogDelegate logToServerHandler)
|
public ConnectionState(LogDelegate logToServerHandler)
|
||||||
{
|
{
|
||||||
ReceiveBuffer = new NBTConnectionReceiveBuffer();
|
ReceiveBuffer = new NBTConnectionReceiveBuffer();
|
||||||
LogToServerHandler = logToServerHandler;
|
LogToServerHandler = logToServerHandler;
|
||||||
|
ServerDialect = SMBDialect.NotSet;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ConnectionState(ConnectionState state)
|
public ConnectionState(ConnectionState state)
|
||||||
|
@ -34,6 +42,7 @@ namespace SMBLibrary.Server
|
||||||
ClientEndPoint = state.ClientEndPoint;
|
ClientEndPoint = state.ClientEndPoint;
|
||||||
ReceiveBuffer = state.ReceiveBuffer;
|
ReceiveBuffer = state.ReceiveBuffer;
|
||||||
LogToServerHandler = state.LogToServerHandler;
|
LogToServerHandler = state.LogToServerHandler;
|
||||||
|
ServerDialect = state.ServerDialect;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void LogToServer(Severity severity, string message)
|
public void LogToServer(Severity severity, string message)
|
||||||
|
|
|
@ -53,25 +53,42 @@ namespace SMBLibrary.Server
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public SMB1Command ProcessSMB1Command(SMB1Header header, SMB1Command command, SMB1ConnectionState state, List<SMB1Command> sendQueue)
|
public SMB1Command ProcessSMB1Command(SMB1Header header, SMB1Command command, SMB1ConnectionState state, List<SMB1Command> sendQueue)
|
||||||
{
|
{
|
||||||
if (command is NegotiateRequest)
|
if (state.ServerDialect == SMBDialect.NotSet)
|
||||||
{
|
{
|
||||||
NegotiateRequest request = (NegotiateRequest)command;
|
if (command is NegotiateRequest)
|
||||||
if (request.Dialects.Contains(SMBServer.NTLanManagerDialect))
|
|
||||||
{
|
{
|
||||||
if (EnableExtendedSecurity && header.ExtendedSecurityFlag)
|
NegotiateRequest request = (NegotiateRequest)command;
|
||||||
|
if (request.Dialects.Contains(SMBServer.NTLanManagerDialect))
|
||||||
{
|
{
|
||||||
return NegotiateHelper.GetNegotiateResponseExtended(request, m_serverGuid);
|
state.ServerDialect = SMBDialect.NTLM012;
|
||||||
|
if (EnableExtendedSecurity && header.ExtendedSecurityFlag)
|
||||||
|
{
|
||||||
|
return NegotiateHelper.GetNegotiateResponseExtended(request, m_serverGuid);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return NegotiateHelper.GetNegotiateResponse(header, request, m_users);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return NegotiateHelper.GetNegotiateResponse(header, request, m_users);
|
return new NegotiateResponseNotSupported();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return new NegotiateResponseNotSupported();
|
// [MS-CIFS] An SMB_COM_NEGOTIATE exchange MUST be completed before any other SMB messages are sent to the server
|
||||||
|
header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
|
||||||
|
return new ErrorResponse(command.CommandName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else if (command is NegotiateRequest)
|
||||||
|
{
|
||||||
|
// There MUST be only one SMB_COM_NEGOTIATE exchange per SMB connection.
|
||||||
|
// Subsequent SMB_COM_NEGOTIATE requests received by the server MUST be rejected with error responses.
|
||||||
|
header.Status = NTStatus.STATUS_SMB_BAD_COMMAND;
|
||||||
|
return new ErrorResponse(command.CommandName);
|
||||||
|
}
|
||||||
else if (command is SessionSetupAndXRequest)
|
else if (command is SessionSetupAndXRequest)
|
||||||
{
|
{
|
||||||
SessionSetupAndXRequest request = (SessionSetupAndXRequest)command;
|
SessionSetupAndXRequest request = (SessionSetupAndXRequest)command;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue