1 | var rewire = require("rewire");
|
2 | var equal = require('deep-equal');
|
3 | var ntlm = rewire("./ntlm.js");
|
4 |
|
5 | function test_create_LM_hashed_password_v1() {
|
6 | console.log('> testing create_LM_hashed_password_v1');
|
7 | const create_LM_hashed_password_v1 = ntlm.__get__("create_LM_hashed_password_v1");
|
8 |
|
9 | var realResponse = create_LM_hashed_password_v1('Azx123456');
|
10 |
|
11 |
|
12 | var expectedResponse = Buffer.from([0xb7, 0xb4, 0x13, 0x5f, 0xa3, 0x05, 0x76, 0x82, 0x1e, 0x92, 0x9f, 0xfc, 0x01, 0x39, 0x51, 0x27]);
|
13 | return realResponse.equals(expectedResponse);
|
14 | }
|
15 |
|
16 | function test_create_LM_hashed_password_v1_longpassword() {
|
17 | console.log('> testing create_LM_hashed_password_v1 (long password)');
|
18 | const create_LM_hashed_password_v1 = ntlm.__get__("create_LM_hashed_password_v1");
|
19 |
|
20 | var realResponse = create_LM_hashed_password_v1('Azx123456Azx123456');
|
21 |
|
22 |
|
23 | var expectedResponse = Buffer.from([0xb7, 0xb4, 0x13, 0x5f, 0xa3, 0x05, 0x76, 0x82, 0x17, 0x48, 0x74, 0x2b, 0xc4, 0xcf, 0xed, 0x38]);
|
24 | return realResponse.equals(expectedResponse);
|
25 | }
|
26 |
|
27 | function test_createType1Message() {
|
28 | console.log('> testing createType1Message');
|
29 | const createType1Message = ntlm.__get__("createType1Message");
|
30 |
|
31 | var options = {
|
32 | url: "https://someurl.com",
|
33 | username: 'someUsername',
|
34 | password: 'stinks',
|
35 | workstation: 'choose.something',
|
36 | domain: 'someDomain'
|
37 | };
|
38 |
|
39 | var realResponse = createType1Message(options);
|
40 |
|
41 |
|
42 | var expectedResponse = "NTLM TlRMTVNTUAABAAAAB7IIogoACgA4AAAAEAAQACgAAAAFASgKAAAAD0NIT09TRS5TT01FVEhJTkdTT01FRE9NQUlO";
|
43 | return realResponse == expectedResponse;
|
44 | }
|
45 |
|
46 | function test_createType1Message_nodomain() {
|
47 | console.log('> testing createType1Message (no domain)');
|
48 | const createType1Message = ntlm.__get__("createType1Message");
|
49 |
|
50 | var options = {
|
51 | url: "https://someurl.com",
|
52 | username: 'm$',
|
53 | password: 'stinks',
|
54 | workstation: 'choose.something',
|
55 | domain: ''
|
56 | };
|
57 |
|
58 | var realResponse = createType1Message(options);
|
59 |
|
60 |
|
61 | var expectedResponse = "NTLM TlRMTVNTUAABAAAAB6IIogAAAAA4AAAAEAAQACgAAAAFASgKAAAAD0NIT09TRS5TT01FVEhJTkc=";
|
62 | return realResponse == expectedResponse;
|
63 | }
|
64 |
|
65 | function test_createType1Message_noworkstation() {
|
66 | console.log('> testing createType1Message (no workstation)');
|
67 | const createType1Message = ntlm.__get__("createType1Message");
|
68 |
|
69 | var options = {
|
70 | url: "https://someurl.com",
|
71 | username: 'm$',
|
72 | password: 'stinks',
|
73 | workstation: '',
|
74 | domain: ''
|
75 | };
|
76 |
|
77 | var realResponse = createType1Message(options);
|
78 |
|
79 |
|
80 | var expectedResponse = "NTLM TlRMTVNTUAABAAAAB6IIogAAAAAoAAAAAAAAACgAAAAFASgKAAAADw==";
|
81 | return realResponse == expectedResponse;
|
82 | }
|
83 |
|
84 |
|
85 |
|
86 |
|
87 | function test_parseType2Message() {
|
88 | console.log('> testing parseType2Message');
|
89 | const parseType2Message = ntlm.__get__("parseType2Message");
|
90 |
|
91 | var type2Message = 'NTLM ' +
|
92 | 'TlRMTVNTUAACAAAAHgAeADgAAAAFgoqiBevywvJykjAAAAAAAAAAAJgAmABWAAAA' +
|
93 | 'CgC6RwAAAA9EAEUAUwBLAFQATwBQAC0ASgBTADQAVQBKAFQARAACAB4ARABFAFMA' +
|
94 | 'SwBUAE8AUAAtAEoAUwA0AFUASgBUAEQAAQAeAEQARQBTAEsAVABPAFAALQBKAFMA' +
|
95 | 'NABVAEoAVABEAAQAHgBEAEUAUwBLAFQATwBQAC0ASgBTADQAVQBKAFQARAADAB4A' +
|
96 | 'RABFAFMASwBUAE8AUAAtAEoAUwA0AFUASgBUAEQABwAIADmguzCHn9UBAAAAAA==';
|
97 |
|
98 | var realResponse = parseType2Message(type2Message, function (err) {
|
99 | console.log(err);
|
100 | });
|
101 |
|
102 |
|
103 |
|
104 |
|
105 |
|
106 |
|
107 |
|
108 | var expectedResponse = {
|
109 | signature: Buffer.from([0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00]),
|
110 | type: 2,
|
111 | targetNameLen: 30,
|
112 | targetNameMaxLen: 30,
|
113 | targetNameOffset: 56,
|
114 | targetName: Buffer.from([0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00]),
|
115 | negotiateFlags: -1567981051,
|
116 | serverChallenge: Buffer.from([0x05, 0xeb, 0xf2, 0xc2, 0xf2, 0x72, 0x92, 0x30]),
|
117 | reserved: Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
118 | targetInfoLen: 152,
|
119 | targetInfoMaxLen: 152,
|
120 | targetInfoOffset: 86,
|
121 | targetInfo: Buffer.from([0x02, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x07, 0x00, 0x08, 0x00, 0x39, 0xa0, 0xbb, 0x30, 0x87, 0x9f, 0xd5, 0x01, 0x00, 0x00, 0x00, 0x00])
|
122 | };
|
123 |
|
124 | return equal(realResponse, expectedResponse);
|
125 | }
|
126 |
|
127 |
|
128 | function test_createType3Message() {
|
129 | console.log('> testing createType3Message');
|
130 | const createType3Message = ntlm.__get__("createType3Message");
|
131 |
|
132 | var mathMock = {
|
133 | random: function () {
|
134 | return 0.8092;
|
135 | },
|
136 | floor: Math.floor
|
137 | };
|
138 | ntlm.__set__("Math", mathMock);
|
139 |
|
140 | var dateMock = {
|
141 | now: function () {
|
142 | return 1679346960095;
|
143 | }
|
144 | };
|
145 | ntlm.__set__("Date", dateMock);
|
146 |
|
147 | var type2Message = {
|
148 | signature: Buffer.from([0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00]),
|
149 | type: 2,
|
150 | targetNameLen: 30,
|
151 | targetNameMaxLen: 30,
|
152 | targetNameOffset: 56,
|
153 | targetName: Buffer.from([0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00]),
|
154 | negotiateFlags: -1567981051,
|
155 | serverChallenge: Buffer.from([0x05, 0xeb, 0xf2, 0xc2, 0xf2, 0x72, 0x92, 0x30]),
|
156 | reserved: Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
157 | targetInfoLen: 152,
|
158 | targetInfoMaxLen: 152,
|
159 | targetInfoOffset: 86,
|
160 | targetInfo: Buffer.from([0x02, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x07, 0x00, 0x08, 0x00, 0x39, 0xa0, 0xbb, 0x30, 0x87, 0x9f, 0xd5, 0x01, 0x00, 0x00, 0x00, 0x00])
|
161 | };
|
162 |
|
163 | var options = {
|
164 | url: "https://someurl.com",
|
165 | username: 'm$',
|
166 | password: 'stinks',
|
167 | workstation: 'choose.something',
|
168 | domain: ''
|
169 | };
|
170 |
|
171 | var realResponse = createType3Message(type2Message, options);
|
172 |
|
173 |
|
174 | var expectedResponse = "NTLM TlRMTVNTUAADAAAAGAAYAGwAAADIAMgAhAAAAAAAAABIAAAABAAEAEgAAAAgACAATAAAAAAAAABMAQAABYKIogUBKAoAAAAPbQAkAEMASABPAE8AUwBFAC4AUwBPAE0ARQBUAEgASQBOAEcA34OQvQRxhMrl/ZdqHfdXsc/Pz8/Pz8/PBRktHt+/zDBHvSp4tqmfpwEBAAAAAAAA8OZaK3Fb2QHPz8/Pz8/PzwAAAAACAB4ARABFAFMASwBUAE8AUAAtAEoAUwA0AFUASgBUAEQAAQAeAEQARQBTAEsAVABPAFAALQBKAFMANABVAEoAVABEAAQAHgBEAEUAUwBLAFQATwBQAC0ASgBTADQAVQBKAFQARAADAB4ARABFAFMASwBUAE8AUAAtAEoAUwA0AFUASgBUAEQABwAIADmguzCHn9UBAAAAAAAAAAA=";
|
175 | return realResponse == expectedResponse;
|
176 | }
|
177 |
|
178 | function test_createType3Message_negotiateflagszero() {
|
179 | console.log('> testing createType3Message (negotiateFlags zero)');
|
180 | const createType3Message = ntlm.__get__("createType3Message");
|
181 |
|
182 | var mathMock = {
|
183 | random: function () {
|
184 | return 0.8092;
|
185 | },
|
186 | floor: Math.floor
|
187 | };
|
188 | ntlm.__set__("Math", mathMock);
|
189 |
|
190 | var dateMock = {
|
191 | now: function () {
|
192 | return 1679346960095;
|
193 | }
|
194 | };
|
195 | ntlm.__set__("Date", dateMock);
|
196 |
|
197 | var type2Message = {
|
198 | signature: Buffer.from([0x4e, 0x54, 0x4c, 0x4d, 0x53, 0x53, 0x50, 0x00]),
|
199 | type: 2,
|
200 | targetNameLen: 30,
|
201 | targetNameMaxLen: 30,
|
202 | targetNameOffset: 56,
|
203 | targetName: Buffer.from([0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00]),
|
204 | negotiateFlags: 0,
|
205 | serverChallenge: Buffer.from([0x05, 0xeb, 0xf2, 0xc2, 0xf2, 0x72, 0x92, 0x30]),
|
206 | reserved: Buffer.from([0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
207 | targetInfoLen: 152,
|
208 | targetInfoMaxLen: 152,
|
209 | targetInfoOffset: 86,
|
210 | targetInfo: Buffer.from([0x02, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x07, 0x00, 0x08, 0x00, 0x39, 0xa0, 0xbb, 0x30, 0x87, 0x9f, 0xd5, 0x01, 0x00, 0x00, 0x00, 0x00])
|
211 | };
|
212 |
|
213 | var options = {
|
214 | url: "https://someurl.com",
|
215 | username: 'm$',
|
216 | password: 'stinks',
|
217 | workstation: 'choose.something',
|
218 | domain: ''
|
219 | };
|
220 |
|
221 | var realResponse = createType3Message(type2Message, options);
|
222 |
|
223 |
|
224 | var expectedResponse = "NTLM TlRMTVNTUAADAAAAGAAYAFoAAAAYABgAcgAAAAAAAABIAAAAAgACAEgAAAAQABAASgAAAAAAAACKAAAABIKIogUBKAoAAAAPbSRDSE9PU0UuU09NRVRISU5HEBenAMbG/BJagLAbC+ssxjoV6DmoMZnLPnIxjabRKh2kis6avHJoHUvdnSQrhLYz";
|
225 | return realResponse == expectedResponse;
|
226 | }
|
227 |
|
228 | function test_insertZerosEvery7Bits() {
|
229 | console.log('> testing insertZerosEvery7Bits');
|
230 | const insertZerosEvery7Bits = ntlm.__get__("insertZerosEvery7Bits");
|
231 |
|
232 |
|
233 | var realResponse = insertZerosEvery7Bits(Buffer.from([0x41, 0x5a, 0x58, 0x31, 0x32, 0x33, 0x34]));
|
234 |
|
235 |
|
236 | var expectedResponse = Buffer.from([0x40, 0xac, 0x96, 0x06, 0x12, 0x90, 0xcc, 0x68]);
|
237 | return equal(realResponse, expectedResponse);
|
238 | }
|
239 |
|
240 | function test_bytes2binaryArray() {
|
241 | console.log('> testing bytes2binaryArray');
|
242 | const bytes2binaryArray = ntlm.__get__("bytes2binaryArray");
|
243 |
|
244 |
|
245 | var realResponse = bytes2binaryArray(Buffer.from([0x41, 0x5a, 0x58, 0x31, 0x32, 0x33, 0x34]));
|
246 |
|
247 |
|
248 | var expectedResponse = [
|
249 | 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1,
|
250 | 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0,
|
251 | 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1,
|
252 | 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1,
|
253 | 0, 0, 1, 1, 0, 1, 0, 0
|
254 | ];
|
255 | return equal(realResponse, expectedResponse);
|
256 | }
|
257 |
|
258 | function test_binaryArray2bytes() {
|
259 | console.log('> testing binaryArray2bytes');
|
260 | const binaryArray2bytes = ntlm.__get__("binaryArray2bytes");
|
261 |
|
262 |
|
263 | var realResponse = binaryArray2bytes([
|
264 | 0, 1, 0, 0, 0, 0, 0, 1, 0, 1, 0, 1,
|
265 | 1, 0, 1, 0, 0, 1, 0, 1, 1, 0, 0, 0,
|
266 | 0, 0, 1, 1, 0, 0, 0, 1, 0, 0, 1, 1,
|
267 | 0, 0, 1, 0, 0, 0, 1, 1, 0, 0, 1, 1,
|
268 | 0, 0, 1, 1, 0, 1, 0, 0
|
269 | ]);
|
270 |
|
271 |
|
272 | var expectedResponse = Buffer.from([0x41, 0x5a, 0x58, 0x31, 0x32, 0x33, 0x34]);
|
273 | return equal(realResponse, expectedResponse);
|
274 | }
|
275 |
|
276 | function test_create_NT_hashed_password_v1() {
|
277 | console.log('> testing create_NT_hashed_password_v1');
|
278 | const create_NT_hashed_password_v1 = ntlm.__get__("create_NT_hashed_password_v1");
|
279 |
|
280 | var realResponse = create_NT_hashed_password_v1('Azx123456');
|
281 |
|
282 |
|
283 | var expectedResponse = Buffer.from([0x96, 0x1b, 0x07, 0xdb, 0xdc, 0xcf, 0x86, 0x9f, 0x2a, 0x3c, 0x99, 0x1c, 0x83, 0x94, 0x0e, 0x01]);
|
284 | return realResponse.equals(expectedResponse);
|
285 | }
|
286 |
|
287 | function test_calc_resp() {
|
288 | console.log('> testing calc_resp');
|
289 | const calc_resp = ntlm.__get__("calc_resp");
|
290 |
|
291 | var password_hash = Buffer.from([ 183, 180, 19, 95, 163, 5, 118, 130, 30, 146, 159, 1, 57, 81, 39, 252, 1, 57, 81, 39, 252 ]);
|
292 | var server_challenge = Buffer.from([150, 27, 7, 219, 220, 207, 134, 159]);
|
293 |
|
294 | var realResponse = calc_resp(password_hash, server_challenge);
|
295 |
|
296 |
|
297 | var expectedResponse = Buffer.from([0xaf, 0x00, 0xee, 0x2f, 0xd7, 0x8c, 0xaf, 0x4a, 0xab, 0x57, 0xcc, 0xcb, 0xb0, 0x93, 0x58, 0x62, 0x31, 0x69, 0x02, 0x92, 0x4d, 0x34, 0xbc, 0x92]);
|
298 | return realResponse.equals(expectedResponse);
|
299 | }
|
300 |
|
301 | function test_hmac_md5() {
|
302 | console.log('> testing hmac_md5');
|
303 | const hmac_md5 = ntlm.__get__("hmac_md5");
|
304 |
|
305 |
|
306 | var realResponse = hmac_md5('somekey', 'somedata');
|
307 |
|
308 |
|
309 | var expectedResponse = Buffer.from([0x7e, 0x58, 0x72, 0xda, 0x5d, 0x34, 0xa8, 0x22, 0x58, 0x4a, 0x69, 0x8f, 0xe7, 0xdb, 0x6c, 0x10]);
|
310 | return equal(realResponse, expectedResponse);
|
311 | }
|
312 |
|
313 | function test_ntlm2sr_calc_resp() {
|
314 | console.log('> testing ntlm2sr_calc_resp');
|
315 | const ntlm2sr_calc_resp = ntlm.__get__("ntlm2sr_calc_resp");
|
316 |
|
317 | var realResponse = ntlm2sr_calc_resp(
|
318 | Buffer.from([0x1b, 0xc8, 0x2f, 0x16, 0xdd, 0xcc, 0xbd, 0x4d, 0xac, 0xfc, 0xba, 0x4d, 0xcb, 0xc3, 0x51, 0x9d]),
|
319 | Buffer.from([0x05, 0xeb, 0xf2, 0xc2, 0xf2, 0x72, 0x92, 0x30]),
|
320 | Buffer.from([0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf])
|
321 | );
|
322 |
|
323 |
|
324 | var expectedResponse = {
|
325 | lmChallengeResponse: Buffer.from([0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00]),
|
326 | ntChallengeResponse: Buffer.from([0x2b, 0x8f, 0x56, 0xa4, 0x3f, 0x61, 0xdd, 0x6a, 0xa1, 0xa5, 0x57, 0xbe, 0xea, 0x81, 0x4b, 0x2c, 0x36, 0x56, 0x79, 0x5d, 0x7f, 0xa5, 0x3a, 0x51])
|
327 | }
|
328 | return equal(realResponse, expectedResponse);
|
329 | }
|
330 |
|
331 | function test_calc_ntlmv2_resp() {
|
332 | console.log('> testing calc_ntlmv2_resp');
|
333 | const calc_ntlmv2_resp = ntlm.__get__("calc_ntlmv2_resp");
|
334 |
|
335 | var dateMock = {
|
336 | now: function () {
|
337 | return 1679346960095;
|
338 | }
|
339 | };
|
340 | ntlm.__set__("Date", dateMock);
|
341 |
|
342 |
|
343 | var realResponse = calc_ntlmv2_resp(
|
344 | Buffer.from([0x1b, 0xc8, 0x2f, 0x16, 0xdd, 0xcc, 0xbd, 0x4d, 0xac, 0xfc, 0xba, 0x4d, 0xcb, 0xc3, 0x51, 0x9d]),
|
345 | 'm$',
|
346 | '',
|
347 | Buffer.from([0x02, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x07, 0x00, 0x08, 0x00, 0x39, 0xa0, 0xbb, 0x30, 0x87, 0x9f, 0xd5, 0x01, 0x00, 0x00, 0x00, 0x00]),
|
348 | Buffer.from([0x05, 0xeb, 0xf2, 0xc2, 0xf2, 0x72, 0x92, 0x30]),
|
349 | Buffer.from([0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf])
|
350 | );
|
351 |
|
352 |
|
353 |
|
354 | var expectedResponse = {
|
355 | lmChallengeResponse: Buffer.from([0xdf, 0x83, 0x90, 0xbd, 0x04, 0x71, 0x84, 0xca, 0xe5, 0xfd, 0x97, 0x6a, 0x1d, 0xf7, 0x57, 0xb1, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf]),
|
356 | ntChallengeResponse: Buffer.from([0x05, 0x19, 0x2d, 0x1e, 0xdf, 0xbf, 0xcc, 0x30, 0x47, 0xbd, 0x2a, 0x78, 0xb6, 0xa9, 0x9f, 0xa7, 0x01, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xf0, 0xe6, 0x5a, 0x2b, 0x71, 0x5b, 0xd9, 0x01, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0xcf, 0x00, 0x00, 0x00, 0x00, 0x02, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x01, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x04, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x03, 0x00, 0x1e, 0x00, 0x44, 0x00, 0x45, 0x00, 0x53, 0x00, 0x4b, 0x00, 0x54, 0x00, 0x4f, 0x00, 0x50, 0x00, 0x2d, 0x00, 0x4a, 0x00, 0x53, 0x00, 0x34, 0x00, 0x55, 0x00, 0x4a, 0x00, 0x54, 0x00, 0x44, 0x00, 0x07, 0x00, 0x08, 0x00, 0x39, 0xa0, 0xbb, 0x30, 0x87, 0x9f, 0xd5, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00])
|
357 | }
|
358 | return equal(realResponse, expectedResponse);
|
359 | }
|
360 |
|
361 | function test_NTOWFv2() {
|
362 | console.log('> testing NTOWFv2');
|
363 | const NTOWFv2 = ntlm.__get__("NTOWFv2");
|
364 |
|
365 |
|
366 | var realResponse = NTOWFv2(
|
367 | Buffer.from([0x1b, 0xc8, 0x2f, 0x16, 0xdd, 0xcc, 0xbd, 0x4d, 0xac, 0xfc, 0xba, 0x4d, 0xcb, 0xc3, 0x51, 0x9d]),
|
368 | 'someUsername',
|
369 | 'someDomain');
|
370 |
|
371 |
|
372 | var expectedResponse = Buffer.from([0x26, 0xd9, 0xf6, 0xea, 0x4d, 0x31, 0xd7, 0xf5, 0x12, 0xfb, 0x5f, 0xb4, 0x50, 0xd0, 0x9d, 0xf4]);
|
373 | return realResponse.equals(expectedResponse);
|
374 | }
|
375 |
|
376 |
|
377 | console.log(test_createType1Message());
|
378 | console.log(test_createType1Message_nodomain());
|
379 | console.log(test_createType1Message_noworkstation());
|
380 | console.log(test_parseType2Message());
|
381 | console.log(test_createType3Message());
|
382 | console.log(test_createType3Message_negotiateflagszero());
|
383 | console.log(test_create_LM_hashed_password_v1());
|
384 | console.log(test_create_LM_hashed_password_v1_longpassword());
|
385 | console.log(test_insertZerosEvery7Bits());
|
386 | console.log(test_bytes2binaryArray());
|
387 | console.log(test_binaryArray2bytes());
|
388 | console.log(test_create_NT_hashed_password_v1());
|
389 | console.log(test_calc_resp());
|
390 | console.log(test_hmac_md5());
|
391 | console.log(test_ntlm2sr_calc_resp());
|
392 | console.log(test_calc_ntlmv2_resp());
|
393 | console.log(test_NTOWFv2());
|
394 |
|