Server: Added option to enable SMB 3.0

This commit is contained in:
TalAloni 2020-11-28 22:00:44 +02:00
parent 7438ccdf4f
commit fc3a4341f9
4 changed files with 26 additions and 6 deletions

View file

@ -7,5 +7,6 @@ namespace SMBLibrary.Server
NTLM012, // NT LM 0.12 NTLM012, // NT LM 0.12
SMB202, // SMB 2.0.2 SMB202, // SMB 2.0.2
SMB210, // SMB 2.1 SMB210, // SMB 2.1
SMB300, // SMB 3.0
} }
} }

View file

@ -73,10 +73,15 @@ namespace SMBLibrary.Server.SMB2
return response; return response;
} }
internal static SMB2Command GetNegotiateResponse(NegotiateRequest request, GSSProvider securityProvider, ConnectionState state, SMBTransportType transportType, Guid serverGuid, DateTime serverStartTime) internal static SMB2Command GetNegotiateResponse(NegotiateRequest request, GSSProvider securityProvider, ConnectionState state, SMBTransportType transportType, Guid serverGuid, DateTime serverStartTime, bool enableSMB3)
{ {
NegotiateResponse response = new NegotiateResponse(); NegotiateResponse response = new NegotiateResponse();
if (request.Dialects.Contains(SMB2Dialect.SMB210)) if (enableSMB3 && request.Dialects.Contains(SMB2Dialect.SMB300))
{
state.Dialect = SMBDialect.SMB300;
response.DialectRevision = SMB2Dialect.SMB300;
}
else if (request.Dialects.Contains(SMB2Dialect.SMB210))
{ {
state.Dialect = SMBDialect.SMB210; state.Dialect = SMBDialect.SMB210;
response.DialectRevision = SMB2Dialect.SMB210; response.DialectRevision = SMB2Dialect.SMB210;

View file

@ -83,7 +83,7 @@ namespace SMBLibrary.Server
if (command is NegotiateRequest) if (command is NegotiateRequest)
{ {
NegotiateRequest request = (NegotiateRequest)command; NegotiateRequest request = (NegotiateRequest)command;
SMB2Command response = NegotiateHelper.GetNegotiateResponse(request, m_securityProvider, state, m_transport, m_serverGuid, m_serverStartTime); SMB2Command response = NegotiateHelper.GetNegotiateResponse(request, m_securityProvider, state, m_transport, m_serverGuid, m_serverStartTime, m_enableSMB3);
if (state.Dialect != SMBDialect.NotSet) if (state.Dialect != SMBDialect.NotSet)
{ {
state = new SMB2ConnectionState(state); state = new SMB2ConnectionState(state);
@ -260,6 +260,8 @@ namespace SMBLibrary.Server
return SMB2Dialect.SMB202; return SMB2Dialect.SMB202;
case SMBDialect.SMB210: case SMBDialect.SMB210:
return SMB2Dialect.SMB210; return SMB2Dialect.SMB210;
case SMBDialect.SMB300:
return SMB2Dialect.SMB300;
default: default:
throw new ArgumentException("Unsupported SMB2 Dialect: " + smbDialect.ToString()); throw new ArgumentException("Unsupported SMB2 Dialect: " + smbDialect.ToString());
} }

View file

@ -38,6 +38,7 @@ namespace SMBLibrary.Server
private SMBTransportType m_transport; private SMBTransportType m_transport;
private bool m_enableSMB1; private bool m_enableSMB1;
private bool m_enableSMB2; private bool m_enableSMB2;
private bool m_enableSMB3;
private Socket m_listenerSocket; private Socket m_listenerSocket;
private bool m_listening; private bool m_listening;
private DateTime m_serverStartTime; private DateTime m_serverStartTime;
@ -61,7 +62,12 @@ namespace SMBLibrary.Server
public void Start(IPAddress serverAddress, SMBTransportType transport, bool enableSMB1, bool enableSMB2) public void Start(IPAddress serverAddress, SMBTransportType transport, bool enableSMB1, bool enableSMB2)
{ {
Start(serverAddress, transport, enableSMB1, enableSMB2, null); Start(serverAddress, transport, enableSMB1, enableSMB2, false);
}
public void Start(IPAddress serverAddress, SMBTransportType transport, bool enableSMB1, bool enableSMB2, bool enableSMB3)
{
Start(serverAddress, transport, enableSMB1, enableSMB2, enableSMB3, null);
} }
/// <param name="connectionInactivityTimeout"> /// <param name="connectionInactivityTimeout">
@ -70,15 +76,21 @@ namespace SMBLibrary.Server
/// to prevent such connections from hanging around indefinitely, this parameter can be used. /// to prevent such connections from hanging around indefinitely, this parameter can be used.
/// </param> /// </param>
/// <exception cref="System.Net.Sockets.SocketException"></exception> /// <exception cref="System.Net.Sockets.SocketException"></exception>
public void Start(IPAddress serverAddress, SMBTransportType transport, bool enableSMB1, bool enableSMB2, TimeSpan? connectionInactivityTimeout) public void Start(IPAddress serverAddress, SMBTransportType transport, bool enableSMB1, bool enableSMB2, bool enableSMB3, TimeSpan? connectionInactivityTimeout)
{ {
if (!m_listening) if (!m_listening)
{ {
if (enableSMB3 && !enableSMB2)
{
throw new ArgumentException("SMB2 must be enabled for SMB3 to be enabled");
}
Log(Severity.Information, "Starting server"); Log(Severity.Information, "Starting server");
m_serverAddress = serverAddress; m_serverAddress = serverAddress;
m_transport = transport; m_transport = transport;
m_enableSMB1 = enableSMB1; m_enableSMB1 = enableSMB1;
m_enableSMB2 = enableSMB2; m_enableSMB2 = enableSMB2;
m_enableSMB3 = enableSMB3;
m_listening = true; m_listening = true;
m_serverStartTime = DateTime.Now; m_serverStartTime = DateTime.Now;
@ -290,7 +302,7 @@ namespace SMBLibrary.Server
// Note: To be compatible with SMB2 specifications, we must accept SMB_COM_NEGOTIATE. // Note: To be compatible with SMB2 specifications, we must accept SMB_COM_NEGOTIATE.
// We will disconnect the connection if m_enableSMB1 == false and the client does not support SMB2. // We will disconnect the connection if m_enableSMB1 == false and the client does not support SMB2.
bool acceptSMB1 = (state.Dialect == SMBDialect.NotSet || state.Dialect == SMBDialect.NTLM012); bool acceptSMB1 = (state.Dialect == SMBDialect.NotSet || state.Dialect == SMBDialect.NTLM012);
bool acceptSMB2 = (m_enableSMB2 && (state.Dialect == SMBDialect.NotSet || state.Dialect == SMBDialect.SMB202 || state.Dialect == SMBDialect.SMB210)); bool acceptSMB2 = (m_enableSMB2 && (state.Dialect == SMBDialect.NotSet || state.Dialect == SMBDialect.SMB202 || state.Dialect == SMBDialect.SMB210 || state.Dialect == SMBDialect.SMB300));
if (SMB1Header.IsValidSMB1Header(packet.Trailer)) if (SMB1Header.IsValidSMB1Header(packet.Trailer))
{ {