NTLMVersion.cs 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  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.Authentication.NTLM
  12. {
  13. /// <summary>
  14. /// [MS-NLMP] 2.2.2.10 - VERSION
  15. /// </summary>
  16. public class NTLMVersion
  17. {
  18. public const int Length = 8;
  19. public const byte NTLMSSP_REVISION_W2K3 = 0x0F;
  20. public byte ProductMajorVersion;
  21. public byte ProductMinorVersion;
  22. public ushort ProductBuild;
  23. // Reserved - 3 bytes
  24. public byte NTLMRevisionCurrent;
  25. public NTLMVersion(byte majorVersion, byte minorVersion, ushort build, byte ntlmRevisionCurrent)
  26. {
  27. ProductMajorVersion = majorVersion;
  28. ProductMinorVersion = minorVersion;
  29. ProductBuild = build;
  30. NTLMRevisionCurrent = ntlmRevisionCurrent;
  31. }
  32. public NTLMVersion(byte[] buffer, int offset)
  33. {
  34. ProductMajorVersion = ByteReader.ReadByte(buffer, offset + 0);
  35. ProductMinorVersion = ByteReader.ReadByte(buffer, offset + 1);
  36. ProductBuild = LittleEndianConverter.ToUInt16(buffer, offset + 2);
  37. NTLMRevisionCurrent = ByteReader.ReadByte(buffer, offset + 7);
  38. }
  39. public void WriteBytes(byte[] buffer, int offset)
  40. {
  41. ByteWriter.WriteByte(buffer, offset + 0, ProductMajorVersion);
  42. ByteWriter.WriteByte(buffer, offset + 1, ProductMinorVersion);
  43. LittleEndianWriter.WriteUInt16(buffer, offset + 2, ProductBuild);
  44. ByteWriter.WriteByte(buffer, offset + 7, NTLMRevisionCurrent);
  45. }
  46. public override string ToString()
  47. {
  48. return String.Format("{0}.{1}.{2}", ProductMajorVersion, ProductMinorVersion, ProductBuild);
  49. }
  50. public static NTLMVersion WindowsXP
  51. {
  52. get
  53. {
  54. return new NTLMVersion(5, 1, 2600, NTLMSSP_REVISION_W2K3);
  55. }
  56. }
  57. public static NTLMVersion Server2003
  58. {
  59. get
  60. {
  61. return new NTLMVersion(5, 2, 3790, NTLMSSP_REVISION_W2K3);
  62. }
  63. }
  64. }
  65. }