ntlm.js 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  1. "use strict";
  2. Object.defineProperty(exports, "__esModule", {
  3. value: true
  4. });
  5. exports.createNTLMRequest = createNTLMRequest;
  6. const NTLMFlags = {
  7. NTLM_NegotiateUnicode: 0x00000001,
  8. NTLM_NegotiateOEM: 0x00000002,
  9. NTLM_RequestTarget: 0x00000004,
  10. NTLM_Unknown9: 0x00000008,
  11. NTLM_NegotiateSign: 0x00000010,
  12. NTLM_NegotiateSeal: 0x00000020,
  13. NTLM_NegotiateDatagram: 0x00000040,
  14. NTLM_NegotiateLanManagerKey: 0x00000080,
  15. NTLM_Unknown8: 0x00000100,
  16. NTLM_NegotiateNTLM: 0x00000200,
  17. NTLM_NegotiateNTOnly: 0x00000400,
  18. NTLM_Anonymous: 0x00000800,
  19. NTLM_NegotiateOemDomainSupplied: 0x00001000,
  20. NTLM_NegotiateOemWorkstationSupplied: 0x00002000,
  21. NTLM_Unknown6: 0x00004000,
  22. NTLM_NegotiateAlwaysSign: 0x00008000,
  23. NTLM_TargetTypeDomain: 0x00010000,
  24. NTLM_TargetTypeServer: 0x00020000,
  25. NTLM_TargetTypeShare: 0x00040000,
  26. NTLM_NegotiateExtendedSecurity: 0x00080000,
  27. NTLM_NegotiateIdentify: 0x00100000,
  28. NTLM_Unknown5: 0x00200000,
  29. NTLM_RequestNonNTSessionKey: 0x00400000,
  30. NTLM_NegotiateTargetInfo: 0x00800000,
  31. NTLM_Unknown4: 0x01000000,
  32. NTLM_NegotiateVersion: 0x02000000,
  33. NTLM_Unknown3: 0x04000000,
  34. NTLM_Unknown2: 0x08000000,
  35. NTLM_Unknown1: 0x10000000,
  36. NTLM_Negotiate128: 0x20000000,
  37. NTLM_NegotiateKeyExchange: 0x40000000,
  38. NTLM_Negotiate56: 0x80000000
  39. };
  40. function createNTLMRequest(options) {
  41. const domain = escape(options.domain.toUpperCase());
  42. const workstation = options.workstation ? escape(options.workstation.toUpperCase()) : '';
  43. let type1flags = NTLMFlags.NTLM_NegotiateUnicode + NTLMFlags.NTLM_NegotiateOEM + NTLMFlags.NTLM_RequestTarget + NTLMFlags.NTLM_NegotiateNTLM + NTLMFlags.NTLM_NegotiateOemDomainSupplied + NTLMFlags.NTLM_NegotiateOemWorkstationSupplied + NTLMFlags.NTLM_NegotiateAlwaysSign + NTLMFlags.NTLM_NegotiateVersion + NTLMFlags.NTLM_NegotiateExtendedSecurity + NTLMFlags.NTLM_Negotiate128 + NTLMFlags.NTLM_Negotiate56;
  44. if (workstation === '') {
  45. type1flags -= NTLMFlags.NTLM_NegotiateOemWorkstationSupplied;
  46. }
  47. const fixedData = Buffer.alloc(40);
  48. const buffers = [fixedData];
  49. let offset = 0;
  50. offset += fixedData.write('NTLMSSP', offset, 7, 'ascii');
  51. offset = fixedData.writeUInt8(0, offset);
  52. offset = fixedData.writeUInt32LE(1, offset);
  53. offset = fixedData.writeUInt32LE(type1flags, offset);
  54. offset = fixedData.writeUInt16LE(domain.length, offset);
  55. offset = fixedData.writeUInt16LE(domain.length, offset);
  56. offset = fixedData.writeUInt32LE(fixedData.length + workstation.length, offset);
  57. offset = fixedData.writeUInt16LE(workstation.length, offset);
  58. offset = fixedData.writeUInt16LE(workstation.length, offset);
  59. offset = fixedData.writeUInt32LE(fixedData.length, offset);
  60. offset = fixedData.writeUInt8(5, offset);
  61. offset = fixedData.writeUInt8(0, offset);
  62. offset = fixedData.writeUInt16LE(2195, offset);
  63. offset = fixedData.writeUInt8(0, offset);
  64. offset = fixedData.writeUInt8(0, offset);
  65. offset = fixedData.writeUInt8(0, offset);
  66. fixedData.writeUInt8(15, offset);
  67. buffers.push(Buffer.from(workstation, 'ascii'));
  68. buffers.push(Buffer.from(domain, 'ascii'));
  69. return Buffer.concat(buffers);
  70. }