NegotiateResponseExtended.cs 4.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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_NEGOTIATE Response, NT LAN Manager dialect, Extended Security response
  15. /// </summary>
  16. public class NegotiateResponseExtended : SMB1Command
  17. {
  18. public const int ParametersLength = 34;
  19. // Parameters:
  20. public ushort DialectIndex;
  21. public SecurityMode SecurityMode;
  22. public ushort MaxMpxCount;
  23. public ushort MaxNumberVcs;
  24. public uint MaxBufferSize;
  25. public uint MaxRawSize;
  26. public uint SessionKey;
  27. public Capabilities Capabilities;
  28. public DateTime SystemTime;
  29. public short ServerTimeZone;
  30. private byte ChallengeLength; // MUST be set to 0
  31. // Data:
  32. public Guid ServerGuid;
  33. public byte[] SecurityBlob; // [MS-SMB] 3.3.5.2: The server can leave SecurityBlob empty if not configured to send GSS token.
  34. public NegotiateResponseExtended() : base()
  35. {
  36. SecurityBlob = new byte[0];
  37. }
  38. public NegotiateResponseExtended(byte[] buffer, int offset) : base(buffer, offset, false)
  39. {
  40. DialectIndex = LittleEndianConverter.ToUInt16(this.SMBParameters, 0);
  41. SecurityMode = (SecurityMode)ByteReader.ReadByte(this.SMBParameters, 2);
  42. MaxMpxCount = LittleEndianConverter.ToUInt16(this.SMBParameters, 3);
  43. MaxNumberVcs = LittleEndianConverter.ToUInt16(this.SMBParameters, 5);
  44. MaxBufferSize = LittleEndianConverter.ToUInt32(this.SMBParameters, 7);
  45. MaxRawSize = LittleEndianConverter.ToUInt32(this.SMBParameters, 11);
  46. SessionKey = LittleEndianConverter.ToUInt32(this.SMBParameters, 15);
  47. Capabilities = (Capabilities)LittleEndianConverter.ToUInt32(this.SMBParameters, 19);
  48. SystemTime = FileTimeHelper.ReadFileTime(this.SMBParameters, 23);
  49. ServerTimeZone = LittleEndianConverter.ToInt16(this.SMBParameters, 31);
  50. ChallengeLength = ByteReader.ReadByte(this.SMBParameters, 33);
  51. ServerGuid = LittleEndianConverter.ToGuid(this.SMBData, 0);
  52. SecurityBlob = ByteReader.ReadBytes(this.SMBData, 16, this.SMBData.Length - 16);
  53. }
  54. public override byte[] GetBytes(bool isUnicode)
  55. {
  56. ChallengeLength = 0;
  57. this.SMBParameters = new byte[ParametersLength];
  58. LittleEndianWriter.WriteUInt16(this.SMBParameters, 0, DialectIndex);
  59. ByteWriter.WriteByte(this.SMBParameters, 2, (byte)SecurityMode);
  60. LittleEndianWriter.WriteUInt16(this.SMBParameters, 3, MaxMpxCount);
  61. LittleEndianWriter.WriteUInt16(this.SMBParameters, 5, MaxNumberVcs);
  62. LittleEndianWriter.WriteUInt32(this.SMBParameters, 7, MaxBufferSize);
  63. LittleEndianWriter.WriteUInt32(this.SMBParameters, 11, MaxRawSize);
  64. LittleEndianWriter.WriteUInt32(this.SMBParameters, 15, SessionKey);
  65. LittleEndianWriter.WriteUInt32(this.SMBParameters, 19, (uint)Capabilities);
  66. FileTimeHelper.WriteFileTime(this.SMBParameters, 23, SystemTime);
  67. LittleEndianWriter.WriteInt16(this.SMBParameters, 31, ServerTimeZone);
  68. ByteWriter.WriteByte(this.SMBParameters, 33, ChallengeLength);
  69. this.SMBData = new byte[16 + SecurityBlob.Length];
  70. LittleEndianWriter.WriteGuidBytes(this.SMBData, 0, ServerGuid);
  71. ByteWriter.WriteBytes(this.SMBData, 16, SecurityBlob);
  72. return base.GetBytes(isUnicode);
  73. }
  74. public override CommandName CommandName
  75. {
  76. get
  77. {
  78. return CommandName.SMB_COM_NEGOTIATE;
  79. }
  80. }
  81. }
  82. }