aboutsummaryrefslogtreecommitdiffstats
path: root/packet-smb-logon.c
blob: 749566de150ca50c010b34b73529d17f1aaa071c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
/* packet-smb-logon.c
 * Routines for smb net logon packet dissection
 * Copyright 2000, Jeffrey C. Foster <jfoste@woodward.com>
 *
 * $Id: packet-smb-logon.c,v 1.3 2000/02/21 23:50:15 sharpe Exp $
 *
 * Ethereal - Network traffic analyzer
 * By Gerald Combs <gerald@zing.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-pop.c
 * 
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
 */

#include "packet-smb-common.h"

static int proto_smb_logon = -1;

static int ett_smb_logon = -1;
static int ett_smb_account_flags = -1;


static void
dissect_account_control( const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){
		
/* display the Allowable Account control bits */

	proto_tree  *flags_tree;
	proto_item  *ti;
	guint32  flags = GWORD( pd, offset);

	struct flag_array_type  flag_info[] = {
		{ 0x400, "User account ", "", "not ", "auto-locked"},
		{ 0x200, "User password will ", "not ", "", "expire"},
		{ 0x100, "", "", "Not a ", "Server Trust user account"},
		{ 0x080, "", "", "Not a ", "Workstation Trust user account"},
		{ 0x040, "", "", "Not an ", "Inter-domain Trust user account"},
		{ 0x020, "", "", "Not a ", "MNS Logon user account"},
		{ 0x010, "", "", "Not a ", "Normal user account"},
		{ 0x008, "", "", "Not a ", "temp duplicate user account"},
		{ 0x004, "", "No", "", "User password required"},
		{ 0x002, "", "No", "", "User home directory required"},
		{ 0x001, "User account ", "enabled", "disabled", ""},
		{ 0, "", "", "", ""}
	};


	ti = proto_tree_add_text( tree, offset, 4,
		"Account control  = 0x%04x", flags);
		
     	flags_tree = proto_item_add_subtree( ti, ett_smb_account_flags);

	display_flags( flag_info, 4, pd, offset, flags_tree);
}



static void
display_LM_token( const u_char *pd, int *offset, frame_data *fd,
	proto_tree *tree) {

/* decode and display the LanMan token */	

	guint16 Token = GSHORT( pd, *offset);
	
	if ( Token && 0x01) 
		proto_tree_add_text( tree, *offset, 2,
			"LM20 Token: 0x%x (LanMan 2.0 or higher)", Token);
	else
		proto_tree_add_text( tree, *offset, 2,
			"LM10 Token: 0x%x (WFW Networking)", Token);

	if (( *offset + 2) > fd->cap_len)
		proto_tree_add_text(tree, *offset, 0,"****FRAME TOO SHORT***");
	else
		*offset += 2;
	
}

static void
display_NT_version( const u_char *pd, int *offset, frame_data *fd,
	proto_tree *tree, int length) {

/* display the NT version	*/	

	guint32 Version;
	
	if ( length == 2)
		Version = GSHORT( pd, *offset);
	else
		Version  = GWORD( pd, *offset);
	
	proto_tree_add_text( tree, *offset, length, "NT Version: 0x%x ",
		Version);

	if (( *offset + length) > fd->cap_len)
		proto_tree_add_text(tree, *offset, 0, "****FRAME TOO SHORT***");
	else
		*offset += length;
	
}



void dissect_smb_logon_request( const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/*** 0x00 (LM1.0/LM2.0 LOGON Request) ***/
 
 	MoveAndCheckOffset( display_ms_string( "Computer Name", pd, offset, fd,
 		tree));
	
	MoveAndCheckOffset( display_ms_string( "User Name", pd, offset, fd,
		tree));

	MoveAndCheckOffset( display_ms_string( "Mailslot Name", pd, offset, fd,
		tree));

/*$$$$$ here add the Mailslot to the response list (if needed) */
	
	MoveAndCheckOffset( display_ms_value( "Request Count", 1, pd, offset,
		fd, tree));

	display_NT_version( pd, &offset, fd, tree,2);
	display_LM_token( pd, &offset, fd, tree);
}



static void
dissect_smb_logon_LM10_resp(const u_char *pd, int offset, frame_data *fd,
	proto_tree *tree){

/*** 0x01 LanMan 1.0 Logon response ***/

	MoveAndCheckOffset( display_ms_string( "User Name", pd, offset, fd,
		tree));
	MoveAndCheckOffset( display_ms_string( "Script Name", pd, offset, fd,
		tree));
}



void dissect_smb_logon_2(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree) {

/*** 0x02  LM1.0 Query - Centralized Initialization ***/
/*** 0x03  LM1.0 Query - Distributed Initialization ***/
/*** 0x04  LM1.0 Query - Centralized Query Response ***/
/*** 0x04  LM1.0 Query - Distributed Query Response ***/

	MoveAndCheckOffset( display_ms_string( "Computer Name", pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_string( "Mailslot Name", pd, offset, fd, tree));

	display_NT_version( pd, &offset, fd, tree, 2);
	display_LM_token( pd, &offset, fd, tree);
}



void dissect_smb_logon_LM20_resp(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/*** 0x06 (LM2.0 LOGON Response)	***/

	++offset;		/* move to the server name */

	MoveAndCheckOffset( display_ms_string( "Logon Server Name", pd, offset,
		fd, tree));

	display_LM_token( pd, &offset, fd, tree);

}



static void
dissect_smb_pdc_query(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/*** 0x07 Query for Primary PDC  ***/

 
	MoveAndCheckOffset( display_ms_string( "Computer Name", pd, offset,
		fd, tree));

	MoveAndCheckOffset( display_ms_string( "Mailslot Name", pd, offset,
		fd, tree));

	MoveAndCheckOffset( display_ms_string( "OEM Computer Name", pd, offset,
		fd, tree));

	display_NT_version( pd, &offset, fd, tree, 4);

	proto_tree_add_text( tree, offset, 2, "LMNT Token: 0x%x",
		GWORD(pd, offset));
	MoveAndCheckOffset( 2);
	
	display_LM_token( pd, &offset, fd, tree);
}



void dissect_smb_pdc_startup(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/*** 0x08  Announce startup of PDC ***/
 
	MoveAndCheckOffset(
		display_ms_string( "PDC Name", pd, offset, fd, tree));

	/* A short Announce will not have the rest */

	if (END_OF_FRAME > 0) { 

	  if (offset % 2) offset++;      /* word align ... */

	  MoveAndCheckOffset(
		 display_unicode_string("Unicode PDC Name", pd, offset, fd, tree));

	  if (offset % 2) offset++;

	  MoveAndCheckOffset(
		 display_unicode_string("Unicode Domain Name", pd, offset, fd, tree));

	  display_NT_version( pd, &offset, fd, tree, 4);

	  display_LM_token( pd, &offset, fd, tree);
	}
}



static void
dissect_smb_pdc_failure( const u_char *pd, int offset, frame_data *fd,
	proto_tree *tree){

/*** 0x09 Announce failure of the PDC ***/
/*** 0x0F LM2.0 Resp. during LOGON pause ***/
/*** 0x10 (LM 2.0 Unknown user response) ***/

	display_NT_version( pd, &offset, fd, tree, 4);
	display_LM_token( pd, &offset, fd, tree);
}


void dissect_announce_change( const u_char *pd, int offset,
	frame_data *fd,proto_tree *tree) {
	
/*** 0x0A ( Announce change to UAS or SAM ) ***/


	MoveAndCheckOffset( display_ms_value( "Low serial number", 4, pd,
		offset, fd, tree));
	MoveAndCheckOffset( display_ms_value( "Date/Time", 4, pd, offset, fd,
		tree));
	MoveAndCheckOffset(
		display_ms_value( "Pulse", 4, pd, offset, fd, tree));
	MoveAndCheckOffset(
		display_ms_value( "Random", 4, pd, offset, fd, tree));
	MoveAndCheckOffset(
		display_ms_string( "PDC Name", pd, offset, fd, tree));
	MoveAndCheckOffset(
		display_ms_string( "Domain Name", pd, offset, fd, tree));

/*???? is this needed ??? */
	if ( !( offset & 0x1))			/* add padding if needed */
		++offset;

	MoveAndCheckOffset( display_unicode_string( "Unicode PDC Name", pd,
		offset, fd, tree));

	MoveAndCheckOffset( display_unicode_string( "Unicode Domain Name", pd,
		offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "DB Count", 4, pd, offset, fd,
		tree));

	MoveAndCheckOffset( display_ms_value( "NT Version ", 4, pd, offset, fd,
		tree));

	MoveAndCheckOffset( display_ms_value( "LMNT Token ", 2, pd, offset, fd,
		tree));

	MoveAndCheckOffset( display_ms_value( "Unknown Token ", 2, pd, offset,
		fd, tree));
}


static void
dissect_smb_sam_logon_req(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/*** Netlogon command 0x12 - decode the SAM logon request from client ***/


	proto_tree_add_text( tree, offset, 2, "Request Count  = %x",
		GSHORT(pd, offset));

	MoveAndCheckOffset( 2);
	
	MoveAndCheckOffset( display_unicode_string( "Unicode Computer Name",
		pd, offset, fd, tree));
	
	MoveAndCheckOffset( display_unicode_string( "Unicode User Name",
		pd, offset, fd, tree));
	
	MoveAndCheckOffset( display_ms_string( "Mailslot Name", pd, offset, fd,
		tree));

	dissect_account_control( pd, offset, fd, tree);
		
	proto_tree_add_text( tree, offset, 2, "Domain SID Size = %x",
		GWORD(pd, offset));

}



static void
dissect_smb_no_user( const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree)

{/* 0x0B (Announce no user on machine) */

	display_ms_string( "Computer Name", pd, offset, fd, tree);
}



static void
dissect_smb_relogon_resp( const u_char *pd, int offset, frame_data *fd,
	proto_tree *tree){

/*** 0x0d LanMan Response to relogon request ***/

	MoveAndCheckOffset( display_ms_value( "Workstation major version", 1,
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "Workstation minor version", 1,
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "Workstation OS version", 1,
		pd, offset, fd, tree));

	display_NT_version( pd, &offset, fd, tree, 4);

	display_LM_token( pd, &offset, fd, tree);
}



static void
dissect_smb_acc_update( const u_char *pd, int offset, frame_data *fd,
	proto_tree *tree){

/*** 0x11  LM2.1 Announce Acc updates  ***/

	guint32 Temp1, Temp2;
	
	Temp1 = GWORD( pd, offset);

	Temp2 = GWORD( pd, offset + 4);
	
	proto_tree_add_text( tree, offset, 2, "Signature: 0x%04x%04x",
		Temp1, Temp2);

	MoveAndCheckOffset( 8);

	MoveAndCheckOffset( display_ms_value( "Time/Date:", 4,
		pd, offset, fd, tree));
	
	MoveAndCheckOffset( display_ms_string( "Computer name:", 
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_string( "User name:", 
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "Update Type:", 2,
		pd, offset, fd, tree));

	display_NT_version( pd, &offset, fd, tree, 4);

	display_LM_token( pd, &offset, fd, tree);
}



static void
dissect_smb_inter_resp( const u_char *pd, int offset, frame_data *fd,
	proto_tree *tree){

/* 0x0e LanMan Response to interrogate request */

	MoveAndCheckOffset( display_ms_value( "Workstation major version", 1,
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "Workstation minor version", 1,
		pd, offset, fd, tree));

	MoveAndCheckOffset( display_ms_value( "Workstation OS version", 1, pd,
		offset, fd, tree));

	display_NT_version( pd, &offset, fd, tree, 4);

	MoveAndCheckOffset( display_ms_value( "LMNT Token ", 2, pd, offset, fd,
		tree));
}


void dissect_smb_sam_logon_resp(const u_char *pd, int offset, frame_data *fd,
		proto_tree *tree){

/* Netlogon command 0x13 - decode the SAM logon response from server */


	MoveAndCheckOffset( display_unicode_string( "Server Name", pd, offset,
		fd, tree));
	
	MoveAndCheckOffset( display_unicode_string( "User Name", pd, offset,
		fd, tree));
	
	MoveAndCheckOffset( display_unicode_string( "Domain Name", pd, offset,
		fd, tree));

	display_NT_version( pd, &offset, fd, tree, 4);

	proto_tree_add_text( tree, offset, 2, "LMNT Token: 0x%x",
		GSHORT(pd, offset));
	MoveAndCheckOffset( 2);

	display_LM_token( pd, &offset, fd, tree);
}


guint32 
dissect_smb_logon(const u_char *pd, int offset, frame_data *fd,
	proto_tree *parent, proto_tree *tree, struct smb_info si,
	int max_data, int SMB_offset, int errcode, int dirn,
	const u_char *command, int DataOffset, int DataCount){


/* decode the Microsoft netlogon protocol */

static char* CommandName[] = {

	"LM1.0/LM2.0 LOGON Request",			/* 0x00 */
	"LM1.0 LOGON Response",				/* 0x01 */
	"LM1.0 Query - Centralized Initialization",	/* 0x02 */
	"LM1.0 Query - Distributed Initialization",	/* 0x03 */
	"LM1.0 Response - Centralized Query",		/* 0x04 */
	"LM1.0 Response - Distributed Initialization",	/* 0x05 */
	"LM2.0 Response to LOGON Request",		/* 0x06 */
	"Query for PDC",				/* 0x07 */
	"Announce Startup of PDC",			/* 0x08 */
	"Announce Failed PDC",				/* 0x09 */
	"Announce Change to UAS or SAM",		/* 0x0A */
	"Announce no user on machine",			/* 0x0B */
	"Response from PDC",				/* 0x0C */
	"LM1.0/LM2.0 Response to re-LOGON Request",	/* 0x0D */
	"LM1.0/LM2.0 Response to Interrogate Request",	/* 0x0E */
	"LM2.0 Response during LOGON pause",		/* 0x0F */
	"LM2.0 Response - user unknown",		/* 0x10 */
	"LM2.0 Announce account updates ",		/* 0x11 */
	"SAM LOGON request from client ",		/* 0x12 */
	"Response to SAM LOGON request",		/* 0x13 */
	"SAM Response during LOGON pause",		/* 0x14 */
	"SAM Response - user unknown",			/* 0x15 */
	"SAM Response to Interrogate Request",		/* 0x16 */
	"Unknown"					/* 0x17 */
	};

/* Array of functions to dissect the ms logon commands */
		
static void (*dissect_smb_logon_cmds[])(const u_char *, int, frame_data *,
	proto_tree *) = {

  dissect_smb_logon_request,    /* 0x00 (LM1.0/LM2.0 LOGON Request) 	*/
  dissect_smb_logon_LM10_resp, 	/* 0x01 (LM1.0 LOGON Response) 		*/
  dissect_smb_logon_2,	      	/* 0x02 (LM1.0 Query Centralized Init.)	*/
  dissect_smb_logon_2,	      	/* 0x03 (LM1.0 Query Distributed Init.)	*/
  dissect_smb_logon_2,	      	/* 0x04 (LM1.0 Centralized Query Resp.)	*/
  dissect_smb_logon_2,	      	/* 0x05 (LM1.0 Distributed Query Resp.) */
  dissect_smb_logon_LM20_resp, 	/* 0x06 (LM2.0 LOGON Response)		*/
  dissect_smb_pdc_query,	/* 0x07 (Query for PDC) 		*/
  dissect_smb_pdc_startup,	/* 0x08 (Announce PDC startup)		*/
  dissect_smb_pdc_failure,     	/* 0x09 (Announce Failed PDC)		*/
  dissect_announce_change,     	/* 0x0A (Announce change to UAS or SAM)	*/
  dissect_smb_no_user,	      	/* 0x0B (Announce no user on machine)	*/
  dissect_smb_pdc_startup,	/* 0x0C (Response from PDC)		*/
  dissect_smb_relogon_resp,	/* 0x0D (Relogon response) 		*/
  dissect_smb_inter_resp,      	/* 0x0E (Interrogate response) 		*/
  dissect_smb_pdc_failure,	/* 0x0F (LM2.0 Resp. during LOGON pause	*/
  dissect_smb_pdc_failure,    	/* 0x10 (LM 2.0 Unknown user response)	*/
  dissect_smb_acc_update,    	/* 0x11 (LM2.1 Announce Acc updates) 	*/
  dissect_smb_sam_logon_req,   	/* 0x12 (SAM LOGON request )		*/
  dissect_smb_sam_logon_resp,  	/* 0x13 (SAM LOGON response) 		*/
  dissect_smb_unknown,    	/* 0x14 (LM2.1 Announce Acc updates) 	*/
};



	guint8  cmd;
	proto_tree      *smb_logon_tree;
	proto_item      *ti;

					   /* get the Command field */
   	cmd = MIN(  GBYTE(pd, offset), array_length(dissect_smb_logon_cmds)-1);

	if (check_col(fd, COL_PROTOCOL))
		col_add_str(fd, COL_PROTOCOL, "NETLOGON");


	if (check_col(fd, COL_INFO))
		col_add_fstr(fd, COL_INFO, "%s", CommandName[ cmd]);

    	if (tree) {
		ti = proto_tree_add_item( parent, proto_smb_logon, offset,
			END_OF_FRAME, NULL);
		smb_logon_tree = proto_item_add_subtree(ti, ett_smb_logon);

		proto_tree_add_text(smb_logon_tree, offset, 1,
			"Command: %u (%s)", cmd, CommandName[ cmd]);
			
		offset += 2;			/* skip to name field */

						/* vector to handle commands */
		(dissect_smb_logon_cmds[  cmd]) (pd, offset, fd,smb_logon_tree);

	}
   return 1;  
}



void
register_proto_smb_logon( void){

/*** Prep the logon protocol, for now, just register it	*/

	static gint *ett[] = {
		&ett_smb_logon,
		&ett_smb_account_flags
	};

   	proto_smb_logon = proto_register_protocol(
   		"Microsoft Windows Logon Protocol", "netlogon");

	proto_register_subtree_array(ett, array_length(ett));          
}