SessionSetupAndXRequestExtended.cs 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. /* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using System.Text;
  10. using Utilities;
  11. namespace SMBLibrary.SMB1
  12. {
  13. /// <summary>
  14. /// SMB_COM_SESSION_SETUP_ANDX Extended Request
  15. /// </summary>
  16. public class SessionSetupAndXRequestExtended : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 24;
  19. // Parameters:
  20. public ushort MaxBufferSize;
  21. public ushort MaxMpxCount;
  22. public ushort VcNumber;
  23. public uint SessionKey;
  24. //ushort SecurityBlobLength;
  25. public uint Reserved;
  26. public ServerCapabilities Capabilities;
  27. // Data:
  28. public byte[] SecurityBlob;
  29. 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)
  30. public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  31. public SessionSetupAndXRequestExtended(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  32. {
  33. MaxBufferSize = LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
  34. MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 6);
  35. VcNumber = LittleEndianConverter.ToUInt16(this.SMBParameters, 8);
  36. SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 10);
  37. ushort securityBlobLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 14);
  38. Reserved = LittleEndianConverter.ToUInt32(this.SMBParameters, 16);
  39. Capabilities = (ServerCapabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 20);
  40. SecurityBlob = ByteReader.ReadBytes(this.SMBData, 0, securityBlobLength);
  41. int dataOffset = SecurityBlob.Length;
  42. if (isUnicode)
  43. {
  44. // when a Unicode string is passed it MUST be aligned to a 16-bit boundary with respect to the beginning of the SMB Header.
  45. // Note: SMBData starts at an odd offset
  46. int padding = (securityBlobLength + 1) % 2;
  47. dataOffset += padding;
  48. }
  49. NativeOS = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  50. NativeLanMan = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  51. }
  52. public override CommandName CommandName
  53. {
  54. get
  55. {
  56. return CommandName.SMB_COM_SESSION_SETUP_ANDX;
  57. }
  58. }
  59. }
  60. }