NTLMVersion.cs 2.3 KB

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