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