]> The Tcpdump Group git mirrors - tcpdump/blob - print-smb.c
Show the message type for NBT Session Service messages even with "-vv".
[tcpdump] / print-smb.c
1 /*
2 * Copyright (C) Andrew Tridgell 1995-1999
3 *
4 * This software may be distributed either under the terms of the
5 * BSD-style license that accompanies tcpdump or the GNU GPL version 2
6 * or later
7 */
8
9 #ifdef HAVE_CONFIG_H
10 #include "config.h"
11 #endif
12
13 #ifndef lint
14 static const char rcsid[] _U_ =
15 "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.31 2004-05-31 01:55:07 guy Exp $";
16 #endif
17
18 #include <tcpdump-stdinc.h>
19
20 #include <stdio.h>
21 #include <string.h>
22
23 #include "interface.h"
24 #include "extract.h"
25 #include "smb.h"
26
27 static int request = 0;
28
29 const u_char *startbuf = NULL;
30
31 struct smbdescript {
32 const char *req_f1;
33 const char *req_f2;
34 const char *rep_f1;
35 const char *rep_f2;
36 void (*fn)(const u_char *, const u_char *, const u_char *, const u_char *);
37 };
38
39 struct smbdescriptint {
40 const char *req_f1;
41 const char *req_f2;
42 const char *rep_f1;
43 const char *rep_f2;
44 void (*fn)(const u_char *, const u_char *, int, int);
45 };
46
47 struct smbfns
48 {
49 int id;
50 const char *name;
51 int flags;
52 struct smbdescript descript;
53 };
54
55 struct smbfnsint
56 {
57 int id;
58 const char *name;
59 int flags;
60 struct smbdescriptint descript;
61 };
62
63 #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
64
65 #define FLG_CHAIN (1 << 0)
66
67 static struct smbfns *
68 smbfind(int id, struct smbfns *list)
69 {
70 int sindex;
71
72 for (sindex = 0; list[sindex].name; sindex++)
73 if (list[sindex].id == id)
74 return(&list[sindex]);
75
76 return(&list[0]);
77 }
78
79 static struct smbfnsint *
80 smbfindint(int id, struct smbfnsint *list)
81 {
82 int sindex;
83
84 for (sindex = 0; list[sindex].name; sindex++)
85 if (list[sindex].id == id)
86 return(&list[sindex]);
87
88 return(&list[0]);
89 }
90
91 static void
92 trans2_findfirst(const u_char *param, const u_char *data, int pcnt, int dcnt)
93 {
94 const char *fmt;
95
96 if (request)
97 fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP5]\nFile=[S]\n";
98 else
99 fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n";
100
101 smb_fdata(param, fmt, param + pcnt);
102 if (dcnt) {
103 printf("data:\n");
104 print_data(data, dcnt);
105 }
106 }
107
108 static void
109 trans2_qfsinfo(const u_char *param, const u_char *data, int pcnt, int dcnt)
110 {
111 static int level = 0;
112 const char *fmt="";
113
114 if (request) {
115 TCHECK2(*param, 2);
116 level = EXTRACT_LE_16BITS(param);
117 fmt = "InfoLevel=[d]\n";
118 smb_fdata(param, fmt, param + pcnt);
119 } else {
120 switch (level) {
121 case 1:
122 fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n";
123 break;
124 case 2:
125 fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n";
126 break;
127 case 0x105:
128 fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n";
129 break;
130 default:
131 fmt = "UnknownLevel\n";
132 break;
133 }
134 smb_fdata(data, fmt, data + dcnt);
135 }
136 if (dcnt) {
137 printf("data:\n");
138 print_data(data, dcnt);
139 }
140 return;
141 trunc:
142 printf("[|SMB]");
143 return;
144 }
145
146 struct smbfnsint trans2_fns[] = {
147 { 0, "TRANSACT2_OPEN", 0,
148 { "Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w, w, w, w, w])\nPath=[S]",
149 NULL,
150 "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",
151 NULL, NULL }},
152 { 1, "TRANSACT2_FINDFIRST", 0,
153 { NULL, NULL, NULL, NULL, trans2_findfirst }},
154 { 2, "TRANSACT2_FINDNEXT", 0, DEFDESCRIPT },
155 { 3, "TRANSACT2_QFSINFO", 0,
156 { NULL, NULL, NULL, NULL, trans2_qfsinfo }},
157 { 4, "TRANSACT2_SETFSINFO", 0, DEFDESCRIPT },
158 { 5, "TRANSACT2_QPATHINFO", 0, DEFDESCRIPT },
159 { 6, "TRANSACT2_SETPATHINFO", 0, DEFDESCRIPT },
160 { 7, "TRANSACT2_QFILEINFO", 0, DEFDESCRIPT },
161 { 8, "TRANSACT2_SETFILEINFO", 0, DEFDESCRIPT },
162 { 9, "TRANSACT2_FSCTL", 0, DEFDESCRIPT },
163 { 10, "TRANSACT2_IOCTL", 0, DEFDESCRIPT },
164 { 11, "TRANSACT2_FINDNOTIFYFIRST", 0, DEFDESCRIPT },
165 { 12, "TRANSACT2_FINDNOTIFYNEXT", 0, DEFDESCRIPT },
166 { 13, "TRANSACT2_MKDIR", 0, DEFDESCRIPT },
167 { -1, NULL, 0, DEFDESCRIPT }
168 };
169
170
171 static void
172 print_trans2(const u_char *words, const u_char *dat _U_, const u_char *buf, const u_char *maxbuf)
173 {
174 static struct smbfnsint *fn = &trans2_fns[0];
175 const u_char *data, *param;
176 const u_char *w = words + 1;
177 const char *f1 = NULL, *f2 = NULL;
178 int pcnt, dcnt;
179
180 TCHECK(words[0]);
181 if (request) {
182 TCHECK2(w[14 * 2], 2);
183 pcnt = EXTRACT_LE_16BITS(w + 9 * 2);
184 param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
185 dcnt = EXTRACT_LE_16BITS(w + 11 * 2);
186 data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
187 fn = smbfindint(EXTRACT_LE_16BITS(w + 14 * 2), trans2_fns);
188 } else {
189 if (words[0] == 0) {
190 printf("%s\n", fn->name);
191 printf("Trans2Interim\n");
192 return;
193 }
194 TCHECK2(w[7 * 2], 2);
195 pcnt = EXTRACT_LE_16BITS(w + 3 * 2);
196 param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
197 dcnt = EXTRACT_LE_16BITS(w + 6 * 2);
198 data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
199 }
200
201 printf("%s param_length=%d data_length=%d\n", fn->name, pcnt, dcnt);
202
203 if (request) {
204 if (words[0] == 8) {
205 smb_fdata(words + 1,
206 "Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",
207 maxbuf);
208 return;
209 } else {
210 smb_fdata(words + 1,
211 "TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n",
212 words + 1 + 14 * 2);
213 smb_fdata(data + 1, "TransactionName=[S]\n%", maxbuf);
214 }
215 f1 = fn->descript.req_f1;
216 f2 = fn->descript.req_f2;
217 } else {
218 smb_fdata(words + 1,
219 "TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n",
220 words + 1 + 10 * 2);
221 f1 = fn->descript.rep_f1;
222 f2 = fn->descript.rep_f2;
223 }
224
225 if (fn->descript.fn)
226 (*fn->descript.fn)(param, data, pcnt, dcnt);
227 else {
228 smb_fdata(param, f1 ? f1 : "Parameters=\n", param + pcnt);
229 smb_fdata(data, f2 ? f2 : "Data=\n", data + dcnt);
230 }
231 return;
232 trunc:
233 printf("[|SMB]");
234 return;
235 }
236
237
238 static void
239 print_browse(const u_char *param, int paramlen, const u_char *data, int datalen)
240 {
241 const u_char *maxbuf = data + datalen;
242 int command;
243
244 TCHECK(data[0]);
245 command = data[0];
246
247 smb_fdata(param, "BROWSE PACKET\n|Param ", param+paramlen);
248
249 switch (command) {
250 case 0xF:
251 data = smb_fdata(data,
252 "BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
253 maxbuf);
254 break;
255
256 case 0x1:
257 data = smb_fdata(data,
258 "BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",
259 maxbuf);
260 break;
261
262 case 0x2:
263 data = smb_fdata(data,
264 "BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",
265 maxbuf);
266 break;
267
268 case 0xc:
269 data = smb_fdata(data,
270 "BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",
271 maxbuf);
272 break;
273
274 case 0x8:
275 data = smb_fdata(data,
276 "BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W, W)]\nServerName=[S]\n",
277 maxbuf);
278 break;
279
280 case 0xb:
281 data = smb_fdata(data,
282 "BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",
283 maxbuf);
284 break;
285
286 case 0x9:
287 data = smb_fdata(data,
288 "BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken?=[B]\n",
289 maxbuf);
290 break;
291
292 case 0xa:
293 data = smb_fdata(data,
294 "BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken?=[B]*Name=[S]\n",
295 maxbuf);
296 break;
297
298 case 0xd:
299 data = smb_fdata(data,
300 "BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",
301 maxbuf);
302 break;
303
304 case 0xe:
305 data = smb_fdata(data,
306 "BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n", maxbuf);
307 break;
308
309 default:
310 data = smb_fdata(data, "Unknown Browser Frame ", maxbuf);
311 break;
312 }
313 return;
314 trunc:
315 printf("[|SMB]");
316 return;
317 }
318
319
320 static void
321 print_ipc(const u_char *param, int paramlen, const u_char *data, int datalen)
322 {
323 if (paramlen)
324 smb_fdata(param, "Command=[w]\nStr1=[S]\nStr2=[S]\n", param + paramlen);
325 if (datalen)
326 smb_fdata(data, "IPC ", data + datalen);
327 }
328
329
330 static void
331 print_trans(const u_char *words, const u_char *data1, const u_char *buf, const u_char *maxbuf)
332 {
333 const char *f1, *f2, *f3, *f4;
334 const u_char *data, *param;
335 const u_char *w = words + 1;
336 int datalen, paramlen;
337
338 if (request) {
339 TCHECK2(w[12 * 2], 2);
340 paramlen = EXTRACT_LE_16BITS(w + 9 * 2);
341 param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
342 datalen = EXTRACT_LE_16BITS(w + 11 * 2);
343 data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
344 f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n";
345 f2 = "|Name=[S]\n";
346 f3 = "|Param ";
347 f4 = "|Data ";
348 } else {
349 TCHECK2(w[7 * 2], 2);
350 paramlen = EXTRACT_LE_16BITS(w + 3 * 2);
351 param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
352 datalen = EXTRACT_LE_16BITS(w + 6 * 2);
353 data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
354 f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n";
355 f2 = "|Unknown ";
356 f3 = "|Param ";
357 f4 = "|Data ";
358 }
359
360 smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf));
361 smb_fdata(data1 + 2, f2, maxbuf - (paramlen + datalen));
362
363 if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) {
364 print_browse(param, paramlen, data, datalen);
365 return;
366 }
367
368 if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) {
369 print_ipc(param, paramlen, data, datalen);
370 return;
371 }
372
373 if (paramlen)
374 smb_fdata(param, f3, SMBMIN(param + paramlen, maxbuf));
375 if (datalen)
376 smb_fdata(data, f4, SMBMIN(data + datalen, maxbuf));
377 return;
378 trunc:
379 printf("[|SMB]");
380 return;
381 }
382
383
384 static void
385 print_negprot(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
386 {
387 u_int wcnt;
388 const char *f1 = NULL, *f2 = NULL;
389
390 TCHECK(words[0]);
391 wcnt = words[0];
392 if (request)
393 f2 = "*|Dialect=[Z]\n";
394 else {
395 if (wcnt == 1)
396 f1 = "Core Protocol\nDialectIndex=[d]";
397 else if (wcnt == 17)
398 f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey=";
399 else if (wcnt == 13)
400 f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey=";
401 }
402
403 if (f1)
404 smb_fdata(words + 1, f1, SMBMIN(words + 1 + wcnt * 2, maxbuf));
405 else
406 print_data(words + 1, SMBMIN(wcnt * 2, PTR_DIFF(maxbuf, words + 1)));
407
408 TCHECK2(*data, 2);
409 if (f2)
410 smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf));
411 else
412 print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
413 return;
414 trunc:
415 printf("[|SMB]");
416 return;
417 }
418
419 static void
420 print_sesssetup(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
421 {
422 u_int wcnt;
423 const char *f1 = NULL, *f2 = NULL;
424
425 TCHECK(words[0]);
426 wcnt = words[0];
427 if (request) {
428 if (wcnt == 10)
429 f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
430 else
431 f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n";
432 } else {
433 if (wcnt == 3) {
434 f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n";
435 } else if (wcnt == 13) {
436 f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n";
437 f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
438 }
439 }
440
441 if (f1)
442 smb_fdata(words + 1, f1, SMBMIN(words + 1 + wcnt * 2, maxbuf));
443 else
444 print_data(words + 1, SMBMIN(wcnt * 2, PTR_DIFF(maxbuf, words + 1)));
445
446 TCHECK2(*data, 2);
447 if (f2)
448 smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf));
449 else
450 print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
451 return;
452 trunc:
453 printf("[|SMB]");
454 return;
455 }
456
457
458 static struct smbfns smb_fns[] = {
459 { -1, "SMBunknown", 0, DEFDESCRIPT },
460
461 { SMBtcon, "SMBtcon", 0,
462 { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
463 "MaxXmit=[d]\nTreeId=[d]\n", NULL,
464 NULL } },
465
466 { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
467 { SMBexit, "SMBexit", 0, DEFDESCRIPT },
468 { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
469
470 { SMBecho, "SMBecho", 0,
471 { "ReverbCount=[d]\n", NULL,
472 "SequenceNum=[d]\n", NULL,
473 NULL } },
474
475 { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
476
477 { SMBgetatr, "SMBgetatr", 0,
478 { NULL, "Path=[Z]\n",
479 "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL,
480 NULL } },
481
482 { SMBsetatr, "SMBsetatr", 0,
483 { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
484 NULL, NULL, NULL } },
485
486 { SMBchkpth, "SMBchkpth", 0,
487 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
488
489 { SMBsearch, "SMBsearch", 0,
490 { "Count=[d]\nAttrib=[A]\n",
491 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n",
492 "Count=[d]\n",
493 "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
494 NULL } },
495
496 { SMBopen, "SMBopen", 0,
497 { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
498 "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",
499 NULL, NULL } },
500
501 { SMBcreate, "SMBcreate", 0,
502 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
503
504 { SMBmknew, "SMBmknew", 0,
505 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
506
507 { SMBunlink, "SMBunlink", 0,
508 { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
509
510 { SMBread, "SMBread", 0,
511 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
512 "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
513
514 { SMBwrite, "SMBwrite", 0,
515 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
516 "Count=[d]\n", NULL, NULL } },
517
518 { SMBclose, "SMBclose", 0,
519 { "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } },
520
521 { SMBmkdir, "SMBmkdir", 0,
522 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
523
524 { SMBrmdir, "SMBrmdir", 0,
525 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
526
527 { SMBdskattr, "SMBdskattr", 0,
528 { NULL, NULL,
529 "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n",
530 NULL, NULL } },
531
532 { SMBmv, "SMBmv", 0,
533 { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
534
535 /*
536 * this is a Pathworks specific call, allowing the
537 * changing of the root path
538 */
539 { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
540
541 { SMBlseek, "SMBlseek", 0,
542 { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
543
544 { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
545
546 { SMBsplopen, "SMBsplopen", 0,
547 { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n",
548 NULL, NULL } },
549
550 { SMBsplclose, "SMBsplclose", 0,
551 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
552
553 { SMBsplretq, "SMBsplretq", 0,
554 { "MaxCount=[d]\nStartIndex=[d]\n", NULL,
555 "Count=[d]\nIndex=[d]\n",
556 "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n",
557 NULL } },
558
559 { SMBsplwr, "SMBsplwr", 0,
560 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
561
562 { SMBlock, "SMBlock", 0,
563 { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
564
565 { SMBunlock, "SMBunlock", 0,
566 { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
567
568 /* CORE+ PROTOCOL FOLLOWS */
569
570 { SMBreadbraw, "SMBreadbraw", 0,
571 { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n",
572 NULL, NULL, NULL, NULL } },
573
574 { SMBwritebraw, "SMBwritebraw", 0,
575 { "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n",
576 NULL, "WriteRawAck", NULL, NULL } },
577
578 { SMBwritec, "SMBwritec", 0,
579 { NULL, NULL, "Count=[d]\n", NULL, NULL } },
580
581 { SMBwriteclose, "SMBwriteclose", 0,
582 { "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
583 NULL, "Count=[d]\n", NULL, NULL } },
584
585 { SMBlockread, "SMBlockread", 0,
586 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
587 "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
588
589 { SMBwriteunlock, "SMBwriteunlock", 0,
590 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
591 "Count=[d]\n", NULL, NULL } },
592
593 { SMBreadBmpx, "SMBreadBmpx", 0,
594 { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n",
595 NULL,
596 "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n",
597 NULL, NULL } },
598
599 { SMBwriteBmpx, "SMBwriteBmpx", 0,
600 { "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL,
601 "Remaining=[d]\n", NULL, NULL } },
602
603 { SMBwriteBs, "SMBwriteBs", 0,
604 { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",
605 NULL, "Count=[d]\n", NULL, NULL } },
606
607 { SMBsetattrE, "SMBsetattrE", 0,
608 { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
609 NULL, NULL, NULL } },
610
611 { SMBgetattrE, "SMBgetattrE", 0,
612 { "Handle=[d]\n", NULL,
613 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",
614 NULL, NULL } },
615
616 { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
617 { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
618
619 { SMBcopy, "SMBcopy", 0,
620 { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
621 "CopyCount=[d]\n", "|ErrStr=[S]\n", NULL } },
622
623 { SMBmove, "SMBmove", 0,
624 { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
625 "MoveCount=[d]\n", "|ErrStr=[S]\n", NULL } },
626
627 { SMBopenX, "SMBopenX", FLG_CHAIN,
628 { "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n",
629 "Path=[S]\n",
630 "Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",
631 NULL, NULL } },
632
633 { SMBreadX, "SMBreadX", FLG_CHAIN,
634 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",
635 NULL,
636 "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",
637 NULL, NULL } },
638
639 { SMBwriteX, "SMBwriteX", FLG_CHAIN,
640 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",
641 NULL,
642 "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",
643 NULL, NULL } },
644
645 { SMBlockingX, "SMBlockingX", FLG_CHAIN,
646 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n",
647 "*Process=[d]\nOffset=[D]\nLength=[D]\n",
648 "Com2=[w]\nOff2=[d]\n", NULL, NULL } },
649
650 { SMBffirst, "SMBffirst", 0,
651 { "Count=[d]\nAttrib=[A]\n",
652 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
653 "Count=[d]\n",
654 "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
655 NULL } },
656
657 { SMBfunique, "SMBfunique", 0,
658 { "Count=[d]\nAttrib=[A]\n",
659 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
660 "Count=[d]\n",
661 "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
662 NULL } },
663
664 { SMBfclose, "SMBfclose", 0,
665 { "Count=[d]\nAttrib=[A]\n",
666 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
667 "Count=[d]\n",
668 "BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",
669 NULL } },
670
671 { SMBfindnclose, "SMBfindnclose", 0,
672 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
673
674 { SMBfindclose, "SMBfindclose", 0,
675 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
676
677 { SMBsends, "SMBsends", 0,
678 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
679
680 { SMBsendstrt, "SMBsendstrt", 0,
681 { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } },
682
683 { SMBsendend, "SMBsendend", 0,
684 { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
685
686 { SMBsendtxt, "SMBsendtxt", 0,
687 { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
688
689 { SMBsendb, "SMBsendb", 0,
690 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
691
692 { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
693 { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
694 { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
695
696 { SMBnegprot, "SMBnegprot", 0,
697 { NULL, NULL, NULL, NULL, print_negprot } },
698
699 { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
700 { NULL, NULL, NULL, NULL, print_sesssetup } },
701
702 { SMBtconX, "SMBtconX", FLG_CHAIN,
703 { "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",
704 NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[S]\n", NULL } },
705
706 { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
707
708 { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
709 { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
710 { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
711 { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
712
713 { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
714 { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
715
716 { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
717 { "Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[d]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n",
718 "Path=[S]\n",
719 "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n",
720 NULL, NULL } },
721
722 { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
723
724 { -1, NULL, 0, DEFDESCRIPT }
725 };
726
727
728 /*
729 * print a SMB message
730 */
731 static void
732 print_smb(const u_char *buf, const u_char *maxbuf)
733 {
734 int command;
735 const u_char *words, *data;
736 struct smbfns *fn;
737 const char *fmt_smbheader =
738 "[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n";
739
740
741 TCHECK(buf[9]);
742 request = (buf[9] & 0x80) ? 0 : 1;
743
744 command = buf[4];
745
746 fn = smbfind(command, smb_fns);
747
748 if (vflag > 1)
749 printf("\n");
750
751 printf("SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY");
752
753 if (vflag < 2)
754 return;
755
756 /* print out the header */
757 smb_fdata(buf, fmt_smbheader, buf + 33);
758
759 if (buf[5])
760 printf("SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7])));
761
762 words = buf + 32;
763 TCHECK(words[0]);
764
765 for (;;) {
766 const char *f1, *f2;
767 int wct;
768 u_int bcc;
769
770 TCHECK(words[0]);
771 wct = words[0];
772 data = words + 1 + wct * 2;
773
774 if (request) {
775 f1 = fn->descript.req_f1;
776 f2 = fn->descript.req_f2;
777 } else {
778 f1 = fn->descript.rep_f1;
779 f2 = fn->descript.rep_f2;
780 }
781
782 if (fn->descript.fn)
783 (*fn->descript.fn)(words, data, buf, maxbuf);
784 else {
785 if (wct) {
786 printf("smbvwv[]=\n");
787 if (f1)
788 smb_fdata(words + 1, f1, words + 1 + wct * 2);
789 else {
790 int i;
791 int v;
792
793 for (i = 0; i < wct; i++) {
794 TCHECK2(words[1 + 2 * i], 2);
795 v = EXTRACT_LE_16BITS(words + 1 + 2 * i);
796 printf("smb_vwv[%d]=%d (0x%X)\n", i, v, v);
797 }
798 }
799 }
800
801 TCHECK2(*data, 2);
802 bcc = EXTRACT_LE_16BITS(data);
803 if (f2) {
804 if (bcc > 0) {
805 printf("smbbuf[]=\n");
806 smb_fdata(data + 2, f2, data + 2 + bcc);
807 }
808 } else {
809 printf("smb_bcc=%u\n", bcc);
810 if (bcc > 0) {
811 printf("smb_buf[]=\n");
812 print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2)));
813 }
814 }
815 }
816
817 if ((fn->flags & FLG_CHAIN) == 0)
818 break;
819 if (wct == 0)
820 break;
821 TCHECK(words[1]);
822 command = EXTRACT_LE_16BITS(words + 1);
823 if (command == 0xFF)
824 break;
825 TCHECK2(words[3], 2);
826 words = buf + EXTRACT_LE_16BITS(words + 3);
827
828 fn = smbfind(command, smb_fns);
829
830 printf("\nSMB PACKET: %s (%s) (CHAINED)\n",
831 fn->name, request ? "REQUEST" : "REPLY");
832 }
833
834 printf("\n");
835 return;
836 trunc:
837 printf("[|SMB]");
838 return;
839 }
840
841
842 /*
843 * print a NBT packet received across tcp on port 139
844 */
845 void
846 nbt_tcp_print(const u_char *data, int length)
847 {
848 const u_char *maxbuf = data + length;
849 int type;
850 u_int nbt_len;
851
852 TCHECK2(data[2], 2);
853 type = data[0];
854 nbt_len = EXTRACT_16BITS(data + 2);
855
856 startbuf = data;
857 if (maxbuf <= data)
858 return;
859
860 if (vflag < 2) {
861 printf(" NBT Session Packet: ");
862 switch (type) {
863 case 0x00:
864 printf("Session Message");
865 break;
866
867 case 0x81:
868 printf("Session Request");
869 break;
870
871 case 0x82:
872 printf("Session Granted");
873 break;
874
875 case 0x83:
876 {
877 int ecode;
878
879 TCHECK(data[4]);
880 ecode = data[4];
881
882 printf("Session Reject, ");
883 switch (ecode) {
884 case 0x80:
885 printf("Not listening on called name");
886 break;
887 case 0x81:
888 printf("Not listening for calling name");
889 break;
890 case 0x82:
891 printf("Called name not present");
892 break;
893 case 0x83:
894 printf("Called name present, but insufficient resources");
895 break;
896 default:
897 printf("Unspecified error 0x%X", ecode);
898 break;
899 }
900 }
901 break;
902
903 case 0x85:
904 printf("Session Keepalive");
905 break;
906
907 default:
908 data = smb_fdata(data, "Unknown packet type [rB]", maxbuf);
909 break;
910 }
911 } else {
912 printf ("\n>>> NBT Session Packet\n");
913 switch (type) {
914 case 0x00:
915 data = smb_fdata(data, "[P1]NBT Session Message\nFlags=[rB]\nLength=[d]\n",
916 data + 4);
917 if (data == NULL)
918 break;
919 if (memcmp(data,"\377SMB",4) == 0) {
920 if (nbt_len > PTR_DIFF(maxbuf, data))
921 printf("WARNING: Short packet. Try increasing the snap length (%lu)\n",
922 (unsigned long)PTR_DIFF(maxbuf, data));
923 print_smb(data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
924 } else
925 printf("Session packet:(raw data?)\n");
926 break;
927
928 case 0x81:
929 data = smb_fdata(data,
930 "[P1]NBT Session Request\nFlags=[rB]\nDestination=[n1]\nSource=[n1]\n",
931 maxbuf);
932 break;
933
934 case 0x82:
935 data = smb_fdata(data, "[P1]NBT Session Granted\nFlags=[rB]\n", maxbuf);
936 break;
937
938 case 0x83:
939 {
940 int ecode;
941
942 TCHECK(data[4]);
943 ecode = data[4];
944
945 data = smb_fdata(data, "[P1]NBT SessionReject\nFlags=[rB]\nReason=[B]\n",
946 maxbuf);
947 switch (ecode) {
948 case 0x80:
949 printf("Not listening on called name\n");
950 break;
951 case 0x81:
952 printf("Not listening for calling name\n");
953 break;
954 case 0x82:
955 printf("Called name not present\n");
956 break;
957 case 0x83:
958 printf("Called name present, but insufficient resources\n");
959 break;
960 default:
961 printf("Unspecified error 0x%X\n", ecode);
962 break;
963 }
964 }
965 break;
966
967 case 0x85:
968 data = smb_fdata(data, "[P1]NBT Session Keepalive\nFlags=[rB]\n", maxbuf);
969 break;
970
971 default:
972 data = smb_fdata(data, "NBT - Unknown packet type\nType=[rB]\n", maxbuf);
973 break;
974 }
975 printf("\n");
976 fflush(stdout);
977 }
978 return;
979 trunc:
980 printf("[|SMB]");
981 return;
982 }
983
984
985 /*
986 * print a NBT packet received across udp on port 137
987 */
988 void
989 nbt_udp137_print(const u_char *data, int length)
990 {
991 const u_char *maxbuf = data + length;
992 int name_trn_id, response, opcode, nm_flags, rcode;
993 int qdcount, ancount, nscount, arcount;
994 const char *opcodestr;
995 const u_char *p;
996 int total, i;
997
998 TCHECK2(data[10], 2);
999 name_trn_id = EXTRACT_16BITS(data);
1000 response = (data[2] >> 7);
1001 opcode = (data[2] >> 3) & 0xF;
1002 nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
1003 rcode = data[3] & 0xF;
1004 qdcount = EXTRACT_16BITS(data + 4);
1005 ancount = EXTRACT_16BITS(data + 6);
1006 nscount = EXTRACT_16BITS(data + 8);
1007 arcount = EXTRACT_16BITS(data + 10);
1008 startbuf = data;
1009
1010 if (maxbuf <= data)
1011 return;
1012
1013 if (vflag > 1)
1014 printf("\n>>> ");
1015
1016 printf("NBT UDP PACKET(137): ");
1017
1018 switch (opcode) {
1019 case 0: opcodestr = "QUERY"; break;
1020 case 5: opcodestr = "REGISTRATION"; break;
1021 case 6: opcodestr = "RELEASE"; break;
1022 case 7: opcodestr = "WACK"; break;
1023 case 8: opcodestr = "REFRESH(8)"; break;
1024 case 9: opcodestr = "REFRESH"; break;
1025 case 15: opcodestr = "MULTIHOMED REGISTRATION"; break;
1026 default: opcodestr = "OPUNKNOWN"; break;
1027 }
1028 printf("%s", opcodestr);
1029 if (response) {
1030 if (rcode)
1031 printf("; NEGATIVE");
1032 else
1033 printf("; POSITIVE");
1034 }
1035
1036 if (response)
1037 printf("; RESPONSE");
1038 else
1039 printf("; REQUEST");
1040
1041 if (nm_flags & 1)
1042 printf("; BROADCAST");
1043 else
1044 printf("; UNICAST");
1045
1046 if (vflag < 2)
1047 return;
1048
1049 printf("\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n",
1050 name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
1051 arcount);
1052
1053 p = data + 12;
1054
1055 total = ancount + nscount + arcount;
1056
1057 if (qdcount > 100 || total > 100) {
1058 printf("Corrupt packet??\n");
1059 return;
1060 }
1061
1062 if (qdcount) {
1063 printf("QuestionRecords:\n");
1064 for (i = 0; i < qdcount; i++)
1065 p = smb_fdata(p,
1066 "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
1067 maxbuf);
1068 if (p == NULL)
1069 goto out;
1070 }
1071
1072 if (total) {
1073 printf("\nResourceRecords:\n");
1074 for (i = 0; i < total; i++) {
1075 int rdlen;
1076 int restype;
1077
1078 p = smb_fdata(p, "Name=[n1]\n#", maxbuf);
1079 if (p == NULL)
1080 goto out;
1081 restype = EXTRACT_16BITS(p);
1082 p = smb_fdata(p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8);
1083 if (p == NULL)
1084 goto out;
1085 rdlen = EXTRACT_16BITS(p);
1086 printf("ResourceLength=%d\nResourceData=\n", rdlen);
1087 p += 2;
1088 if (rdlen == 6) {
1089 p = smb_fdata(p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen);
1090 if (p == NULL)
1091 goto out;
1092 } else {
1093 if (restype == 0x21) {
1094 int numnames;
1095
1096 TCHECK(*p);
1097 numnames = p[0];
1098 p = smb_fdata(p, "NumNames=[B]\n", p + 1);
1099 if (p == NULL)
1100 goto out;
1101 while (numnames--) {
1102 p = smb_fdata(p, "Name=[n2]\t#", maxbuf);
1103 TCHECK(*p);
1104 if (p[0] & 0x80)
1105 printf("<GROUP> ");
1106 switch (p[0] & 0x60) {
1107 case 0x00: printf("B "); break;
1108 case 0x20: printf("P "); break;
1109 case 0x40: printf("M "); break;
1110 case 0x60: printf("_ "); break;
1111 }
1112 if (p[0] & 0x10)
1113 printf("<DEREGISTERING> ");
1114 if (p[0] & 0x08)
1115 printf("<CONFLICT> ");
1116 if (p[0] & 0x04)
1117 printf("<ACTIVE> ");
1118 if (p[0] & 0x02)
1119 printf("<PERMANENT> ");
1120 printf("\n");
1121 p += 2;
1122 }
1123 } else {
1124 print_data(p, min(rdlen, length - (p - data)));
1125 p += rdlen;
1126 }
1127 }
1128 }
1129 }
1130
1131 if (p < maxbuf)
1132 smb_fdata(p, "AdditionalData:\n", maxbuf);
1133
1134 out:
1135 printf("\n");
1136 fflush(stdout);
1137 return;
1138 trunc:
1139 printf("[|SMB]");
1140 return;
1141 }
1142
1143
1144
1145 /*
1146 * print a NBT packet received across udp on port 138
1147 */
1148 void
1149 nbt_udp138_print(const u_char *data, int length)
1150 {
1151 const u_char *maxbuf = data + length;
1152
1153 if (maxbuf > snapend)
1154 maxbuf = snapend;
1155 if (maxbuf <= data)
1156 return;
1157 startbuf = data;
1158
1159 if (vflag < 2) {
1160 printf("NBT UDP PACKET(138)");
1161 return;
1162 }
1163
1164 data = smb_fdata(data,
1165 "\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",
1166 maxbuf);
1167
1168 if (data != NULL) {
1169 /* If there isn't enough data for "\377SMB", don't check for it. */
1170 if (&data[3] >= maxbuf)
1171 goto out;
1172
1173 if (memcmp(data, "\377SMB",4) == 0)
1174 print_smb(data, maxbuf);
1175 }
1176 out:
1177 printf("\n");
1178 fflush(stdout);
1179 }
1180
1181
1182 /*
1183 print netbeui frames
1184 */
1185 struct nbf_strings {
1186 const char *name;
1187 const char *nonverbose;
1188 const char *verbose;
1189 } nbf_strings[0x20] = {
1190 { "Add Group Name Query", ", [P23]Name to add=[n2]#",
1191 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1192 { "Add Name Query", ", [P23]Name to add=[n2]#",
1193 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1194 { "Name In Conflict", NULL, NULL },
1195 { "Status Query", NULL, NULL },
1196 { NULL, NULL, NULL }, /* not used */
1197 { NULL, NULL, NULL }, /* not used */
1198 { NULL, NULL, NULL }, /* not used */
1199 { "Terminate Trace", NULL, NULL },
1200 { "Datagram", NULL,
1201 "[P7]Destination=[n2]\nSource=[n2]\n" },
1202 { "Broadcast Datagram", NULL,
1203 "[P7]Destination=[n2]\nSource=[n2]\n" },
1204 { "Name Query", ", [P7]Name=[n2]#",
1205 "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
1206 { NULL, NULL, NULL }, /* not used */
1207 { NULL, NULL, NULL }, /* not used */
1208 { "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
1209 "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
1210 { "Name Recognized", NULL,
1211 "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
1212 { "Status Response", NULL, NULL },
1213 { NULL, NULL, NULL }, /* not used */
1214 { NULL, NULL, NULL }, /* not used */
1215 { NULL, NULL, NULL }, /* not used */
1216 { "Terminate Trace", NULL, NULL },
1217 { "Data Ack", NULL,
1218 "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1219 { "Data First/Middle", NULL,
1220 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1221 { "Data Only/Last", NULL,
1222 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1223 { "Session Confirm", NULL,
1224 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1225 { "Session End", NULL,
1226 "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1227 { "Session Initialize", NULL,
1228 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1229 { "No Receive", NULL,
1230 "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1231 { "Receive Outstanding", NULL,
1232 "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1233 { "Receive Continue", NULL,
1234 "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1235 { NULL, NULL, NULL }, /* not used */
1236 { NULL, NULL, NULL }, /* not used */
1237 { "Session Alive", NULL, NULL }
1238 };
1239
1240 void
1241 netbeui_print(u_short control, const u_char *data, int length)
1242 {
1243 const u_char *maxbuf = data + length;
1244 int len;
1245 int command;
1246 const u_char *data2;
1247 int is_truncated = 0;
1248
1249 if (maxbuf > snapend)
1250 maxbuf = snapend;
1251 TCHECK(data[4]);
1252 len = EXTRACT_LE_16BITS(data);
1253 command = data[4];
1254 data2 = data + len;
1255 if (data2 >= maxbuf) {
1256 data2 = maxbuf;
1257 is_truncated = 1;
1258 }
1259
1260 startbuf = data;
1261
1262 if (vflag < 2) {
1263 printf("NBF Packet: ");
1264 data = smb_fdata(data, "[P5]#", maxbuf);
1265 } else {
1266 printf("\n>>> NBF Packet\nType=0x%X ", control);
1267 data = smb_fdata(data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf);
1268 }
1269 if (data == NULL)
1270 goto out;
1271
1272 if (command > 0x1f || nbf_strings[command].name == NULL) {
1273 if (vflag < 2)
1274 data = smb_fdata(data, "Unknown NBF Command#", data2);
1275 else
1276 data = smb_fdata(data, "Unknown NBF Command\n", data2);
1277 } else {
1278 if (vflag < 2) {
1279 printf("%s", nbf_strings[command].name);
1280 if (nbf_strings[command].nonverbose != NULL)
1281 data = smb_fdata(data, nbf_strings[command].nonverbose, data2);
1282 } else {
1283 printf("%s:\n", nbf_strings[command].name);
1284 if (nbf_strings[command].verbose != NULL)
1285 data = smb_fdata(data, nbf_strings[command].verbose, data2);
1286 else
1287 printf("\n");
1288 }
1289 }
1290
1291 if (vflag < 2)
1292 return;
1293
1294 if (data == NULL)
1295 goto out;
1296
1297 if (is_truncated) {
1298 /* data2 was past the end of the buffer */
1299 goto out;
1300 }
1301
1302 /* If this isn't a command that would contain an SMB message, quit. */
1303 if (command != 0x08 && command != 0x09 && command != 0x15 &&
1304 command != 0x16)
1305 goto out;
1306
1307 /* If there isn't enough data for "\377SMB", don't look for it. */
1308 if (&data2[3] >= maxbuf)
1309 goto out;
1310
1311 if (memcmp(data2, "\377SMB",4) == 0)
1312 print_smb(data2, maxbuf);
1313 else {
1314 int i;
1315 for (i = 0; i < 128; i++) {
1316 if (&data2[i + 3] >= maxbuf)
1317 break;
1318 if (memcmp(&data2[i], "\377SMB", 4) == 0) {
1319 printf("found SMB packet at %d\n", i);
1320 print_smb(&data2[i], maxbuf);
1321 break;
1322 }
1323 }
1324 }
1325
1326 out:
1327 printf("\n");
1328 return;
1329 trunc:
1330 printf("[|SMB]");
1331 return;
1332 }
1333
1334
1335 /*
1336 * print IPX-Netbios frames
1337 */
1338 void
1339 ipx_netbios_print(const u_char *data, u_int length)
1340 {
1341 /*
1342 * this is a hack till I work out how to parse the rest of the
1343 * NetBIOS-over-IPX stuff
1344 */
1345 int i;
1346 const u_char *maxbuf;
1347
1348 maxbuf = data + length;
1349 /* Don't go past the end of the captured data in the packet. */
1350 if (maxbuf > snapend)
1351 maxbuf = snapend;
1352 startbuf = data;
1353 for (i = 0; i < 128; i++) {
1354 if (&data[i + 4] > maxbuf)
1355 break;
1356 if (memcmp(&data[i], "\377SMB", 4) == 0) {
1357 smb_fdata(data, "\n>>> IPX transport ", &data[i]);
1358 if (data != NULL)
1359 print_smb(&data[i], maxbuf);
1360 printf("\n");
1361 fflush(stdout);
1362 break;
1363 }
1364 }
1365 if (i == 128)
1366 smb_fdata(data, "\n>>> Unknown IPX ", maxbuf);
1367 }