SessionSetupAndXRequest.cs 3.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. /* Copyright (C) 2014 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 Request
  15. /// </summary>
  16. public class SessionSetupAndXRequest : SMBAndXCommand
  17. {
  18. public const int ParametersLength = 26;
  19. // Parameters:
  20. public ushort MaxBufferSize;
  21. public ushort MaxMpxCount;
  22. public ushort VcNumber;
  23. public uint SessionKey;
  24. //ushort OEMPasswordLength;
  25. //ushort UnicodePasswordLength;
  26. public uint Reserved;
  27. public ServerCapabilities Capabilities;
  28. // Data:
  29. public byte[] OEMPassword;
  30. public byte[] UnicodePassword;
  31. // Padding
  32. public string AccountName; // SMB_STRING (If Unicode, this field MUST be aligned to start on a 2-byte boundary from the start of the SMB header)
  33. public string PrimaryDomain; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  34. public string NativeOS; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  35. public string NativeLanMan; // SMB_STRING (this field WILL be aligned to start on a 2-byte boundary from the start of the SMB header)
  36. public SessionSetupAndXRequest(byte[] buffer, int offset, bool isUnicode) : base(buffer, offset, isUnicode)
  37. {
  38. MaxBufferSize = LittleEndianConverter.ToUInt16(this.SMBParameters, 4);
  39. MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 6);
  40. VcNumber = LittleEndianConverter.ToUInt16(this.SMBParameters, 8);
  41. SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 10);
  42. ushort OEMPasswordLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 14);
  43. ushort UnicodePasswordLength = LittleEndianConverter.ToUInt16(this.SMBParameters, 16);
  44. Reserved = LittleEndianConverter.ToUInt32(this.SMBParameters, 18);
  45. Capabilities = (ServerCapabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 22);
  46. OEMPassword = ByteReader.ReadBytes(this.SMBData, 0, OEMPasswordLength);
  47. UnicodePassword = ByteReader.ReadBytes(this.SMBData, OEMPasswordLength, UnicodePasswordLength);
  48. int dataOffset = OEMPasswordLength + UnicodePasswordLength;
  49. if (isUnicode)
  50. {
  51. // wordCount is 1 byte
  52. int padding = (1 + OEMPasswordLength + UnicodePasswordLength) % 2;
  53. dataOffset += padding;
  54. }
  55. AccountName = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  56. PrimaryDomain = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  57. NativeOS = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  58. NativeLanMan = SMB1Helper.ReadSMBString(this.SMBData, ref dataOffset, isUnicode);
  59. }
  60. public override CommandName CommandName
  61. {
  62. get
  63. {
  64. return CommandName.SMB_COM_SESSION_SETUP_ANDX;
  65. }
  66. }
  67. }
  68. }