From b3445530ac28f14e6ec6c9134bedd56183e8bfa3 Mon Sep 17 00:00:00 2001 From: Tal Aloni Date: Fri, 1 Sep 2017 18:38:42 +0300 Subject: [PATCH] SMB1: Minor implementation improvements --- .../SMB1/Commands/SessionSetupAndXRequestExtended.cs | 4 ++-- SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs | 11 +++++++---- .../SMB1/Commands/SessionSetupAndXResponseExtended.cs | 9 +++++---- SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs | 2 +- SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs | 2 +- SMBLibrary/SMB1/SMB1Header.cs | 11 +++++++++++ 6 files changed, 27 insertions(+), 12 deletions(-) diff --git a/SMBLibrary/SMB1/Commands/SessionSetupAndXRequestExtended.cs b/SMBLibrary/SMB1/Commands/SessionSetupAndXRequestExtended.cs index 72b0dbb..159ba56 100644 --- a/SMBLibrary/SMB1/Commands/SessionSetupAndXRequestExtended.cs +++ b/SMBLibrary/SMB1/Commands/SessionSetupAndXRequestExtended.cs @@ -27,8 +27,8 @@ namespace SMBLibrary.SMB1 public ServerCapabilities Capabilities; // Data: public byte[] SecurityBlob; - public string NativeOS; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) - public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeOS = String.Empty; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeLanMan = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) public SessionSetupAndXRequestExtended(): base() { diff --git a/SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs b/SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs index b88117b..76d2e44 100644 --- a/SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs +++ b/SMBLibrary/SMB1/Commands/SessionSetupAndXResponse.cs @@ -11,6 +11,9 @@ using Utilities; namespace SMBLibrary.SMB1 { + /// + /// SMB_COM_SESSION_SETUP_ANDX Response + /// public class SessionSetupAndXResponse : SMBAndXCommand { public const int ParametersLength = 6; @@ -20,9 +23,9 @@ namespace SMBLibrary.SMB1 //ushort AndXOffset; public SessionSetupAction Action; // Data: - public string NativeOS; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) - public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) - public string PrimaryDomain; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeOS = String.Empty; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeLanMan = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) + public string PrimaryDomain = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) public SessionSetupAndXResponse() : base() { @@ -62,7 +65,7 @@ namespace SMBLibrary.SMB1 { this.SMBData = new byte[NativeOS.Length + NativeLanMan.Length + PrimaryDomain.Length + 3]; } - SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS); + SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeOS); SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, NativeLanMan); SMB1Helper.WriteSMBString(this.SMBData, ref offset, isUnicode, PrimaryDomain); diff --git a/SMBLibrary/SMB1/Commands/SessionSetupAndXResponseExtended.cs b/SMBLibrary/SMB1/Commands/SessionSetupAndXResponseExtended.cs index dd0c5ea..c77e177 100644 --- a/SMBLibrary/SMB1/Commands/SessionSetupAndXResponseExtended.cs +++ b/SMBLibrary/SMB1/Commands/SessionSetupAndXResponseExtended.cs @@ -11,6 +11,9 @@ using Utilities; namespace SMBLibrary.SMB1 { + /// + /// SMB_COM_SESSION_SETUP_ANDX Response, NT LAN Manager dialect, Extended Security response + /// public class SessionSetupAndXResponseExtended : SMBAndXCommand { public const int ParametersLength = 8; @@ -22,14 +25,12 @@ namespace SMBLibrary.SMB1 private ushort SecurityBlobLength; // Data: public byte[] SecurityBlob; - public string NativeOS; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) - public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeOS = String.Empty; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header) + public string NativeLanMan = String.Empty; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header) public SessionSetupAndXResponseExtended() : base() { SecurityBlob = new byte[0]; - NativeOS = String.Empty; - NativeLanMan = String.Empty; } public SessionSetupAndXResponseExtended(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode) diff --git a/SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs b/SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs index 63e0927..952fc03 100644 --- a/SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs +++ b/SMBLibrary/SMB1/Commands/WriteRawFinalResponse.cs @@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1 /// public class WriteRawFinalResponse : SMB1Command { - public ushort ParametersLength = 2; + public const ushort ParametersLength = 2; // Parameters; public ushort Count; diff --git a/SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs b/SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs index f8a3caa..5889a39 100644 --- a/SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs +++ b/SMBLibrary/SMB1/Commands/WriteRawInterimResponse.cs @@ -16,7 +16,7 @@ namespace SMBLibrary.SMB1 /// public class WriteRawInterimResponse : SMB1Command { - public ushort ParametersLength = 2; + public const ushort ParametersLength = 2; // Parameters; public ushort Available; diff --git a/SMBLibrary/SMB1/SMB1Header.cs b/SMBLibrary/SMB1/SMB1Header.cs index c1148c4..a81142b 100644 --- a/SMBLibrary/SMB1/SMB1Header.cs +++ b/SMBLibrary/SMB1/SMB1Header.cs @@ -114,6 +114,17 @@ namespace SMBLibrary.SMB1 { return (Flags2 & HeaderFlags2.Unicode) > 0; } + set + { + if (value) + { + this.Flags2 |= HeaderFlags2.Unicode; + } + else + { + this.Flags2 &= ~HeaderFlags2.Unicode; + } + } } public static bool IsValidSMB1Header(byte[] buffer)