]> The Tcpdump Group git mirrors - tcpdump/blob - print-smb.c
648cfe807e97e850bde083937b3899c59576d031
[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.33 2004-12-28 09:16:09 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 u_int bcc;
334 const char *f1, *f2, *f3, *f4;
335 const u_char *data, *param;
336 const u_char *w = words + 1;
337 int datalen, paramlen;
338
339 if (request) {
340 TCHECK2(w[12 * 2], 2);
341 paramlen = EXTRACT_LE_16BITS(w + 9 * 2);
342 param = buf + EXTRACT_LE_16BITS(w + 10 * 2);
343 datalen = EXTRACT_LE_16BITS(w + 11 * 2);
344 data = buf + EXTRACT_LE_16BITS(w + 12 * 2);
345 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";
346 f2 = "|Name=[S]\n";
347 f3 = "|Param ";
348 f4 = "|Data ";
349 } else {
350 TCHECK2(w[7 * 2], 2);
351 paramlen = EXTRACT_LE_16BITS(w + 3 * 2);
352 param = buf + EXTRACT_LE_16BITS(w + 4 * 2);
353 datalen = EXTRACT_LE_16BITS(w + 6 * 2);
354 data = buf + EXTRACT_LE_16BITS(w + 7 * 2);
355 f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n";
356 f2 = "|Unknown ";
357 f3 = "|Param ";
358 f4 = "|Data ";
359 }
360
361 smb_fdata(words + 1, f1, SMBMIN(words + 1 + 2 * words[0], maxbuf));
362
363 TCHECK2(*data, 2);
364 bcc = EXTRACT_LE_16BITS(data);
365 printf("smb_bcc=%u\n", bcc);
366 smb_fdata(data1 + 2, f2, maxbuf - (paramlen + datalen));
367
368 if (strcmp((const char *)(data1 + 2), "\\MAILSLOT\\BROWSE") == 0) {
369 print_browse(param, paramlen, data, datalen);
370 return;
371 }
372
373 if (strcmp((const char *)(data1 + 2), "\\PIPE\\LANMAN") == 0) {
374 print_ipc(param, paramlen, data, datalen);
375 return;
376 }
377
378 if (paramlen)
379 smb_fdata(param, f3, SMBMIN(param + paramlen, maxbuf));
380 if (datalen)
381 smb_fdata(data, f4, SMBMIN(data + datalen, maxbuf));
382 return;
383 trunc:
384 printf("[|SMB]");
385 return;
386 }
387
388
389 static void
390 print_negprot(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
391 {
392 u_int wct, bcc;
393 const char *f1 = NULL, *f2 = NULL;
394
395 TCHECK(words[0]);
396 wct = words[0];
397 if (request)
398 f2 = "*|Dialect=[Z]\n";
399 else {
400 if (wct == 1)
401 f1 = "Core Protocol\nDialectIndex=[d]";
402 else if (wct == 17)
403 f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey=";
404 else if (wct == 13)
405 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=";
406 }
407
408 if (f1)
409 smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf));
410 else
411 print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1)));
412
413 TCHECK2(*data, 2);
414 bcc = EXTRACT_LE_16BITS(data);
415 printf("smb_bcc=%u\n", bcc);
416 if (f2)
417 smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf));
418 else
419 print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
420 return;
421 trunc:
422 printf("[|SMB]");
423 return;
424 }
425
426 static void
427 print_sesssetup(const u_char *words, const u_char *data, const u_char *buf _U_, const u_char *maxbuf)
428 {
429 u_int wct, bcc;
430 const char *f1 = NULL, *f2 = NULL;
431
432 TCHECK(words[0]);
433 wct = words[0];
434 if (request) {
435 if (wct == 10)
436 f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n";
437 else
438 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";
439 } else {
440 if (wct == 3) {
441 f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n";
442 } else if (wct == 13) {
443 f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n";
444 f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n";
445 }
446 }
447
448 if (f1)
449 smb_fdata(words + 1, f1, SMBMIN(words + 1 + wct * 2, maxbuf));
450 else
451 print_data(words + 1, SMBMIN(wct * 2, PTR_DIFF(maxbuf, words + 1)));
452
453 TCHECK2(*data, 2);
454 bcc = EXTRACT_LE_16BITS(data);
455 printf("smb_bcc=%u\n", bcc);
456 if (f2)
457 smb_fdata(data + 2, f2, SMBMIN(data + 2 + EXTRACT_LE_16BITS(data), maxbuf));
458 else
459 print_data(data + 2, SMBMIN(EXTRACT_LE_16BITS(data), PTR_DIFF(maxbuf, data + 2)));
460 return;
461 trunc:
462 printf("[|SMB]");
463 return;
464 }
465
466
467 static struct smbfns smb_fns[] = {
468 { -1, "SMBunknown", 0, DEFDESCRIPT },
469
470 { SMBtcon, "SMBtcon", 0,
471 { NULL, "Path=[Z]\nPassword=[Z]\nDevice=[Z]\n",
472 "MaxXmit=[d]\nTreeId=[d]\n", NULL,
473 NULL } },
474
475 { SMBtdis, "SMBtdis", 0, DEFDESCRIPT },
476 { SMBexit, "SMBexit", 0, DEFDESCRIPT },
477 { SMBioctl, "SMBioctl", 0, DEFDESCRIPT },
478
479 { SMBecho, "SMBecho", 0,
480 { "ReverbCount=[d]\n", NULL,
481 "SequenceNum=[d]\n", NULL,
482 NULL } },
483
484 { SMBulogoffX, "SMBulogoffX", FLG_CHAIN, DEFDESCRIPT },
485
486 { SMBgetatr, "SMBgetatr", 0,
487 { NULL, "Path=[Z]\n",
488 "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n", NULL,
489 NULL } },
490
491 { SMBsetatr, "SMBsetatr", 0,
492 { "Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n", "Path=[Z]\n",
493 NULL, NULL, NULL } },
494
495 { SMBchkpth, "SMBchkpth", 0,
496 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
497
498 { SMBsearch, "SMBsearch", 0,
499 { "Count=[d]\nAttrib=[A]\n",
500 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n",
501 "Count=[d]\n",
502 "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",
503 NULL } },
504
505 { SMBopen, "SMBopen", 0,
506 { "Mode=[w]\nAttribute=[A]\n", "Path=[Z]\n",
507 "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",
508 NULL, NULL } },
509
510 { SMBcreate, "SMBcreate", 0,
511 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
512
513 { SMBmknew, "SMBmknew", 0,
514 { "Attrib=[A]\nTime=[T2]", "Path=[Z]\n", "Handle=[d]\n", NULL, NULL } },
515
516 { SMBunlink, "SMBunlink", 0,
517 { "Attrib=[A]\n", "Path=[Z]\n", NULL, NULL, NULL } },
518
519 { SMBread, "SMBread", 0,
520 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
521 "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
522
523 { SMBwrite, "SMBwrite", 0,
524 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
525 "Count=[d]\n", NULL, NULL } },
526
527 { SMBclose, "SMBclose", 0,
528 { "Handle=[d]\nTime=[T2]", NULL, NULL, NULL, NULL } },
529
530 { SMBmkdir, "SMBmkdir", 0,
531 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
532
533 { SMBrmdir, "SMBrmdir", 0,
534 { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
535
536 { SMBdskattr, "SMBdskattr", 0,
537 { NULL, NULL,
538 "TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n",
539 NULL, NULL } },
540
541 { SMBmv, "SMBmv", 0,
542 { "Attrib=[A]\n", "OldPath=[Z]\nNewPath=[Z]\n", NULL, NULL, NULL } },
543
544 /*
545 * this is a Pathworks specific call, allowing the
546 * changing of the root path
547 */
548 { pSETDIR, "SMBsetdir", 0, { NULL, "Path=[Z]\n", NULL, NULL, NULL } },
549
550 { SMBlseek, "SMBlseek", 0,
551 { "Handle=[d]\nMode=[w]\nOffset=[D]\n", "Offset=[D]\n", NULL, NULL, NULL } },
552
553 { SMBflush, "SMBflush", 0, { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
554
555 { SMBsplopen, "SMBsplopen", 0,
556 { "SetupLen=[d]\nMode=[w]\n", "Ident=[Z]\n", "Handle=[d]\n",
557 NULL, NULL } },
558
559 { SMBsplclose, "SMBsplclose", 0,
560 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
561
562 { SMBsplretq, "SMBsplretq", 0,
563 { "MaxCount=[d]\nStartIndex=[d]\n", NULL,
564 "Count=[d]\nIndex=[d]\n",
565 "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n",
566 NULL } },
567
568 { SMBsplwr, "SMBsplwr", 0,
569 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
570
571 { SMBlock, "SMBlock", 0,
572 { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
573
574 { SMBunlock, "SMBunlock", 0,
575 { "Handle=[d]\nCount=[D]\nOffset=[D]\n", NULL, NULL, NULL, NULL } },
576
577 /* CORE+ PROTOCOL FOLLOWS */
578
579 { SMBreadbraw, "SMBreadbraw", 0,
580 { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n",
581 NULL, NULL, NULL, NULL } },
582
583 { SMBwritebraw, "SMBwritebraw", 0,
584 { "Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n",
585 NULL, "WriteRawAck", NULL, NULL } },
586
587 { SMBwritec, "SMBwritec", 0,
588 { NULL, NULL, "Count=[d]\n", NULL, NULL } },
589
590 { SMBwriteclose, "SMBwriteclose", 0,
591 { "Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",
592 NULL, "Count=[d]\n", NULL, NULL } },
593
594 { SMBlockread, "SMBlockread", 0,
595 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
596 "Count=[d]\nRes=([w,w,w,w])\n", NULL, NULL } },
597
598 { SMBwriteunlock, "SMBwriteunlock", 0,
599 { "Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n", NULL,
600 "Count=[d]\n", NULL, NULL } },
601
602 { SMBreadBmpx, "SMBreadBmpx", 0,
603 { "Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n",
604 NULL,
605 "Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n",
606 NULL, NULL } },
607
608 { SMBwriteBmpx, "SMBwriteBmpx", 0,
609 { "Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n", NULL,
610 "Remaining=[d]\n", NULL, NULL } },
611
612 { SMBwriteBs, "SMBwriteBs", 0,
613 { "Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",
614 NULL, "Count=[d]\n", NULL, NULL } },
615
616 { SMBsetattrE, "SMBsetattrE", 0,
617 { "Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]", NULL,
618 NULL, NULL, NULL } },
619
620 { SMBgetattrE, "SMBgetattrE", 0,
621 { "Handle=[d]\n", NULL,
622 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",
623 NULL, NULL } },
624
625 { SMBtranss, "SMBtranss", 0, DEFDESCRIPT },
626 { SMBioctls, "SMBioctls", 0, DEFDESCRIPT },
627
628 { SMBcopy, "SMBcopy", 0,
629 { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
630 "CopyCount=[d]\n", "|ErrStr=[S]\n", NULL } },
631
632 { SMBmove, "SMBmove", 0,
633 { "TreeID2=[d]\nOFun=[w]\nFlags=[w]\n", "Path=[S]\nNewPath=[S]\n",
634 "MoveCount=[d]\n", "|ErrStr=[S]\n", NULL } },
635
636 { SMBopenX, "SMBopenX", FLG_CHAIN,
637 { "Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n",
638 "Path=[S]\n",
639 "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",
640 NULL, NULL } },
641
642 { SMBreadX, "SMBreadX", FLG_CHAIN,
643 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",
644 NULL,
645 "Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",
646 NULL, NULL } },
647
648 { SMBwriteX, "SMBwriteX", FLG_CHAIN,
649 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",
650 NULL,
651 "Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",
652 NULL, NULL } },
653
654 { SMBlockingX, "SMBlockingX", FLG_CHAIN,
655 { "Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n",
656 "*Process=[d]\nOffset=[D]\nLength=[D]\n",
657 "Com2=[w]\nOff2=[d]\n", NULL, NULL } },
658
659 { SMBffirst, "SMBffirst", 0,
660 { "Count=[d]\nAttrib=[A]\n",
661 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
662 "Count=[d]\n",
663 "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",
664 NULL } },
665
666 { SMBfunique, "SMBfunique", 0,
667 { "Count=[d]\nAttrib=[A]\n",
668 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
669 "Count=[d]\n",
670 "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",
671 NULL } },
672
673 { SMBfclose, "SMBfclose", 0,
674 { "Count=[d]\nAttrib=[A]\n",
675 "Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n",
676 "Count=[d]\n",
677 "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",
678 NULL } },
679
680 { SMBfindnclose, "SMBfindnclose", 0,
681 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
682
683 { SMBfindclose, "SMBfindclose", 0,
684 { "Handle=[d]\n", NULL, NULL, NULL, NULL } },
685
686 { SMBsends, "SMBsends", 0,
687 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
688
689 { SMBsendstrt, "SMBsendstrt", 0,
690 { NULL, "Source=[Z]\nDest=[Z]\n", "GroupID=[d]\n", NULL, NULL } },
691
692 { SMBsendend, "SMBsendend", 0,
693 { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
694
695 { SMBsendtxt, "SMBsendtxt", 0,
696 { "GroupID=[d]\n", NULL, NULL, NULL, NULL } },
697
698 { SMBsendb, "SMBsendb", 0,
699 { NULL, "Source=[Z]\nDest=[Z]\n", NULL, NULL, NULL } },
700
701 { SMBfwdname, "SMBfwdname", 0, DEFDESCRIPT },
702 { SMBcancelf, "SMBcancelf", 0, DEFDESCRIPT },
703 { SMBgetmac, "SMBgetmac", 0, DEFDESCRIPT },
704
705 { SMBnegprot, "SMBnegprot", 0,
706 { NULL, NULL, NULL, NULL, print_negprot } },
707
708 { SMBsesssetupX, "SMBsesssetupX", FLG_CHAIN,
709 { NULL, NULL, NULL, NULL, print_sesssetup } },
710
711 { SMBtconX, "SMBtconX", FLG_CHAIN,
712 { "Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",
713 NULL, "Com2=[w]\nOff2=[d]\n", "ServiceType=[S]\n", NULL } },
714
715 { SMBtrans2, "SMBtrans2", 0, { NULL, NULL, NULL, NULL, print_trans2 } },
716
717 { SMBtranss2, "SMBtranss2", 0, DEFDESCRIPT },
718 { SMBctemp, "SMBctemp", 0, DEFDESCRIPT },
719 { SMBreadBs, "SMBreadBs", 0, DEFDESCRIPT },
720 { SMBtrans, "SMBtrans", 0, { NULL, NULL, NULL, NULL, print_trans } },
721
722 { SMBnttrans, "SMBnttrans", 0, DEFDESCRIPT },
723 { SMBnttranss, "SMBnttranss", 0, DEFDESCRIPT },
724
725 { SMBntcreateX, "SMBntcreateX", FLG_CHAIN,
726 { "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",
727 "Path=[S]\n",
728 "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",
729 NULL, NULL } },
730
731 { SMBntcancel, "SMBntcancel", 0, DEFDESCRIPT },
732
733 { -1, NULL, 0, DEFDESCRIPT }
734 };
735
736
737 /*
738 * print a SMB message
739 */
740 static void
741 print_smb(const u_char *buf, const u_char *maxbuf)
742 {
743 int command;
744 const u_char *words, *data;
745 struct smbfns *fn;
746 const char *fmt_smbheader =
747 "[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";
748
749
750 TCHECK(buf[9]);
751 request = (buf[9] & 0x80) ? 0 : 1;
752
753 command = buf[4];
754
755 fn = smbfind(command, smb_fns);
756
757 if (vflag > 1)
758 printf("\n");
759
760 printf("SMB PACKET: %s (%s)\n", fn->name, request ? "REQUEST" : "REPLY");
761
762 if (vflag < 2)
763 return;
764
765 /* print out the header */
766 smb_fdata(buf, fmt_smbheader, buf + 33);
767
768 if (buf[5])
769 printf("SMBError = %s\n", smb_errstr(buf[5], EXTRACT_LE_16BITS(&buf[7])));
770
771 words = buf + 32;
772 TCHECK(words[0]);
773
774 for (;;) {
775 const char *f1, *f2;
776 int wct;
777 u_int bcc;
778
779 TCHECK(words[0]);
780 wct = words[0];
781 data = words + 1 + wct * 2;
782
783 if (request) {
784 f1 = fn->descript.req_f1;
785 f2 = fn->descript.req_f2;
786 } else {
787 f1 = fn->descript.rep_f1;
788 f2 = fn->descript.rep_f2;
789 }
790
791 if (fn->descript.fn)
792 (*fn->descript.fn)(words, data, buf, maxbuf);
793 else {
794 if (wct) {
795 if (f1)
796 smb_fdata(words + 1, f1, words + 1 + wct * 2);
797 else {
798 int i;
799 int v;
800
801 for (i = 0; i < wct; i++) {
802 TCHECK2(words[1 + 2 * i], 2);
803 v = EXTRACT_LE_16BITS(words + 1 + 2 * i);
804 printf("smb_vwv[%d]=%d (0x%X)\n", i, v, v);
805 }
806 }
807 }
808
809 TCHECK2(*data, 2);
810 bcc = EXTRACT_LE_16BITS(data);
811 printf("smb_bcc=%u\n", bcc);
812 if (f2) {
813 if (bcc > 0)
814 smb_fdata(data + 2, f2, data + 2 + bcc);
815 } else {
816 if (bcc > 0) {
817 printf("smb_buf[]=\n");
818 print_data(data + 2, SMBMIN(bcc, PTR_DIFF(maxbuf, data + 2)));
819 }
820 }
821 }
822
823 if ((fn->flags & FLG_CHAIN) == 0)
824 break;
825 if (wct == 0)
826 break;
827 TCHECK(words[1]);
828 command = EXTRACT_LE_16BITS(words + 1);
829 if (command == 0xFF)
830 break;
831 TCHECK2(words[3], 2);
832 words = buf + EXTRACT_LE_16BITS(words + 3);
833
834 fn = smbfind(command, smb_fns);
835
836 printf("\nSMB PACKET: %s (%s) (CHAINED)\n",
837 fn->name, request ? "REQUEST" : "REPLY");
838 }
839
840 printf("\n");
841 return;
842 trunc:
843 printf("[|SMB]");
844 return;
845 }
846
847
848 /*
849 * print a NBT packet received across tcp on port 139
850 */
851 void
852 nbt_tcp_print(const u_char *data, int length)
853 {
854 const u_char *maxbuf = data + length;
855 int type;
856 u_int nbt_len;
857
858 TCHECK2(data[2], 2);
859 type = data[0];
860 nbt_len = EXTRACT_16BITS(data + 2);
861
862 startbuf = data;
863 if (maxbuf <= data)
864 return;
865
866 if (vflag < 2) {
867 printf(" NBT Session Packet: ");
868 switch (type) {
869 case 0x00:
870 printf("Session Message");
871 break;
872
873 case 0x81:
874 printf("Session Request");
875 break;
876
877 case 0x82:
878 printf("Session Granted");
879 break;
880
881 case 0x83:
882 {
883 int ecode;
884
885 TCHECK(data[4]);
886 ecode = data[4];
887
888 printf("Session Reject, ");
889 switch (ecode) {
890 case 0x80:
891 printf("Not listening on called name");
892 break;
893 case 0x81:
894 printf("Not listening for calling name");
895 break;
896 case 0x82:
897 printf("Called name not present");
898 break;
899 case 0x83:
900 printf("Called name present, but insufficient resources");
901 break;
902 default:
903 printf("Unspecified error 0x%X", ecode);
904 break;
905 }
906 }
907 break;
908
909 case 0x85:
910 printf("Session Keepalive");
911 break;
912
913 default:
914 data = smb_fdata(data, "Unknown packet type [rB]", maxbuf);
915 break;
916 }
917 } else {
918 printf ("\n>>> NBT Session Packet\n");
919 switch (type) {
920 case 0x00:
921 data = smb_fdata(data, "[P1]NBT Session Message\nFlags=[B]\nLength=[rd]\n",
922 data + 4);
923 if (data == NULL)
924 break;
925 if (memcmp(data,"\377SMB",4) == 0) {
926 if (nbt_len > PTR_DIFF(maxbuf, data))
927 printf("WARNING: Short packet. Try increasing the snap length (%lu)\n",
928 (unsigned long)PTR_DIFF(maxbuf, data));
929 print_smb(data, maxbuf > data + nbt_len ? data + nbt_len : maxbuf);
930 } else
931 printf("Session packet:(raw data?)\n");
932 break;
933
934 case 0x81:
935 data = smb_fdata(data,
936 "[P1]NBT Session Request\nFlags=[B]\nLength=[rd]\nDestination=[n1]\nSource=[n1]\n",
937 maxbuf);
938 break;
939
940 case 0x82:
941 data = smb_fdata(data, "[P1]NBT Session Granted\nFlags=[B]\nLength=[rd]\n", maxbuf);
942 break;
943
944 case 0x83:
945 {
946 int ecode;
947
948 TCHECK(data[4]);
949 ecode = data[4];
950
951 data = smb_fdata(data, "[P1]NBT SessionReject\nFlags=[B]\nLength=[rd]\nReason=[B]\n",
952 maxbuf);
953 switch (ecode) {
954 case 0x80:
955 printf("Not listening on called name\n");
956 break;
957 case 0x81:
958 printf("Not listening for calling name\n");
959 break;
960 case 0x82:
961 printf("Called name not present\n");
962 break;
963 case 0x83:
964 printf("Called name present, but insufficient resources\n");
965 break;
966 default:
967 printf("Unspecified error 0x%X\n", ecode);
968 break;
969 }
970 }
971 break;
972
973 case 0x85:
974 data = smb_fdata(data, "[P1]NBT Session Keepalive\nFlags=[B]\nLength=[rd]\n", maxbuf);
975 break;
976
977 default:
978 data = smb_fdata(data, "NBT - Unknown packet type\nType=[B]\n", maxbuf);
979 break;
980 }
981 printf("\n");
982 fflush(stdout);
983 }
984 return;
985 trunc:
986 printf("[|SMB]");
987 return;
988 }
989
990
991 /*
992 * print a NBT packet received across udp on port 137
993 */
994 void
995 nbt_udp137_print(const u_char *data, int length)
996 {
997 const u_char *maxbuf = data + length;
998 int name_trn_id, response, opcode, nm_flags, rcode;
999 int qdcount, ancount, nscount, arcount;
1000 const char *opcodestr;
1001 const u_char *p;
1002 int total, i;
1003
1004 TCHECK2(data[10], 2);
1005 name_trn_id = EXTRACT_16BITS(data);
1006 response = (data[2] >> 7);
1007 opcode = (data[2] >> 3) & 0xF;
1008 nm_flags = ((data[2] & 0x7) << 4) + (data[3] >> 4);
1009 rcode = data[3] & 0xF;
1010 qdcount = EXTRACT_16BITS(data + 4);
1011 ancount = EXTRACT_16BITS(data + 6);
1012 nscount = EXTRACT_16BITS(data + 8);
1013 arcount = EXTRACT_16BITS(data + 10);
1014 startbuf = data;
1015
1016 if (maxbuf <= data)
1017 return;
1018
1019 if (vflag > 1)
1020 printf("\n>>> ");
1021
1022 printf("NBT UDP PACKET(137): ");
1023
1024 switch (opcode) {
1025 case 0: opcodestr = "QUERY"; break;
1026 case 5: opcodestr = "REGISTRATION"; break;
1027 case 6: opcodestr = "RELEASE"; break;
1028 case 7: opcodestr = "WACK"; break;
1029 case 8: opcodestr = "REFRESH(8)"; break;
1030 case 9: opcodestr = "REFRESH"; break;
1031 case 15: opcodestr = "MULTIHOMED REGISTRATION"; break;
1032 default: opcodestr = "OPUNKNOWN"; break;
1033 }
1034 printf("%s", opcodestr);
1035 if (response) {
1036 if (rcode)
1037 printf("; NEGATIVE");
1038 else
1039 printf("; POSITIVE");
1040 }
1041
1042 if (response)
1043 printf("; RESPONSE");
1044 else
1045 printf("; REQUEST");
1046
1047 if (nm_flags & 1)
1048 printf("; BROADCAST");
1049 else
1050 printf("; UNICAST");
1051
1052 if (vflag < 2)
1053 return;
1054
1055 printf("\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n",
1056 name_trn_id, opcode, nm_flags, rcode, qdcount, ancount, nscount,
1057 arcount);
1058
1059 p = data + 12;
1060
1061 total = ancount + nscount + arcount;
1062
1063 if (qdcount > 100 || total > 100) {
1064 printf("Corrupt packet??\n");
1065 return;
1066 }
1067
1068 if (qdcount) {
1069 printf("QuestionRecords:\n");
1070 for (i = 0; i < qdcount; i++)
1071 p = smb_fdata(p,
1072 "|Name=[n1]\nQuestionType=[rw]\nQuestionClass=[rw]\n#",
1073 maxbuf);
1074 if (p == NULL)
1075 goto out;
1076 }
1077
1078 if (total) {
1079 printf("\nResourceRecords:\n");
1080 for (i = 0; i < total; i++) {
1081 int rdlen;
1082 int restype;
1083
1084 p = smb_fdata(p, "Name=[n1]\n#", maxbuf);
1085 if (p == NULL)
1086 goto out;
1087 restype = EXTRACT_16BITS(p);
1088 p = smb_fdata(p, "ResType=[rw]\nResClass=[rw]\nTTL=[rD]\n", p + 8);
1089 if (p == NULL)
1090 goto out;
1091 rdlen = EXTRACT_16BITS(p);
1092 printf("ResourceLength=%d\nResourceData=\n", rdlen);
1093 p += 2;
1094 if (rdlen == 6) {
1095 p = smb_fdata(p, "AddrType=[rw]\nAddress=[b.b.b.b]\n", p + rdlen);
1096 if (p == NULL)
1097 goto out;
1098 } else {
1099 if (restype == 0x21) {
1100 int numnames;
1101
1102 TCHECK(*p);
1103 numnames = p[0];
1104 p = smb_fdata(p, "NumNames=[B]\n", p + 1);
1105 if (p == NULL)
1106 goto out;
1107 while (numnames--) {
1108 p = smb_fdata(p, "Name=[n2]\t#", maxbuf);
1109 TCHECK(*p);
1110 if (p[0] & 0x80)
1111 printf("<GROUP> ");
1112 switch (p[0] & 0x60) {
1113 case 0x00: printf("B "); break;
1114 case 0x20: printf("P "); break;
1115 case 0x40: printf("M "); break;
1116 case 0x60: printf("_ "); break;
1117 }
1118 if (p[0] & 0x10)
1119 printf("<DEREGISTERING> ");
1120 if (p[0] & 0x08)
1121 printf("<CONFLICT> ");
1122 if (p[0] & 0x04)
1123 printf("<ACTIVE> ");
1124 if (p[0] & 0x02)
1125 printf("<PERMANENT> ");
1126 printf("\n");
1127 p += 2;
1128 }
1129 } else {
1130 print_data(p, min(rdlen, length - (p - data)));
1131 p += rdlen;
1132 }
1133 }
1134 }
1135 }
1136
1137 if (p < maxbuf)
1138 smb_fdata(p, "AdditionalData:\n", maxbuf);
1139
1140 out:
1141 printf("\n");
1142 fflush(stdout);
1143 return;
1144 trunc:
1145 printf("[|SMB]");
1146 return;
1147 }
1148
1149
1150
1151 /*
1152 * print a NBT packet received across udp on port 138
1153 */
1154 void
1155 nbt_udp138_print(const u_char *data, int length)
1156 {
1157 const u_char *maxbuf = data + length;
1158
1159 if (maxbuf > snapend)
1160 maxbuf = snapend;
1161 if (maxbuf <= data)
1162 return;
1163 startbuf = data;
1164
1165 if (vflag < 2) {
1166 printf("NBT UDP PACKET(138)");
1167 return;
1168 }
1169
1170 data = smb_fdata(data,
1171 "\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#",
1172 maxbuf);
1173
1174 if (data != NULL) {
1175 /* If there isn't enough data for "\377SMB", don't check for it. */
1176 if (&data[3] >= maxbuf)
1177 goto out;
1178
1179 if (memcmp(data, "\377SMB",4) == 0)
1180 print_smb(data, maxbuf);
1181 }
1182 out:
1183 printf("\n");
1184 fflush(stdout);
1185 }
1186
1187
1188 /*
1189 print netbeui frames
1190 */
1191 struct nbf_strings {
1192 const char *name;
1193 const char *nonverbose;
1194 const char *verbose;
1195 } nbf_strings[0x20] = {
1196 { "Add Group Name Query", ", [P23]Name to add=[n2]#",
1197 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1198 { "Add Name Query", ", [P23]Name to add=[n2]#",
1199 "[P5]ResponseCorrelator=[w]\n[P16]Name to add=[n2]\n" },
1200 { "Name In Conflict", NULL, NULL },
1201 { "Status Query", NULL, NULL },
1202 { NULL, NULL, NULL }, /* not used */
1203 { NULL, NULL, NULL }, /* not used */
1204 { NULL, NULL, NULL }, /* not used */
1205 { "Terminate Trace", NULL, NULL },
1206 { "Datagram", NULL,
1207 "[P7]Destination=[n2]\nSource=[n2]\n" },
1208 { "Broadcast Datagram", NULL,
1209 "[P7]Destination=[n2]\nSource=[n2]\n" },
1210 { "Name Query", ", [P7]Name=[n2]#",
1211 "[P1]SessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nName=[n2]\nName of sender=[n2]\n" },
1212 { NULL, NULL, NULL }, /* not used */
1213 { NULL, NULL, NULL }, /* not used */
1214 { "Add Name Response", ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#",
1215 "AddNameInProcess=[B]\nGroupName=[w]\nTransmitCorrelator=[w][P2]\nDestination=[n2]\nSource=[n2]\n" },
1216 { "Name Recognized", NULL,
1217 "[P1]Data2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n" },
1218 { "Status Response", NULL, NULL },
1219 { NULL, NULL, NULL }, /* not used */
1220 { NULL, NULL, NULL }, /* not used */
1221 { NULL, NULL, NULL }, /* not used */
1222 { "Terminate Trace", NULL, NULL },
1223 { "Data Ack", NULL,
1224 "[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1225 { "Data First/Middle", NULL,
1226 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1227 { "Data Only/Last", NULL,
1228 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1229 { "Session Confirm", NULL,
1230 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1231 { "Session End", NULL,
1232 "[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1233 { "Session Initialize", NULL,
1234 "Data1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1235 { "No Receive", NULL,
1236 "Flags=[{|SEND_NO_ACK}]\nDataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1237 { "Receive Outstanding", NULL,
1238 "[P1]DataBytesAccepted=[b][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1239 { "Receive Continue", NULL,
1240 "[P2]TransmitCorrelator=[w]\n[P2]RemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n" },
1241 { NULL, NULL, NULL }, /* not used */
1242 { NULL, NULL, NULL }, /* not used */
1243 { "Session Alive", NULL, NULL }
1244 };
1245
1246 void
1247 netbeui_print(u_short control, const u_char *data, int length)
1248 {
1249 const u_char *maxbuf = data + length;
1250 int len;
1251 int command;
1252 const u_char *data2;
1253 int is_truncated = 0;
1254
1255 if (maxbuf > snapend)
1256 maxbuf = snapend;
1257 TCHECK(data[4]);
1258 len = EXTRACT_LE_16BITS(data);
1259 command = data[4];
1260 data2 = data + len;
1261 if (data2 >= maxbuf) {
1262 data2 = maxbuf;
1263 is_truncated = 1;
1264 }
1265
1266 startbuf = data;
1267
1268 if (vflag < 2) {
1269 printf("NBF Packet: ");
1270 data = smb_fdata(data, "[P5]#", maxbuf);
1271 } else {
1272 printf("\n>>> NBF Packet\nType=0x%X ", control);
1273 data = smb_fdata(data, "Length=[d] Signature=[w] Command=[B]\n#", maxbuf);
1274 }
1275 if (data == NULL)
1276 goto out;
1277
1278 if (command > 0x1f || nbf_strings[command].name == NULL) {
1279 if (vflag < 2)
1280 data = smb_fdata(data, "Unknown NBF Command#", data2);
1281 else
1282 data = smb_fdata(data, "Unknown NBF Command\n", data2);
1283 } else {
1284 if (vflag < 2) {
1285 printf("%s", nbf_strings[command].name);
1286 if (nbf_strings[command].nonverbose != NULL)
1287 data = smb_fdata(data, nbf_strings[command].nonverbose, data2);
1288 } else {
1289 printf("%s:\n", nbf_strings[command].name);
1290 if (nbf_strings[command].verbose != NULL)
1291 data = smb_fdata(data, nbf_strings[command].verbose, data2);
1292 else
1293 printf("\n");
1294 }
1295 }
1296
1297 if (vflag < 2)
1298 return;
1299
1300 if (data == NULL)
1301 goto out;
1302
1303 if (is_truncated) {
1304 /* data2 was past the end of the buffer */
1305 goto out;
1306 }
1307
1308 /* If this isn't a command that would contain an SMB message, quit. */
1309 if (command != 0x08 && command != 0x09 && command != 0x15 &&
1310 command != 0x16)
1311 goto out;
1312
1313 /* If there isn't enough data for "\377SMB", don't look for it. */
1314 if (&data2[3] >= maxbuf)
1315 goto out;
1316
1317 if (memcmp(data2, "\377SMB",4) == 0)
1318 print_smb(data2, maxbuf);
1319 else {
1320 int i;
1321 for (i = 0; i < 128; i++) {
1322 if (&data2[i + 3] >= maxbuf)
1323 break;
1324 if (memcmp(&data2[i], "\377SMB", 4) == 0) {
1325 printf("found SMB packet at %d\n", i);
1326 print_smb(&data2[i], maxbuf);
1327 break;
1328 }
1329 }
1330 }
1331
1332 out:
1333 printf("\n");
1334 return;
1335 trunc:
1336 printf("[|SMB]");
1337 return;
1338 }
1339
1340
1341 /*
1342 * print IPX-Netbios frames
1343 */
1344 void
1345 ipx_netbios_print(const u_char *data, u_int length)
1346 {
1347 /*
1348 * this is a hack till I work out how to parse the rest of the
1349 * NetBIOS-over-IPX stuff
1350 */
1351 int i;
1352 const u_char *maxbuf;
1353
1354 maxbuf = data + length;
1355 /* Don't go past the end of the captured data in the packet. */
1356 if (maxbuf > snapend)
1357 maxbuf = snapend;
1358 startbuf = data;
1359 for (i = 0; i < 128; i++) {
1360 if (&data[i + 4] > maxbuf)
1361 break;
1362 if (memcmp(&data[i], "\377SMB", 4) == 0) {
1363 smb_fdata(data, "\n>>> IPX transport ", &data[i]);
1364 if (data != NULL)
1365 print_smb(&data[i], maxbuf);
1366 printf("\n");
1367 fflush(stdout);
1368 break;
1369 }
1370 }
1371 if (i == 128)
1372 smb_fdata(data, "\n>>> Unknown IPX ", maxbuf);
1373 }