SMB1: Transaction requests to the NamedPipeStore will not be blocked at the SMB layer

This commit is contained in:
Tal Aloni 2017-02-11 13:10:45 +02:00
parent fbea16545f
commit 384efe97e7
2 changed files with 37 additions and 32 deletions

View file

@ -15,7 +15,7 @@ namespace SMBLibrary.Server.SMB1
{ {
public class Transaction2SubcommandHelper public class Transaction2SubcommandHelper
{ {
internal static Transaction2FindFirst2Response GetSubcommandResponse(SMB1Header header, Transaction2FindFirst2Request subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2FindFirst2Response GetSubcommandResponse(SMB1Header header, Transaction2FindFirst2Request subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
string fileNamePattern = subcommand.FileName; string fileNamePattern = subcommand.FileName;
@ -79,7 +79,7 @@ namespace SMBLibrary.Server.SMB1
return response; return response;
} }
internal static Transaction2FindNext2Response GetSubcommandResponse(SMB1Header header, Transaction2FindNext2Request subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2FindNext2Response GetSubcommandResponse(SMB1Header header, Transaction2FindNext2Request subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
OpenSearch openSearch = session.GetOpenSearch(subcommand.SID); OpenSearch openSearch = session.GetOpenSearch(subcommand.SID);
@ -115,13 +115,16 @@ namespace SMBLibrary.Server.SMB1
return response; return response;
} }
internal static Transaction2QueryFSInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFSInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2QueryFSInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFSInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
if (!share.HasReadAccess(session.UserName, @"\", state.ClientEndPoint)) if (share is FileSystemShare)
{ {
header.Status = NTStatus.STATUS_ACCESS_DENIED; if (!((FileSystemShare)share).HasReadAccess(session.UserName, @"\", state.ClientEndPoint))
return null; {
header.Status = NTStatus.STATUS_ACCESS_DENIED;
return null;
}
} }
Transaction2QueryFSInformationResponse response = new Transaction2QueryFSInformationResponse(); Transaction2QueryFSInformationResponse response = new Transaction2QueryFSInformationResponse();
@ -137,15 +140,19 @@ namespace SMBLibrary.Server.SMB1
return response; return response;
} }
internal static Transaction2QueryPathInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryPathInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2QueryPathInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryPathInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
string path = subcommand.FileName; string path = subcommand.FileName;
if (!share.HasReadAccess(session.UserName, path, state.ClientEndPoint)) if (share is FileSystemShare)
{ {
header.Status = NTStatus.STATUS_ACCESS_DENIED; if (!((FileSystemShare)share).HasReadAccess(session.UserName, path, state.ClientEndPoint))
return null; {
header.Status = NTStatus.STATUS_ACCESS_DENIED;
return null;
}
} }
Transaction2QueryPathInformationResponse response = new Transaction2QueryPathInformationResponse(); Transaction2QueryPathInformationResponse response = new Transaction2QueryPathInformationResponse();
QueryInformation queryInformation; QueryInformation queryInformation;
NTStatus queryStatus = SMB1FileStoreHelper.GetFileInformation(out queryInformation, share.FileStore, path, subcommand.InformationLevel); NTStatus queryStatus = SMB1FileStoreHelper.GetFileInformation(out queryInformation, share.FileStore, path, subcommand.InformationLevel);
@ -159,7 +166,7 @@ namespace SMBLibrary.Server.SMB1
return response; return response;
} }
internal static Transaction2QueryFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFileInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2QueryFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2QueryFileInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID); OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
@ -169,10 +176,13 @@ namespace SMBLibrary.Server.SMB1
return null; return null;
} }
if (!share.HasReadAccess(session.UserName, openFile.Path, state.ClientEndPoint)) if (share is FileSystemShare)
{ {
header.Status = NTStatus.STATUS_ACCESS_DENIED; if (!((FileSystemShare)share).HasReadAccess(session.UserName, openFile.Path, state.ClientEndPoint))
return null; {
header.Status = NTStatus.STATUS_ACCESS_DENIED;
return null;
}
} }
Transaction2QueryFileInformationResponse response = new Transaction2QueryFileInformationResponse(); Transaction2QueryFileInformationResponse response = new Transaction2QueryFileInformationResponse();
@ -188,7 +198,7 @@ namespace SMBLibrary.Server.SMB1
return response; return response;
} }
internal static Transaction2SetFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2SetFileInformationRequest subcommand, FileSystemShare share, SMB1ConnectionState state) internal static Transaction2SetFileInformationResponse GetSubcommandResponse(SMB1Header header, Transaction2SetFileInformationRequest subcommand, ISMBShare share, SMB1ConnectionState state)
{ {
SMB1Session session = state.GetSession(header.UID); SMB1Session session = state.GetSession(header.UID);
OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID); OpenFileObject openFile = session.GetOpenFileObject(subcommand.FID);
@ -198,10 +208,13 @@ namespace SMBLibrary.Server.SMB1
return null; return null;
} }
if (!share.HasWriteAccess(session.UserName, openFile.Path, state.ClientEndPoint)) if (share is FileSystemShare)
{ {
header.Status = NTStatus.STATUS_ACCESS_DENIED; if (!((FileSystemShare)share).HasWriteAccess(session.UserName, openFile.Path, state.ClientEndPoint))
return null; {
header.Status = NTStatus.STATUS_ACCESS_DENIED;
return null;
}
} }
SetInformation information; SetInformation information;

View file

@ -195,29 +195,21 @@ namespace SMBLibrary.Server.SMB1
} }
Transaction2Subcommand subcommandResponse = null; Transaction2Subcommand subcommandResponse = null;
if (!(share is FileSystemShare))
{
header.Status = NTStatus.STATUS_INVALID_PARAMETER;
return new ErrorResponse(CommandName.SMB_COM_TRANSACTION2);
}
FileSystemShare fileSystemShare = (FileSystemShare)share;
if (subcommand is Transaction2FindFirst2Request) if (subcommand is Transaction2FindFirst2Request)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindFirst2Request)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindFirst2Request)subcommand, share, state);
} }
else if (subcommand is Transaction2FindNext2Request) else if (subcommand is Transaction2FindNext2Request)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindNext2Request)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2FindNext2Request)subcommand, share, state);
} }
else if (subcommand is Transaction2QueryFSInformationRequest) else if (subcommand is Transaction2QueryFSInformationRequest)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFSInformationRequest)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFSInformationRequest)subcommand, share, state);
} }
else if (subcommand is Transaction2QueryPathInformationRequest) else if (subcommand is Transaction2QueryPathInformationRequest)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryPathInformationRequest)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryPathInformationRequest)subcommand, share, state);
} }
else if (subcommand is Transaction2SetPathInformationRequest) else if (subcommand is Transaction2SetPathInformationRequest)
{ {
@ -225,11 +217,11 @@ namespace SMBLibrary.Server.SMB1
} }
else if (subcommand is Transaction2QueryFileInformationRequest) else if (subcommand is Transaction2QueryFileInformationRequest)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFileInformationRequest)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2QueryFileInformationRequest)subcommand, share, state);
} }
else if (subcommand is Transaction2SetFileInformationRequest) else if (subcommand is Transaction2SetFileInformationRequest)
{ {
subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2SetFileInformationRequest)subcommand, fileSystemShare, state); subcommandResponse = Transaction2SubcommandHelper.GetSubcommandResponse(header, (Transaction2SetFileInformationRequest)subcommand, share, state);
} }
else if (subcommand is Transaction2CreateDirectoryRequest) else if (subcommand is Transaction2CreateDirectoryRequest)
{ {