]>
The Tcpdump Group git mirrors - tcpdump/blob - print-smb.c
2 * Copyright (C) Andrew Tridgell 1995-1999
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
9 /* \summary: SMB/CIFS printer */
15 #include "netdissect-stdinc.h"
19 #include "netdissect.h"
23 static const char tstr
[] = "[|SMB]" ;
25 static int request
= 0 ;
26 static int unicodestr
= 0 ;
28 extern const u_char
* startbuf
;
30 const u_char
* startbuf
= NULL
;
37 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, const u_char
*, const u_char
*);
40 struct smbdescriptint
{
45 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, u_int
, u_int
);
53 struct smbdescript descript
;
61 struct smbdescriptint descript
;
64 #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
66 #define FLG_CHAIN (1 << 0)
68 static const struct smbfns
*
69 smbfind ( int id
, const struct smbfns
* list
)
73 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
74 if ( list
[ sindex
]. id
== id
)
75 return (& list
[ sindex
]);
80 static const struct smbfnsint
*
81 smbfindint ( int id
, const struct smbfnsint
* list
)
85 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
86 if ( list
[ sindex
]. id
== id
)
87 return (& list
[ sindex
]);
93 trans2_findfirst ( netdissect_options
* ndo
,
94 const u_char
* param
, const u_char
* data
, u_int pcnt
, u_int dcnt
)
99 fmt
= "Attribute=[A] \n SearchCount=[u] \n Flags=[w] \n Level=[uP4] \n File=[S] \n " ;
101 fmt
= "Handle=[w] \n Count=[u] \n EOS=[w] \n Eoffset=[u] \n LastNameOfs=[w] \n " ;
103 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
106 smb_data_print ( ndo
, data
, dcnt
);
111 trans2_qfsinfo ( netdissect_options
* ndo
,
112 const u_char
* param
, const u_char
* data
, u_int pcnt
, u_int dcnt
)
114 static u_int level
= 0 ;
119 level
= EXTRACT_LE_U_2 ( param
);
120 fmt
= "InfoLevel=[u] \n " ;
121 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
125 fmt
= "idFileSystem=[W] \n SectorUnit=[U] \n Unit=[U] \n Avail=[U] \n SectorSize=[u] \n " ;
128 fmt
= "CreationTime=[T2]VolNameLength=[lb] \n VolumeLabel=[c] \n " ;
131 fmt
= "Capabilities=[W] \n MaxFileLen=[U] \n VolNameLen=[lU] \n Volume=[C] \n " ;
134 fmt
= "UnknownLevel \n " ;
137 smb_fdata ( ndo
, data
, fmt
, data
+ dcnt
, unicodestr
);
141 smb_data_print ( ndo
, data
, dcnt
);
145 ND_PRINT ( "%s" , tstr
);
148 static const struct smbfnsint trans2_fns
[] = {
149 { 0 , "TRANSACT2_OPEN" , 0 ,
150 { "Flags2=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2] \n OFun=[w] \n Size=[U] \n Res=([w, w, w, w, w]) \n Path=[S]" ,
152 "Handle=[u] \n Attrib=[A] \n Time=[T2] \n Size=[U] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n Inode=[W] \n OffErr=[u] \n |EALength=[u] \n " ,
154 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
155 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
156 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
157 { 3 , "TRANSACT2_QFSINFO" , 0 ,
158 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
159 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
160 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
161 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
162 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
163 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
164 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
165 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
166 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
167 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
168 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
169 { - 1 , NULL
, 0 , DEFDESCRIPT
}
174 print_trans2 ( netdissect_options
* ndo
,
175 const u_char
* words
, const u_char
* dat
, const u_char
* buf
, const u_char
* maxbuf
)
178 static const struct smbfnsint
* fn
= & trans2_fns
[ 0 ];
179 const u_char
* data
, * param
;
180 const u_char
* w
= words
+ 1 ;
181 const char * f1
= NULL
, * f2
= NULL
;
186 ND_TCHECK_2 ( w
+ ( 14 * 2 ));
187 pcnt
= EXTRACT_LE_U_2 ( w
+ 9 * 2 );
188 param
= buf
+ EXTRACT_LE_U_2 ( w
+ 10 * 2 );
189 dcnt
= EXTRACT_LE_U_2 ( w
+ 11 * 2 );
190 data
= buf
+ EXTRACT_LE_U_2 ( w
+ 12 * 2 );
191 fn
= smbfindint ( EXTRACT_LE_U_2 ( w
+ 14 * 2 ), trans2_fns
);
193 if ( EXTRACT_U_1 ( words
) == 0 ) {
194 ND_PRINT ( "%s \n " , fn
-> name
);
195 ND_PRINT ( "Trans2Interim \n " );
198 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
199 pcnt
= EXTRACT_LE_U_2 ( w
+ 3 * 2 );
200 param
= buf
+ EXTRACT_LE_U_2 ( w
+ 4 * 2 );
201 dcnt
= EXTRACT_LE_U_2 ( w
+ 6 * 2 );
202 data
= buf
+ EXTRACT_LE_U_2 ( w
+ 7 * 2 );
205 ND_PRINT ( "%s param_length=%u data_length=%u \n " , fn
-> name
, pcnt
, dcnt
);
208 if ( EXTRACT_U_1 ( words
) == 8 ) {
209 smb_fdata ( ndo
, words
+ 1 ,
210 "Trans2Secondary \n TotParam=[u] \n TotData=[u] \n ParamCnt=[u] \n ParamOff=[u] \n ParamDisp=[u] \n DataCnt=[u] \n DataOff=[u] \n DataDisp=[u] \n Handle=[u] \n " ,
214 smb_fdata ( ndo
, words
+ 1 ,
215 "TotParam=[u] \n TotData=[u] \n MaxParam=[u] \n MaxData=[u] \n MaxSetup=[b][P1] \n Flags=[w] \n TimeOut=[D] \n Res1=[w] \n ParamCnt=[u] \n ParamOff=[u] \n DataCnt=[u] \n DataOff=[u] \n SetupCnt=[b][P1] \n " ,
216 words
+ 1 + 14 * 2 , unicodestr
);
218 f1
= fn
-> descript
. req_f1
;
219 f2
= fn
-> descript
. req_f2
;
221 smb_fdata ( ndo
, words
+ 1 ,
222 "TotParam=[u] \n TotData=[u] \n Res1=[w] \n ParamCnt=[u] \n ParamOff=[u] \n ParamDisp[u] \n DataCnt=[u] \n DataOff=[u] \n DataDisp=[u] \n SetupCnt=[b][P1] \n " ,
223 words
+ 1 + 10 * 2 , unicodestr
);
224 f1
= fn
-> descript
. rep_f1
;
225 f2
= fn
-> descript
. rep_f2
;
229 bcc
= EXTRACT_LE_U_2 ( dat
);
230 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
232 (* fn
-> descript
. fn
)( ndo
, param
, data
, pcnt
, dcnt
);
234 smb_fdata ( ndo
, param
, f1
? f1
: "Parameters= \n " , param
+ pcnt
, unicodestr
);
235 smb_fdata ( ndo
, data
, f2
? f2
: "Data= \n " , data
+ dcnt
, unicodestr
);
239 ND_PRINT ( "%s" , tstr
);
243 print_browse ( netdissect_options
* ndo
,
244 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
246 const u_char
* maxbuf
= data
+ datalen
;
250 command
= EXTRACT_U_1 ( data
);
252 smb_fdata ( ndo
, param
, "BROWSE PACKET \n |Param " , param
+ paramlen
, unicodestr
);
256 data
= smb_fdata ( ndo
, data
,
257 "BROWSE PACKET: \n Type=[B] (LocalMasterAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[u] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " ,
262 data
= smb_fdata ( ndo
, data
,
263 "BROWSE PACKET: \n Type=[B] (HostAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[u] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " ,
268 data
= smb_fdata ( ndo
, data
,
269 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
274 data
= smb_fdata ( ndo
, data
,
275 "BROWSE PACKET: \n Type=[B] (WorkgroupAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[u] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n CommentPointer=[W] \n ServerName=[S] \n " ,
280 data
= smb_fdata ( ndo
, data
,
281 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
286 data
= smb_fdata ( ndo
, data
,
287 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
292 data
= smb_fdata ( ndo
, data
,
293 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token=[W] \n " ,
298 data
= smb_fdata ( ndo
, data
,
299 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token=[W] \n *Name=[S] \n " ,
304 data
= smb_fdata ( ndo
, data
,
305 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
310 data
= smb_fdata ( ndo
, data
,
311 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
, unicodestr
);
315 data
= smb_fdata ( ndo
, data
, "Unknown Browser Frame " , maxbuf
, unicodestr
);
320 ND_PRINT ( "%s" , tstr
);
325 print_ipc ( netdissect_options
* ndo
,
326 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
329 smb_fdata ( ndo
, param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
,
332 smb_fdata ( ndo
, data
, "IPC " , data
+ datalen
, unicodestr
);
337 print_trans ( netdissect_options
* ndo
,
338 const u_char
* words
, const u_char
* data1
, const u_char
* buf
, const u_char
* maxbuf
)
341 const char * f1
, * f2
, * f3
, * f4
;
342 const u_char
* data
, * param
;
343 const u_char
* w
= words
+ 1 ;
344 u_int datalen
, paramlen
;
347 ND_TCHECK_2 ( w
+ ( 12 * 2 ));
348 paramlen
= EXTRACT_LE_U_2 ( w
+ 9 * 2 );
349 param
= buf
+ EXTRACT_LE_U_2 ( w
+ 10 * 2 );
350 datalen
= EXTRACT_LE_U_2 ( w
+ 11 * 2 );
351 data
= buf
+ EXTRACT_LE_U_2 ( w
+ 12 * 2 );
352 f1
= "TotParamCnt=[u] \n TotDataCnt=[u] \n MaxParmCnt=[u] \n MaxDataCnt=[u] \n MaxSCnt=[u] \n TransFlags=[w] \n Res1=[w] \n Res2=[w] \n Res3=[w] \n ParamCnt=[u] \n ParamOff=[u] \n DataCnt=[u] \n DataOff=[u] \n SUCnt=[u] \n " ;
357 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
358 paramlen
= EXTRACT_LE_U_2 ( w
+ 3 * 2 );
359 param
= buf
+ EXTRACT_LE_U_2 ( w
+ 4 * 2 );
360 datalen
= EXTRACT_LE_U_2 ( w
+ 6 * 2 );
361 data
= buf
+ EXTRACT_LE_U_2 ( w
+ 7 * 2 );
362 f1
= "TotParamCnt=[u] \n TotDataCnt=[u] \n Res1=[u] \n ParamCnt=[u] \n ParamOff=[u] \n Res2=[u] \n DataCnt=[u] \n DataOff=[u] \n Res3=[u] \n Lsetup=[u] \n " ;
368 smb_fdata ( ndo
, words
+ 1 , f1
,
369 min ( words
+ 1 + 2 * EXTRACT_U_1 ( words
), maxbuf
),
373 bcc
= EXTRACT_LE_U_2 ( data1
);
374 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
376 smb_fdata ( ndo
, data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
), unicodestr
);
378 if ( strcmp (( const char *)( data1
+ 2 ), " \\ MAILSLOT \\ BROWSE" ) == 0 ) {
379 print_browse ( ndo
, param
, paramlen
, data
, datalen
);
383 if ( strcmp (( const char *)( data1
+ 2 ), " \\ PIPE \\ LANMAN" ) == 0 ) {
384 print_ipc ( ndo
, param
, paramlen
, data
, datalen
);
389 smb_fdata ( ndo
, param
, f3
, min ( param
+ paramlen
, maxbuf
), unicodestr
);
391 smb_fdata ( ndo
, data
, f4
, min ( data
+ datalen
, maxbuf
), unicodestr
);
395 ND_PRINT ( "%s" , tstr
);
400 print_negprot ( netdissect_options
* ndo
,
401 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
404 const char * f1
= NULL
, * f2
= NULL
;
407 wct
= EXTRACT_U_1 ( words
);
409 f2
= "*|Dialect=[Y] \n " ;
412 f1
= "Core Protocol \n DialectIndex=[u]" ;
414 f1
= "NT1 Protocol \n DialectIndex=[u] \n SecMode=[B] \n MaxMux=[u] \n NumVcs=[u] \n MaxBuffer=[U] \n RawSize=[U] \n SessionKey=[W] \n Capabilities=[W] \n ServerTime=[T3]TimeZone=[u] \n CryptKey=" ;
416 f1
= "Coreplus/Lanman1/Lanman2 Protocol \n DialectIndex=[u] \n SecMode=[w] \n MaxXMit=[u] \n MaxMux=[u] \n MaxVcs=[u] \n BlkMode=[w] \n SessionKey=[W] \n ServerTime=[T1]TimeZone=[u] \n Res=[W] \n CryptKey=" ;
420 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
423 smb_data_print ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
426 bcc
= EXTRACT_LE_U_2 ( data
);
427 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
430 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_U_2 ( data
),
431 maxbuf
), unicodestr
);
433 smb_data_print ( ndo
, data
+ 2 ,
434 min ( EXTRACT_LE_U_2 ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
438 ND_PRINT ( "%s" , tstr
);
442 print_sesssetup ( netdissect_options
* ndo
,
443 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
446 const char * f1
= NULL
, * f2
= NULL
;
449 wct
= EXTRACT_U_1 ( words
);
452 f1
= "Com2=[w] \n Off2=[u] \n BufSize=[u] \n MpxMax=[u] \n VcNum=[u] \n SessionKey=[W] \n PassLen=[u] \n CryptLen=[u] \n CryptOff=[u] \n Pass&Name= \n " ;
454 f1
= "Com2=[B] \n Res1=[B] \n Off2=[u] \n MaxBuffer=[u] \n MaxMpx=[u] \n VcNumber=[u] \n SessionKey=[W] \n CaseInsensitivePasswordLength=[u] \n CaseSensitivePasswordLength=[u] \n Res=[W] \n Capabilities=[W] \n Pass1&Pass2&Account&Domain&OS&LanMan= \n " ;
457 f1
= "Com2=[w] \n Off2=[u] \n Action=[w] \n " ;
458 } else if ( wct
== 13 ) {
459 f1
= "Com2=[B] \n Res=[B] \n Off2=[u] \n Action=[w] \n " ;
460 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
465 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
468 smb_data_print ( ndo
, words
+ 1 , min ( wct
* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
471 bcc
= EXTRACT_LE_U_2 ( data
);
472 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
475 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_U_2 ( data
),
476 maxbuf
), unicodestr
);
478 smb_data_print ( ndo
, data
+ 2 ,
479 min ( EXTRACT_LE_U_2 ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
483 ND_PRINT ( "%s" , tstr
);
487 print_lockingandx ( netdissect_options
* ndo
,
488 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
491 const u_char
* maxwords
;
492 const char * f1
= NULL
, * f2
= NULL
;
495 wct
= EXTRACT_U_1 ( words
);
497 f1
= "Com2=[w] \n Off2=[u] \n Handle=[u] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[u] \n LockCount=[u] \n " ;
498 ND_TCHECK_1 ( words
+ 7 );
499 if ( EXTRACT_U_1 ( words
+ 7 ) & 0x10 )
500 f2
= "*Process=[u] \n [P2]Offset=[M] \n Length=[M] \n " ;
502 f2
= "*Process=[u] \n Offset=[D] \n Length=[U] \n " ;
504 f1
= "Com2=[w] \n Off2=[u] \n " ;
507 maxwords
= min ( words
+ 1 + wct
* 2 , maxbuf
);
509 smb_fdata ( ndo
, words
+ 1 , f1
, maxwords
, unicodestr
);
512 bcc
= EXTRACT_LE_U_2 ( data
);
513 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
516 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + EXTRACT_LE_U_2 ( data
),
517 maxbuf
), unicodestr
);
519 smb_data_print ( ndo
, data
+ 2 ,
520 min ( EXTRACT_LE_U_2 ( data
), PTR_DIFF ( maxbuf
, data
+ 2 )));
524 ND_PRINT ( "%s" , tstr
);
528 static const struct smbfns smb_fns
[] = {
529 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
531 { SMBtcon
, "SMBtcon" , 0 ,
532 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
533 "MaxXmit=[u] \n TreeId=[u] \n " , NULL
,
536 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
537 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
538 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
540 { SMBecho
, "SMBecho" , 0 ,
541 { "ReverbCount=[u] \n " , NULL
,
542 "SequenceNum=[u] \n " , NULL
,
545 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
547 { SMBgetatr
, "SMBgetatr" , 0 ,
548 { NULL
, "Path=[Z] \n " ,
549 "Attribute=[A] \n Time=[T2]Size=[U] \n Res=([w,w,w,w,w]) \n " , NULL
,
552 { SMBsetatr
, "SMBsetatr" , 0 ,
553 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
554 NULL
, NULL
, NULL
} },
556 { SMBchkpth
, "SMBchkpth" , 0 ,
557 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
559 { SMBsearch
, "SMBsearch" , 0 ,
560 { "Count=[u] \n Attrib=[A] \n " ,
561 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n Res2=[W] \n " ,
563 "BlkType=[B] \n BlkLen=[u] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[U] \n Name=[s13] \n " ,
566 { SMBopen
, "SMBopen" , 0 ,
567 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
568 "Handle=[u] \n OAttrib=[A] \n Time=[T2]Size=[U] \n Access=[w] \n " ,
571 { SMBcreate
, "SMBcreate" , 0 ,
572 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
574 { SMBmknew
, "SMBmknew" , 0 ,
575 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
577 { SMBunlink
, "SMBunlink" , 0 ,
578 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
580 { SMBread
, "SMBread" , 0 ,
581 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
582 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
584 { SMBwrite
, "SMBwrite" , 0 ,
585 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
586 "Count=[u] \n " , NULL
, NULL
} },
588 { SMBclose
, "SMBclose" , 0 ,
589 { "Handle=[u] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
591 { SMBmkdir
, "SMBmkdir" , 0 ,
592 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
594 { SMBrmdir
, "SMBrmdir" , 0 ,
595 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
597 { SMBdskattr
, "SMBdskattr" , 0 ,
599 "TotalUnits=[u] \n BlocksPerUnit=[u] \n BlockSize=[u] \n FreeUnits=[u] \n Media=[w] \n " ,
603 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
606 * this is a Pathworks specific call, allowing the
607 * changing of the root path
609 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
611 { SMBlseek
, "SMBlseek" , 0 ,
612 { "Handle=[u] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
, NULL
} },
614 { SMBflush
, "SMBflush" , 0 , { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
616 { SMBsplopen
, "SMBsplopen" , 0 ,
617 { "SetupLen=[u] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[u] \n " ,
620 { SMBsplclose
, "SMBsplclose" , 0 ,
621 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
623 { SMBsplretq
, "SMBsplretq" , 0 ,
624 { "MaxCount=[u] \n StartIndex=[u] \n " , NULL
,
625 "Count=[u] \n Index=[u] \n " ,
626 "*Time=[T2]Status=[B] \n JobID=[u] \n Size=[U] \n Res=[B]Name=[s16] \n " ,
629 { SMBsplwr
, "SMBsplwr" , 0 ,
630 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
632 { SMBlock
, "SMBlock" , 0 ,
633 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
635 { SMBunlock
, "SMBunlock" , 0 ,
636 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
638 /* CORE+ PROTOCOL FOLLOWS */
640 { SMBreadbraw
, "SMBreadbraw" , 0 ,
641 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[u] \n " ,
642 NULL
, NULL
, NULL
, NULL
} },
644 { SMBwritebraw
, "SMBwritebraw" , 0 ,
645 { "Handle=[u] \n TotalCount=[u] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n |DataSize=[u] \n DataOff=[u] \n " ,
646 NULL
, "WriteRawAck" , NULL
, NULL
} },
648 { SMBwritec
, "SMBwritec" , 0 ,
649 { NULL
, NULL
, "Count=[u] \n " , NULL
, NULL
} },
651 { SMBwriteclose
, "SMBwriteclose" , 0 ,
652 { "Handle=[u] \n Count=[u] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
653 NULL
, "Count=[u] \n " , NULL
, NULL
} },
655 { SMBlockread
, "SMBlockread" , 0 ,
656 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
657 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
659 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
660 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
661 "Count=[u] \n " , NULL
, NULL
} },
663 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
664 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[w] \n " ,
666 "Offset=[D] \n TotCount=[u] \n Remaining=[u] \n Res=([w,w]) \n DataSize=[u] \n DataOff=[u] \n " ,
669 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
670 { "Handle=[u] \n TotCount=[u] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n DataSize=[u] \n DataOff=[u] \n " , NULL
,
671 "Remaining=[u] \n " , NULL
, NULL
} },
673 { SMBwriteBs
, "SMBwriteBs" , 0 ,
674 { "Handle=[u] \n TotCount=[u] \n Offset=[D] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n " ,
675 NULL
, "Count=[u] \n " , NULL
, NULL
} },
677 { SMBsetattrE
, "SMBsetattrE" , 0 ,
678 { "Handle=[u] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
679 NULL
, NULL
, NULL
} },
681 { SMBgetattrE
, "SMBgetattrE" , 0 ,
682 { "Handle=[u] \n " , NULL
,
683 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U] \n AllocSize=[U] \n Attribute=[A] \n " ,
686 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
687 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
689 { SMBcopy
, "SMBcopy" , 0 ,
690 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
691 "CopyCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
693 { SMBmove
, "SMBmove" , 0 ,
694 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
695 "MoveCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
697 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
698 { "Com2=[w] \n Off2=[u] \n Flags=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2]OFun=[w] \n Size=[U] \n TimeOut=[D] \n Res=[W] \n " ,
700 "Com2=[w] \n Off2=[u] \n Handle=[u] \n Attrib=[A] \n Time=[T2]Size=[U] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n FileID=[W] \n Res=[w] \n " ,
703 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
704 { "Com2=[w] \n Off2=[u] \n Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n CountLeft=[u] \n " ,
706 "Com2=[w] \n Off2=[u] \n Remaining=[u] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n Res=([w,w,w,w]) \n " ,
709 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
710 { "Com2=[w] \n Off2=[u] \n Handle=[u] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n CountLeft=[u] \n Res=[w] \n DataSize=[u] \n DataOff=[u] \n " ,
712 "Com2=[w] \n Off2=[u] \n Count=[u] \n Remaining=[u] \n Res=[W] \n " ,
715 { SMBffirst
, "SMBffirst" , 0 ,
716 { "Count=[u] \n Attrib=[A] \n " ,
717 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
719 "BlkType=[B] \n BlkLen=[u] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[U] \n Name=[s13] \n " ,
722 { SMBfunique
, "SMBfunique" , 0 ,
723 { "Count=[u] \n Attrib=[A] \n " ,
724 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
726 "BlkType=[B] \n BlkLen=[u] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[U] \n Name=[s13] \n " ,
729 { SMBfclose
, "SMBfclose" , 0 ,
730 { "Count=[u] \n Attrib=[A] \n " ,
731 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
733 "BlkType=[B] \n BlkLen=[u] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[U] \n Name=[s13] \n " ,
736 { SMBfindnclose
, "SMBfindnclose" , 0 ,
737 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
739 { SMBfindclose
, "SMBfindclose" , 0 ,
740 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
742 { SMBsends
, "SMBsends" , 0 ,
743 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
745 { SMBsendstrt
, "SMBsendstrt" , 0 ,
746 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[u] \n " , NULL
, NULL
} },
748 { SMBsendend
, "SMBsendend" , 0 ,
749 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
751 { SMBsendtxt
, "SMBsendtxt" , 0 ,
752 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
754 { SMBsendb
, "SMBsendb" , 0 ,
755 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
757 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
758 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
759 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
761 { SMBnegprot
, "SMBnegprot" , 0 ,
762 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
764 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
765 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
767 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
768 { "Com2=[w] \n Off2=[u] \n Flags=[w] \n PassLen=[u] \n Passwd&Path&Device= \n " ,
769 NULL
, "Com2=[w] \n Off2=[u] \n " , "ServiceType=[R] \n " , NULL
} },
771 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
772 { NULL
, NULL
, NULL
, NULL
, print_lockingandx
} },
774 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
776 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
777 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
778 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
779 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
781 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
782 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
784 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
785 { "Com2=[w] \n Off2=[u] \n Res=[b] \n NameLen=[lu] \n Flags=[W] \n RootDirectoryFid=[U] \n AccessMask=[W] \n AllocationSize=[L] \n ExtFileAttributes=[W] \n ShareAccess=[W] \n CreateDisposition=[W] \n CreateOptions=[W] \n ImpersonationLevel=[W] \n SecurityFlags=[b] \n " ,
787 "Com2=[w] \n Off2=[u] \n OplockLevel=[b] \n Fid=[u] \n CreateAction=[W] \n CreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W] \n AllocationSize=[L] \n EndOfFile=[L] \n FileType=[w] \n DeviceState=[w] \n Directory=[b] \n " ,
790 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
792 { - 1 , NULL
, 0 , DEFDESCRIPT
}
797 * print a SMB message
800 print_smb ( netdissect_options
* ndo
,
801 const u_char
* buf
, const u_char
* maxbuf
)
807 const u_char
* words
, * maxwords
, * data
;
808 const struct smbfns
* fn
;
809 const char * fmt_smbheader
=
810 "[P4]SMB Command = [B] \n Error class = [BP1] \n Error code = [u] \n Flags1 = [B] \n Flags2 = [B][P13] \n Tree ID = [u] \n Proc ID = [u] \n UID = [u] \n MID = [u] \n Word Count = [b] \n " ;
813 ND_TCHECK_1 ( buf
+ 9 );
814 request
= ( EXTRACT_U_1 ( buf
+ 9 ) & 0x80 ) ? 0 : 1 ;
817 command
= EXTRACT_U_1 ( buf
+ 4 );
819 fn
= smbfind ( command
, smb_fns
);
821 if ( ndo
-> ndo_vflag
> 1 )
824 ND_PRINT ( "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
826 if ( ndo
-> ndo_vflag
< 2 )
829 ND_TCHECK_2 ( buf
+ 10 );
830 flags2
= EXTRACT_LE_U_2 ( buf
+ 10 );
831 unicodestr
= flags2
& 0x8000 ;
832 nterrcodes
= flags2
& 0x4000 ;
834 /* print out the header */
835 smb_fdata ( ndo
, buf
, fmt_smbheader
, buf
+ 33 , unicodestr
);
838 nterror
= EXTRACT_LE_U_4 ( buf
+ 5 );
840 ND_PRINT ( "NTError = %s \n " , nt_errstr ( nterror
));
842 if ( EXTRACT_U_1 ( buf
+ 5 ))
843 ND_PRINT ( "SMBError = %s \n " , smb_errstr ( EXTRACT_U_1 ( buf
+ 5 ),
844 EXTRACT_LE_U_2 ( buf
+ 7 )));
855 words
= buf
+ smboffset
;
857 wct
= EXTRACT_U_1 ( words
);
858 data
= words
+ 1 + wct
* 2 ;
859 maxwords
= min ( data
, maxbuf
);
862 f1
= fn
-> descript
. req_f1
;
863 f2
= fn
-> descript
. req_f2
;
865 f1
= fn
-> descript
. rep_f1
;
866 f2
= fn
-> descript
. rep_f2
;
870 (* fn
-> descript
. fn
)( ndo
, words
, data
, buf
, maxbuf
);
874 smb_fdata ( ndo
, words
+ 1 , f1
, words
+ 1 + wct
* 2 , unicodestr
);
879 for ( i
= 0 ; words
+ 1 + 2 * i
< maxwords
; i
++) {
880 ND_TCHECK_2 ( words
+ 1 + 2 * i
);
881 v
= EXTRACT_LE_U_2 ( words
+ 1 + 2 * i
);
882 ND_PRINT ( "smb_vwv[%u]=%u (0x%X) \n " , i
, v
, v
);
888 bcc
= EXTRACT_LE_U_2 ( data
);
889 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
892 smb_fdata ( ndo
, data
+ 2 , f2
, data
+ 2 + bcc
, unicodestr
);
895 ND_PRINT ( "smb_buf[]= \n " );
896 smb_data_print ( ndo
, data
+ 2 , min ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
901 if (( fn
-> flags
& FLG_CHAIN
) == 0 )
905 ND_TCHECK_1 ( words
+ 1 );
906 command
= EXTRACT_U_1 ( words
+ 1 );
909 ND_TCHECK_2 ( words
+ 3 );
910 newsmboffset
= EXTRACT_LE_U_2 ( words
+ 3 );
912 fn
= smbfind ( command
, smb_fns
);
914 ND_PRINT ( " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
915 fn
-> name
, request
? "REQUEST" : "REPLY" );
916 if ( newsmboffset
<= smboffset
) {
917 ND_PRINT ( "Bad andX offset: %u <= %u \n " , newsmboffset
, smboffset
);
920 smboffset
= newsmboffset
;
926 ND_PRINT ( "%s" , tstr
);
931 * print a NBT packet received across tcp on port 139
934 nbt_tcp_print ( netdissect_options
* ndo
,
935 const u_char
* data
, u_int length
)
940 const u_char
* maxbuf
;
942 ndo
-> ndo_protocol
= "nbt_tcp" ;
945 if ( ndo
-> ndo_snapend
< data
)
947 caplen
= ndo
-> ndo_snapend
- data
;
950 maxbuf
= data
+ caplen
;
952 type
= EXTRACT_U_1 ( data
);
953 ND_TCHECK_2 ( data
+ 2 );
954 nbt_len
= EXTRACT_BE_U_2 ( data
+ 2 );
960 if ( ndo
-> ndo_vflag
< 2 ) {
961 ND_PRINT ( " NBT Session Packet: " );
964 ND_PRINT ( "Session Message" );
968 ND_PRINT ( "Session Request" );
972 ND_PRINT ( "Session Granted" );
985 ecode
= EXTRACT_U_1 ( data
+ 4 );
987 ND_PRINT ( "Session Reject, " );
990 ND_PRINT ( "Not listening on called name" );
993 ND_PRINT ( "Not listening for calling name" );
996 ND_PRINT ( "Called name not present" );
999 ND_PRINT ( "Called name present, but insufficient resources" );
1002 ND_PRINT ( "Unspecified error 0x%X" , ecode
);
1009 ND_PRINT ( "Session Keepalive" );
1013 data
= smb_fdata ( ndo
, data
, "Unknown packet type [rB]" , maxbuf
, 0 );
1017 ND_PRINT ( " \n >>> NBT Session Packet \n " );
1020 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Message \n Flags=[B] \n Length=[ru] \n " ,
1024 if ( nbt_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1025 if ( nbt_len
> caplen
) {
1026 if ( nbt_len
> length
)
1027 ND_PRINT ( "WARNING: Packet is continued in later TCP segments \n " );
1029 ND_PRINT ( "WARNING: Short packet. Try increasing the snap length by %u \n " ,
1032 print_smb ( ndo
, data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
1034 ND_PRINT ( "Session packet:(raw data or continuation?) \n " );
1038 data
= smb_fdata ( ndo
, data
,
1039 "[P1]NBT Session Request \n Flags=[B] \n Length=[ru] \n Destination=[n1] \n Source=[n1] \n " ,
1044 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Granted \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1049 const u_char
* origdata
;
1053 data
= smb_fdata ( ndo
, data
, "[P1]NBT SessionReject \n Flags=[B] \n Length=[ru] \n Reason=[B] \n " ,
1057 if ( nbt_len
>= 1 && caplen
>= 1 ) {
1058 ecode
= EXTRACT_U_1 ( origdata
+ 4 );
1061 ND_PRINT ( "Not listening on called name \n " );
1064 ND_PRINT ( "Not listening for calling name \n " );
1067 ND_PRINT ( "Called name not present \n " );
1070 ND_PRINT ( "Called name present, but insufficient resources \n " );
1073 ND_PRINT ( "Unspecified error 0x%X \n " , ecode
);
1081 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Keepalive \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1085 data
= smb_fdata ( ndo
, data
, "NBT - Unknown packet type \n Type=[B] \n " , maxbuf
, 0 );
1092 ND_PRINT ( "%s" , tstr
);
1095 static const struct tok opcode_str
[] = {
1097 { 5 , "REGISTRATION" },
1100 { 8 , "REFRESH(8)" },
1102 { 15 , "MULTIHOMED REGISTRATION" },
1107 * print a NBT packet received across udp on port 137
1110 nbt_udp137_print ( netdissect_options
* ndo
,
1111 const u_char
* data
, u_int length
)
1113 const u_char
* maxbuf
= data
+ length
;
1114 u_int name_trn_id
, response
, opcode
, nm_flags
, rcode
;
1115 u_int qdcount
, ancount
, nscount
, arcount
;
1119 ndo
-> ndo_protocol
= "nbt_udp137" ;
1120 ND_TCHECK_2 ( data
+ 10 );
1121 name_trn_id
= EXTRACT_BE_U_2 ( data
);
1122 response
= ( EXTRACT_U_1 ( data
+ 2 ) >> 7 );
1123 opcode
= ( EXTRACT_U_1 ( data
+ 2 ) >> 3 ) & 0xF ;
1124 nm_flags
= (( EXTRACT_U_1 ( data
+ 2 ) & 0x7 ) << 4 ) + ( EXTRACT_U_1 ( data
+ 3 ) >> 4 );
1125 rcode
= EXTRACT_U_1 ( data
+ 3 ) & 0xF ;
1126 qdcount
= EXTRACT_BE_U_2 ( data
+ 4 );
1127 ancount
= EXTRACT_BE_U_2 ( data
+ 6 );
1128 nscount
= EXTRACT_BE_U_2 ( data
+ 8 );
1129 arcount
= EXTRACT_BE_U_2 ( data
+ 10 );
1135 if ( ndo
-> ndo_vflag
> 1 )
1138 ND_PRINT ( "NBT UDP PACKET(137): %s" , tok2str ( opcode_str
, "OPUNKNOWN" , opcode
));
1140 ND_PRINT ( "; %s" , rcode
? "NEGATIVE" : "POSITIVE" );
1142 ND_PRINT ( "; %s; %s" , response
? "RESPONSE" : "REQUEST" ,
1143 ( nm_flags
& 1 ) ? "BROADCAST" : "UNICAST" );
1145 if ( ndo
-> ndo_vflag
< 2 )
1148 ND_PRINT ( " \n TrnID=0x%X \n OpCode=%u \n NmFlags=0x%X \n Rcode=%u \n QueryCount=%u \n AnswerCount=%u \n AuthorityCount=%u \n AddressRecCount=%u \n " ,
1149 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
1154 total
= ancount
+ nscount
+ arcount
;
1156 if ( qdcount
> 100 || total
> 100 ) {
1157 ND_PRINT ( "Corrupt packet?? \n " );
1162 ND_PRINT ( "QuestionRecords: \n " );
1163 for ( i
= 0 ; i
< qdcount
; i
++) {
1164 p
= smb_fdata ( ndo
, p
,
1165 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
1173 ND_PRINT ( " \n ResourceRecords: \n " );
1174 for ( i
= 0 ; i
< total
; i
++) {
1178 p
= smb_fdata ( ndo
, p
, "Name=[n1] \n #" , maxbuf
, 0 );
1182 restype
= EXTRACT_BE_U_2 ( p
);
1183 p
= smb_fdata ( ndo
, p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rU] \n " , p
+ 8 , 0 );
1187 rdlen
= EXTRACT_BE_U_2 ( p
);
1188 ND_PRINT ( "ResourceLength=%u \n ResourceData= \n " , rdlen
);
1191 p
= smb_fdata ( ndo
, p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
, 0 );
1195 if ( restype
== 0x21 ) {
1199 numnames
= EXTRACT_U_1 ( p
);
1200 p
= smb_fdata ( ndo
, p
, "NumNames=[B] \n " , p
+ 1 , 0 );
1203 while ( numnames
--) {
1204 p
= smb_fdata ( ndo
, p
, "Name=[n2] \t #" , maxbuf
, 0 );
1210 if ( EXTRACT_U_1 ( p
) & 0x80 )
1211 ND_PRINT ( "<GROUP> " );
1212 switch ( EXTRACT_U_1 ( p
) & 0x60 ) {
1213 case 0x00 : ND_PRINT ( "B " ); break ;
1214 case 0x20 : ND_PRINT ( "P " ); break ;
1215 case 0x40 : ND_PRINT ( "M " ); break ;
1216 case 0x60 : ND_PRINT ( "_ " ); break ;
1218 if ( EXTRACT_U_1 ( p
) & 0x10 )
1219 ND_PRINT ( "<DEREGISTERING> " );
1220 if ( EXTRACT_U_1 ( p
) & 0x08 )
1221 ND_PRINT ( "<CONFLICT> " );
1222 if ( EXTRACT_U_1 ( p
) & 0x04 )
1223 ND_PRINT ( "<ACTIVE> " );
1224 if ( EXTRACT_U_1 ( p
) & 0x02 )
1225 ND_PRINT ( "<PERMANENT> " );
1232 smb_data_print ( ndo
, p
, min ( rdlen
, length
- ( p
- data
)));
1240 smb_fdata ( ndo
, p
, "AdditionalData: \n " , maxbuf
, 0 );
1246 ND_PRINT ( "%s" , tstr
);
1250 * Print an SMB-over-TCP packet received across tcp on port 445
1253 smb_tcp_print ( netdissect_options
* ndo
,
1254 const u_char
* data
, u_int length
)
1258 const u_char
* maxbuf
;
1260 ndo
-> ndo_protocol
= "smb_tcp" ;
1263 if ( ndo
-> ndo_snapend
< data
)
1265 caplen
= ndo
-> ndo_snapend
- data
;
1268 maxbuf
= data
+ caplen
;
1269 smb_len
= EXTRACT_BE_U_3 ( data
+ 1 );
1276 if ( smb_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1277 if ( smb_len
> caplen
) {
1278 if ( smb_len
> length
)
1279 ND_PRINT ( " WARNING: Packet is continued in later TCP segments \n " );
1281 ND_PRINT ( " WARNING: Short packet. Try increasing the snap length by %u \n " ,
1285 print_smb ( ndo
, data
, maxbuf
> data
+ smb_len
? data
+ smb_len
: maxbuf
);
1287 ND_PRINT ( " SMB-over-TCP packet:(raw data or continuation?) \n " );
1290 ND_PRINT ( "%s" , tstr
);
1294 * print a NBT packet received across udp on port 138
1297 nbt_udp138_print ( netdissect_options
* ndo
,
1298 const u_char
* data
, u_int length
)
1300 const u_char
* maxbuf
= data
+ length
;
1302 ndo
-> ndo_protocol
= "nbt_udp138" ;
1303 if ( maxbuf
> ndo
-> ndo_snapend
)
1304 maxbuf
= ndo
-> ndo_snapend
;
1309 if ( ndo
-> ndo_vflag
< 2 ) {
1310 ND_PRINT ( "NBT UDP PACKET(138)" );
1314 data
= smb_fdata ( ndo
, data
,
1315 " \n >>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[ru] Length=[ru] Res2=[rw] \n SourceName=[n1] \n DestName=[n1] \n #" ,
1319 /* If there isn't enough data for "\377SMB", don't check for it. */
1320 if (( data
+ 3 ) >= maxbuf
)
1323 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 )
1324 print_smb ( ndo
, data
, maxbuf
);
1332 print netbeui frames
1334 static struct nbf_strings
{
1336 const char * nonverbose
;
1337 const char * verbose
;
1338 } nbf_strings
[ 0x20 ] = {
1339 { "Add Group Name Query" , ", [P23]Name to add=[n2]#" ,
1340 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1341 { "Add Name Query" , ", [P23]Name to add=[n2]#" ,
1342 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1343 { "Name In Conflict" , NULL
, NULL
},
1344 { "Status Query" , NULL
, NULL
},
1345 { NULL
, NULL
, NULL
}, /* not used */
1346 { NULL
, NULL
, NULL
}, /* not used */
1347 { NULL
, NULL
, NULL
}, /* not used */
1348 { "Terminate Trace" , NULL
, NULL
},
1350 "[P7]Destination=[n2] \n Source=[n2] \n " },
1351 { "Broadcast Datagram" , NULL
,
1352 "[P7]Destination=[n2] \n Source=[n2] \n " },
1353 { "Name Query" , ", [P7]Name=[n2]#" ,
1354 "[P1]SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Name=[n2] \n Name of sender=[n2] \n " },
1355 { NULL
, NULL
, NULL
}, /* not used */
1356 { NULL
, NULL
, NULL
}, /* not used */
1357 { "Add Name Response" , ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#" ,
1358 "AddNameInProcess=[B] \n GroupName=[w] \n TransmitCorrelator=[w][P2] \n Destination=[n2] \n Source=[n2] \n " },
1359 { "Name Recognized" , NULL
,
1360 "[P1]Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " },
1361 { "Status Response" , NULL
, NULL
},
1362 { NULL
, NULL
, NULL
}, /* not used */
1363 { NULL
, NULL
, NULL
}, /* not used */
1364 { NULL
, NULL
, NULL
}, /* not used */
1365 { "Terminate Trace" , NULL
, NULL
},
1367 "[P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1368 { "Data First/Middle" , NULL
,
1369 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1370 { "Data Only/Last" , NULL
,
1371 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1372 { "Session Confirm" , NULL
,
1373 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1374 { "Session End" , NULL
,
1375 "[P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1376 { "Session Initialize" , NULL
,
1377 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1378 { "No Receive" , NULL
,
1379 "Flags=[{|SEND_NO_ACK}] \n DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1380 { "Receive Outstanding" , NULL
,
1381 "[P1]DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1382 { "Receive Continue" , NULL
,
1383 "[P2]TransmitCorrelator=[w] \n [P2]RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1384 { NULL
, NULL
, NULL
}, /* not used */
1385 { NULL
, NULL
, NULL
}, /* not used */
1386 { "Session Alive" , NULL
, NULL
}
1390 netbeui_print ( netdissect_options
* ndo
,
1391 u_short control
, const u_char
* data
, u_int length
)
1393 const u_char
* maxbuf
= data
+ length
;
1396 const u_char
* data2
;
1397 int is_truncated
= 0 ;
1399 ndo
-> ndo_protocol
= "netbeui" ;
1400 if ( maxbuf
> ndo
-> ndo_snapend
)
1401 maxbuf
= ndo
-> ndo_snapend
;
1402 ND_TCHECK_1 ( data
+ 4 );
1403 len
= EXTRACT_LE_U_2 ( data
);
1404 command
= EXTRACT_U_1 ( data
+ 4 );
1406 if ( data2
>= maxbuf
) {
1413 if ( ndo
-> ndo_vflag
< 2 ) {
1414 ND_PRINT ( "NBF Packet: " );
1415 data
= smb_fdata ( ndo
, data
, "[P5]#" , maxbuf
, 0 );
1417 ND_PRINT ( " \n >>> NBF Packet \n Type=0x%X " , control
);
1418 data
= smb_fdata ( ndo
, data
, "Length=[u] Signature=[w] Command=[B] \n #" , maxbuf
, 0 );
1423 if ( command
> 0x1f || nbf_strings
[ command
]. name
== NULL
) {
1424 if ( ndo
-> ndo_vflag
< 2 )
1425 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command#" , data2
, 0 );
1427 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command \n " , data2
, 0 );
1429 if ( ndo
-> ndo_vflag
< 2 ) {
1430 ND_PRINT ( "%s" , nbf_strings
[ command
]. name
);
1431 if ( nbf_strings
[ command
]. nonverbose
!= NULL
)
1432 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. nonverbose
, data2
, 0 );
1434 ND_PRINT ( "%s: \n " , nbf_strings
[ command
]. name
);
1435 if ( nbf_strings
[ command
]. verbose
!= NULL
)
1436 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. verbose
, data2
, 0 );
1442 if ( ndo
-> ndo_vflag
< 2 )
1449 /* data2 was past the end of the buffer */
1453 /* If this isn't a command that would contain an SMB message, quit. */
1454 if ( command
!= 0x08 && command
!= 0x09 && command
!= 0x15 &&
1458 /* If there isn't enough data for "\377SMB", don't look for it. */
1459 if (( data2
+ 3 ) >= maxbuf
)
1462 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1463 print_smb ( ndo
, data2
, maxbuf
);
1466 for ( i
= 0 ; i
< 128 ; i
++) {
1467 if (( data2
+ i
+ 3 ) >= maxbuf
)
1469 if ( memcmp ( data2
+ i
, " \377 SMB" , 4 ) == 0 ) {
1470 ND_PRINT ( "found SMB packet at %u \n " , i
);
1471 print_smb ( ndo
, data2
+ i
, maxbuf
);
1481 ND_PRINT ( "%s" , tstr
);
1486 * print IPX-Netbios frames
1489 ipx_netbios_print ( netdissect_options
* ndo
,
1490 const u_char
* data
, u_int length
)
1493 * this is a hack till I work out how to parse the rest of the
1494 * NetBIOS-over-IPX stuff
1497 const u_char
* maxbuf
;
1499 ndo
-> ndo_protocol
= "ipx_netbios" ;
1500 maxbuf
= data
+ length
;
1501 /* Don't go past the end of the captured data in the packet. */
1502 if ( maxbuf
> ndo
-> ndo_snapend
)
1503 maxbuf
= ndo
-> ndo_snapend
;
1505 for ( i
= 0 ; i
< 128 ; i
++) {
1506 if (( data
+ i
+ 4 ) > maxbuf
)
1508 if ( memcmp ( data
+ i
, " \377 SMB" , 4 ) == 0 ) {
1509 smb_fdata ( ndo
, data
, " \n >>> IPX transport " , data
+ i
, 0 );
1510 print_smb ( ndo
, data
+ i
, maxbuf
);
1516 smb_fdata ( ndo
, data
, " \n >>> Unknown IPX " , maxbuf
, 0 );