]>
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"
24 static int request
= 0 ;
25 static int unicodestr
= 0 ;
27 extern const u_char
* startbuf
;
29 const u_char
* startbuf
= NULL
;
36 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, const u_char
*, const u_char
*);
39 struct smbdescriptint
{
44 void (* fn
)( netdissect_options
*, const u_char
*, const u_char
*, u_int
, u_int
);
52 struct smbdescript descript
;
60 struct smbdescriptint descript
;
63 #define DEFDESCRIPT { NULL, NULL, NULL, NULL, NULL }
65 #define FLG_CHAIN (1 << 0)
67 static const struct smbfns
*
68 smbfind ( int id
, const struct smbfns
* list
)
72 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
73 if ( list
[ sindex
]. id
== id
)
74 return (& list
[ sindex
]);
79 static const struct smbfnsint
*
80 smbfindint ( int id
, const struct smbfnsint
* list
)
84 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
85 if ( list
[ sindex
]. id
== id
)
86 return (& list
[ sindex
]);
92 trans2_findfirst ( netdissect_options
* ndo
,
93 const u_char
* param
, const u_char
* data
, u_int pcnt
, u_int dcnt
)
98 fmt
= "Attribute=[A] \n SearchCount=[u] \n Flags=[w] \n Level=[uP4] \n File=[S] \n " ;
100 fmt
= "Handle=[w] \n Count=[u] \n EOS=[w] \n Eoffset=[u] \n LastNameOfs=[w] \n " ;
102 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
105 smb_data_print ( ndo
, data
, dcnt
);
110 trans2_qfsinfo ( netdissect_options
* ndo
,
111 const u_char
* param
, const u_char
* data
, u_int pcnt
, u_int dcnt
)
113 static u_int level
= 0 ;
117 level
= GET_LE_U_2 ( param
);
118 fmt
= "InfoLevel=[u] \n " ;
119 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
123 fmt
= "idFileSystem=[W] \n SectorUnit=[U] \n Unit=[U] \n Avail=[U] \n SectorSize=[u] \n " ;
126 fmt
= "CreationTime=[T2]VolNameLength=[lb] \n VolumeLabel=[c] \n " ;
129 fmt
= "Capabilities=[W] \n MaxFileLen=[U] \n VolNameLen=[lU] \n Volume=[C] \n " ;
132 fmt
= "UnknownLevel \n " ;
135 smb_fdata ( ndo
, data
, fmt
, data
+ dcnt
, unicodestr
);
139 smb_data_print ( ndo
, data
, dcnt
);
143 static const struct smbfnsint trans2_fns
[] = {
144 { 0 , "TRANSACT2_OPEN" , 0 ,
145 { "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]" ,
147 "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 " ,
149 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
150 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
151 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
152 { 3 , "TRANSACT2_QFSINFO" , 0 ,
153 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
154 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
155 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
156 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
157 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
158 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
159 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
160 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
161 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
162 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
163 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
164 { - 1 , NULL
, 0 , DEFDESCRIPT
}
169 print_trans2 ( netdissect_options
* ndo
,
170 const u_char
* words
, const u_char
* dat
, const u_char
* buf
, const u_char
* maxbuf
)
173 static const struct smbfnsint
* fn
= & trans2_fns
[ 0 ];
174 const u_char
* data
, * param
;
175 const u_char
* w
= words
+ 1 ;
176 const char * f1
= NULL
, * f2
= NULL
;
181 ND_TCHECK_2 ( w
+ ( 14 * 2 ));
182 pcnt
= GET_LE_U_2 ( w
+ 9 * 2 );
183 param
= buf
+ GET_LE_U_2 ( w
+ 10 * 2 );
184 dcnt
= GET_LE_U_2 ( w
+ 11 * 2 );
185 data
= buf
+ GET_LE_U_2 ( w
+ 12 * 2 );
186 fn
= smbfindint ( GET_LE_U_2 ( w
+ 14 * 2 ), trans2_fns
);
188 if ( GET_U_1 ( words
) == 0 ) {
189 ND_PRINT ( "%s \n " , fn
-> name
);
190 ND_PRINT ( "Trans2Interim \n " );
193 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
194 pcnt
= GET_LE_U_2 ( w
+ 3 * 2 );
195 param
= buf
+ GET_LE_U_2 ( w
+ 4 * 2 );
196 dcnt
= GET_LE_U_2 ( w
+ 6 * 2 );
197 data
= buf
+ GET_LE_U_2 ( w
+ 7 * 2 );
200 ND_PRINT ( "%s param_length=%u data_length=%u \n " , fn
-> name
, pcnt
, dcnt
);
203 if ( GET_U_1 ( words
) == 8 ) {
204 smb_fdata ( ndo
, words
+ 1 ,
205 "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 " ,
209 smb_fdata ( ndo
, words
+ 1 ,
210 "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 " ,
211 words
+ 1 + 14 * 2 , unicodestr
);
213 f1
= fn
-> descript
. req_f1
;
214 f2
= fn
-> descript
. req_f2
;
216 smb_fdata ( ndo
, words
+ 1 ,
217 "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 " ,
218 words
+ 1 + 10 * 2 , unicodestr
);
219 f1
= fn
-> descript
. rep_f1
;
220 f2
= fn
-> descript
. rep_f2
;
223 bcc
= GET_LE_U_2 ( dat
);
224 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
226 (* fn
-> descript
. fn
)( ndo
, param
, data
, pcnt
, dcnt
);
228 smb_fdata ( ndo
, param
, f1
? f1
: "Parameters= \n " , param
+ pcnt
, unicodestr
);
229 smb_fdata ( ndo
, data
, f2
? f2
: "Data= \n " , data
+ dcnt
, unicodestr
);
237 print_browse ( netdissect_options
* ndo
,
238 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
240 const u_char
* maxbuf
= data
+ datalen
;
243 command
= GET_U_1 ( data
);
245 smb_fdata ( ndo
, param
, "BROWSE PACKET \n |Param " , param
+ paramlen
, unicodestr
);
249 data
= smb_fdata ( ndo
, data
,
250 "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 " ,
255 data
= smb_fdata ( ndo
, data
,
256 "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 " ,
261 data
= smb_fdata ( ndo
, data
,
262 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
267 data
= smb_fdata ( ndo
, data
,
268 "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 " ,
273 data
= smb_fdata ( ndo
, data
,
274 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
279 data
= smb_fdata ( ndo
, data
,
280 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
285 data
= smb_fdata ( ndo
, data
,
286 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token=[W] \n " ,
291 data
= smb_fdata ( ndo
, data
,
292 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token=[W] \n *Name=[S] \n " ,
297 data
= smb_fdata ( ndo
, data
,
298 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
303 data
= smb_fdata ( ndo
, data
,
304 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
, unicodestr
);
308 data
= smb_fdata ( ndo
, data
, "Unknown Browser Frame " , maxbuf
, unicodestr
);
315 print_ipc ( netdissect_options
* ndo
,
316 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
319 smb_fdata ( ndo
, param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
,
322 smb_fdata ( ndo
, data
, "IPC " , data
+ datalen
, unicodestr
);
327 print_trans ( netdissect_options
* ndo
,
328 const u_char
* words
, const u_char
* data1
, const u_char
* buf
, const u_char
* maxbuf
)
331 const char * f1
, * f2
, * f3
, * f4
;
332 const u_char
* data
, * param
;
333 const u_char
* w
= words
+ 1 ;
334 u_int datalen
, paramlen
;
337 ND_TCHECK_2 ( w
+ ( 12 * 2 ));
338 paramlen
= GET_LE_U_2 ( w
+ 9 * 2 );
339 param
= buf
+ GET_LE_U_2 ( w
+ 10 * 2 );
340 datalen
= GET_LE_U_2 ( w
+ 11 * 2 );
341 data
= buf
+ GET_LE_U_2 ( w
+ 12 * 2 );
342 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 " ;
347 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
348 paramlen
= GET_LE_U_2 ( w
+ 3 * 2 );
349 param
= buf
+ GET_LE_U_2 ( w
+ 4 * 2 );
350 datalen
= GET_LE_U_2 ( w
+ 6 * 2 );
351 data
= buf
+ GET_LE_U_2 ( w
+ 7 * 2 );
352 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 " ;
358 smb_fdata ( ndo
, words
+ 1 , f1
,
359 ND_MIN ( words
+ 1 + 2 * GET_U_1 ( words
), maxbuf
),
362 bcc
= GET_LE_U_2 ( data1
);
363 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
365 smb_fdata ( ndo
, data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
), unicodestr
);
367 #define MAILSLOT_BROWSE_STR " \\ MAILSLOT \\ BROWSE"
368 ND_TCHECK_LEN ( data1
+ 2 , strlen ( MAILSLOT_BROWSE_STR
) + 1 );
369 if ( strcmp (( const char *)( data1
+ 2 ), MAILSLOT_BROWSE_STR
) == 0 ) {
370 print_browse ( ndo
, param
, paramlen
, data
, datalen
);
373 #undef MAILSLOT_BROWSE_STR
375 #define PIPE_LANMAN_STR " \\ PIPE \\ LANMAN"
376 ND_TCHECK_LEN ( data1
+ 2 , strlen ( PIPE_LANMAN_STR
) + 1 );
377 if ( strcmp (( const char *)( data1
+ 2 ), PIPE_LANMAN_STR
) == 0 ) {
378 print_ipc ( ndo
, param
, paramlen
, data
, datalen
);
381 #undef PIPE_LANMAN_STR
384 smb_fdata ( ndo
, param
, f3
, ND_MIN ( param
+ paramlen
, maxbuf
), unicodestr
);
386 smb_fdata ( ndo
, data
, f4
, ND_MIN ( data
+ datalen
, maxbuf
), unicodestr
);
395 print_negprot ( netdissect_options
* ndo
,
396 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
399 const char * f1
= NULL
, * f2
= NULL
;
401 wct
= GET_U_1 ( words
);
403 f2
= "*|Dialect=[Y] \n " ;
406 f1
= "Core Protocol \n DialectIndex=[u]" ;
408 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=" ;
410 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=" ;
414 smb_fdata ( ndo
, words
+ 1 , f1
, ND_MIN ( words
+ 1 + wct
* 2 , maxbuf
),
417 smb_data_print ( ndo
, words
+ 1 , ND_MIN ( wct
* 2 , ND_BYTES_BETWEEN ( maxbuf
, words
+ 1 )));
419 bcc
= GET_LE_U_2 ( data
);
420 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
423 smb_fdata ( ndo
, data
+ 2 , f2
, ND_MIN ( data
+ 2 + GET_LE_U_2 ( data
),
424 maxbuf
), unicodestr
);
426 smb_data_print ( ndo
, data
+ 2 ,
427 ND_MIN ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
432 print_sesssetup ( netdissect_options
* ndo
,
433 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
436 const char * f1
= NULL
, * f2
= NULL
;
438 wct
= GET_U_1 ( words
);
441 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 " ;
443 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 " ;
446 f1
= "Com2=[w] \n Off2=[u] \n Action=[w] \n " ;
447 } else if ( wct
== 13 ) {
448 f1
= "Com2=[B] \n Res=[B] \n Off2=[u] \n Action=[w] \n " ;
449 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
454 smb_fdata ( ndo
, words
+ 1 , f1
, ND_MIN ( words
+ 1 + wct
* 2 , maxbuf
),
457 smb_data_print ( ndo
, words
+ 1 , ND_MIN ( wct
* 2 , ND_BYTES_BETWEEN ( maxbuf
, words
+ 1 )));
459 bcc
= GET_LE_U_2 ( data
);
460 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
463 smb_fdata ( ndo
, data
+ 2 , f2
, ND_MIN ( data
+ 2 + GET_LE_U_2 ( data
),
464 maxbuf
), unicodestr
);
466 smb_data_print ( ndo
, data
+ 2 ,
467 ND_MIN ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
472 print_lockingandx ( netdissect_options
* ndo
,
473 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
476 const u_char
* maxwords
;
477 const char * f1
= NULL
, * f2
= NULL
;
479 wct
= GET_U_1 ( words
);
481 f1
= "Com2=[w] \n Off2=[u] \n Handle=[u] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[u] \n LockCount=[u] \n " ;
482 if ( GET_U_1 ( words
+ 7 ) & 0x10 )
483 f2
= "*Process=[u] \n [P2]Offset=[M] \n Length=[M] \n " ;
485 f2
= "*Process=[u] \n Offset=[D] \n Length=[U] \n " ;
487 f1
= "Com2=[w] \n Off2=[u] \n " ;
490 maxwords
= ND_MIN ( words
+ 1 + wct
* 2 , maxbuf
);
492 smb_fdata ( ndo
, words
+ 1 , f1
, maxwords
, unicodestr
);
494 bcc
= GET_LE_U_2 ( data
);
495 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
498 smb_fdata ( ndo
, data
+ 2 , f2
, ND_MIN ( data
+ 2 + GET_LE_U_2 ( data
),
499 maxbuf
), unicodestr
);
501 smb_data_print ( ndo
, data
+ 2 ,
502 ND_MIN ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
507 static const struct smbfns smb_fns
[] = {
508 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
510 { SMBtcon
, "SMBtcon" , 0 ,
511 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
512 "MaxXmit=[u] \n TreeId=[u] \n " , NULL
,
515 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
516 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
517 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
519 { SMBecho
, "SMBecho" , 0 ,
520 { "ReverbCount=[u] \n " , NULL
,
521 "SequenceNum=[u] \n " , NULL
,
524 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
526 { SMBgetatr
, "SMBgetatr" , 0 ,
527 { NULL
, "Path=[Z] \n " ,
528 "Attribute=[A] \n Time=[T2]Size=[U] \n Res=([w,w,w,w,w]) \n " , NULL
,
531 { SMBsetatr
, "SMBsetatr" , 0 ,
532 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
533 NULL
, NULL
, NULL
} },
535 { SMBchkpth
, "SMBchkpth" , 0 ,
536 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
538 { SMBsearch
, "SMBsearch" , 0 ,
539 { "Count=[u] \n Attrib=[A] \n " ,
540 "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 " ,
542 "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 " ,
545 { SMBopen
, "SMBopen" , 0 ,
546 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
547 "Handle=[u] \n OAttrib=[A] \n Time=[T2]Size=[U] \n Access=[w] \n " ,
550 { SMBcreate
, "SMBcreate" , 0 ,
551 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
553 { SMBmknew
, "SMBmknew" , 0 ,
554 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
556 { SMBunlink
, "SMBunlink" , 0 ,
557 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
559 { SMBread
, "SMBread" , 0 ,
560 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
561 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
563 { SMBwrite
, "SMBwrite" , 0 ,
564 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
565 "Count=[u] \n " , NULL
, NULL
} },
567 { SMBclose
, "SMBclose" , 0 ,
568 { "Handle=[u] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
570 { SMBmkdir
, "SMBmkdir" , 0 ,
571 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
573 { SMBrmdir
, "SMBrmdir" , 0 ,
574 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
576 { SMBdskattr
, "SMBdskattr" , 0 ,
578 "TotalUnits=[u] \n BlocksPerUnit=[u] \n BlockSize=[u] \n FreeUnits=[u] \n Media=[w] \n " ,
582 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
585 * this is a Pathworks specific call, allowing the
586 * changing of the root path
588 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
590 { SMBlseek
, "SMBlseek" , 0 ,
591 { "Handle=[u] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
, NULL
} },
593 { SMBflush
, "SMBflush" , 0 , { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
595 { SMBsplopen
, "SMBsplopen" , 0 ,
596 { "SetupLen=[u] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[u] \n " ,
599 { SMBsplclose
, "SMBsplclose" , 0 ,
600 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
602 { SMBsplretq
, "SMBsplretq" , 0 ,
603 { "MaxCount=[u] \n StartIndex=[u] \n " , NULL
,
604 "Count=[u] \n Index=[u] \n " ,
605 "*Time=[T2]Status=[B] \n JobID=[u] \n Size=[U] \n Res=[B]Name=[s16] \n " ,
608 { SMBsplwr
, "SMBsplwr" , 0 ,
609 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
611 { SMBlock
, "SMBlock" , 0 ,
612 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
614 { SMBunlock
, "SMBunlock" , 0 ,
615 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
617 /* CORE+ PROTOCOL FOLLOWS */
619 { SMBreadbraw
, "SMBreadbraw" , 0 ,
620 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[u] \n " ,
621 NULL
, NULL
, NULL
, NULL
} },
623 { SMBwritebraw
, "SMBwritebraw" , 0 ,
624 { "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 " ,
625 NULL
, "WriteRawAck" , NULL
, NULL
} },
627 { SMBwritec
, "SMBwritec" , 0 ,
628 { NULL
, NULL
, "Count=[u] \n " , NULL
, NULL
} },
630 { SMBwriteclose
, "SMBwriteclose" , 0 ,
631 { "Handle=[u] \n Count=[u] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
632 NULL
, "Count=[u] \n " , NULL
, NULL
} },
634 { SMBlockread
, "SMBlockread" , 0 ,
635 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
636 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
638 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
639 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
640 "Count=[u] \n " , NULL
, NULL
} },
642 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
643 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[w] \n " ,
645 "Offset=[D] \n TotCount=[u] \n Remaining=[u] \n Res=([w,w]) \n DataSize=[u] \n DataOff=[u] \n " ,
648 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
649 { "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
,
650 "Remaining=[u] \n " , NULL
, NULL
} },
652 { SMBwriteBs
, "SMBwriteBs" , 0 ,
653 { "Handle=[u] \n TotCount=[u] \n Offset=[D] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n " ,
654 NULL
, "Count=[u] \n " , NULL
, NULL
} },
656 { SMBsetattrE
, "SMBsetattrE" , 0 ,
657 { "Handle=[u] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
658 NULL
, NULL
, NULL
} },
660 { SMBgetattrE
, "SMBgetattrE" , 0 ,
661 { "Handle=[u] \n " , NULL
,
662 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U] \n AllocSize=[U] \n Attribute=[A] \n " ,
665 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
666 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
668 { SMBcopy
, "SMBcopy" , 0 ,
669 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
670 "CopyCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
672 { SMBmove
, "SMBmove" , 0 ,
673 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
674 "MoveCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
676 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
677 { "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 " ,
679 "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 " ,
682 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
683 { "Com2=[w] \n Off2=[u] \n Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n CountLeft=[u] \n " ,
685 "Com2=[w] \n Off2=[u] \n Remaining=[u] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n Res=([w,w,w,w]) \n " ,
688 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
689 { "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 " ,
691 "Com2=[w] \n Off2=[u] \n Count=[u] \n Remaining=[u] \n Res=[W] \n " ,
694 { SMBffirst
, "SMBffirst" , 0 ,
695 { "Count=[u] \n Attrib=[A] \n " ,
696 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
698 "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 " ,
701 { SMBfunique
, "SMBfunique" , 0 ,
702 { "Count=[u] \n Attrib=[A] \n " ,
703 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
705 "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 " ,
708 { SMBfclose
, "SMBfclose" , 0 ,
709 { "Count=[u] \n Attrib=[A] \n " ,
710 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
712 "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 " ,
715 { SMBfindnclose
, "SMBfindnclose" , 0 ,
716 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
718 { SMBfindclose
, "SMBfindclose" , 0 ,
719 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
721 { SMBsends
, "SMBsends" , 0 ,
722 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
724 { SMBsendstrt
, "SMBsendstrt" , 0 ,
725 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[u] \n " , NULL
, NULL
} },
727 { SMBsendend
, "SMBsendend" , 0 ,
728 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
730 { SMBsendtxt
, "SMBsendtxt" , 0 ,
731 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
733 { SMBsendb
, "SMBsendb" , 0 ,
734 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
736 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
737 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
738 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
740 { SMBnegprot
, "SMBnegprot" , 0 ,
741 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
743 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
744 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
746 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
747 { "Com2=[w] \n Off2=[u] \n Flags=[w] \n PassLen=[u] \n Passwd&Path&Device= \n " ,
748 NULL
, "Com2=[w] \n Off2=[u] \n " , "ServiceType=[R] \n " , NULL
} },
750 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
751 { NULL
, NULL
, NULL
, NULL
, print_lockingandx
} },
753 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
755 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
756 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
757 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
758 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
760 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
761 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
763 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
764 { "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 " ,
766 "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 " ,
769 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
771 { - 1 , NULL
, 0 , DEFDESCRIPT
}
776 * print a SMB message
779 print_smb ( netdissect_options
* ndo
,
780 const u_char
* buf
, const u_char
* maxbuf
)
786 const u_char
* words
, * maxwords
, * data
;
787 const struct smbfns
* fn
;
788 const char * fmt_smbheader
=
789 "[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 " ;
792 ndo
-> ndo_protocol
= "smb" ;
794 request
= ( GET_U_1 ( buf
+ 9 ) & 0x80 ) ? 0 : 1 ;
797 command
= GET_U_1 ( buf
+ 4 );
799 fn
= smbfind ( command
, smb_fns
);
801 if ( ndo
-> ndo_vflag
> 1 )
804 ND_PRINT ( "SMB PACKET: %s (%s)" , fn
-> name
, request
? "REQUEST" : "REPLY" );
806 if ( ndo
-> ndo_vflag
< 2 )
810 flags2
= GET_LE_U_2 ( buf
+ 10 );
811 unicodestr
= flags2
& 0x8000 ;
812 nterrcodes
= flags2
& 0x4000 ;
814 /* print out the header */
815 smb_fdata ( ndo
, buf
, fmt_smbheader
, buf
+ 33 , unicodestr
);
818 nterror
= GET_LE_U_4 ( buf
+ 5 );
820 ND_PRINT ( "NTError = %s \n " , nt_errstr ( nterror
));
822 if ( GET_U_1 ( buf
+ 5 ))
823 ND_PRINT ( "SMBError = %s \n " , smb_errstr ( GET_U_1 ( buf
+ 5 ),
824 GET_LE_U_2 ( buf
+ 7 )));
835 words
= buf
+ smboffset
;
836 wct
= GET_U_1 ( words
);
837 data
= words
+ 1 + wct
* 2 ;
838 maxwords
= ND_MIN ( data
, maxbuf
);
841 f1
= fn
-> descript
. req_f1
;
842 f2
= fn
-> descript
. req_f2
;
844 f1
= fn
-> descript
. rep_f1
;
845 f2
= fn
-> descript
. rep_f2
;
850 (* fn
-> descript
. fn
)( ndo
, words
, data
, buf
, maxbuf
);
854 smb_fdata ( ndo
, words
+ 1 , f1
, words
+ 1 + wct
* 2 , unicodestr
);
859 for ( i
= 0 ; words
+ 1 + 2 * i
< maxwords
; i
++) {
860 v
= GET_LE_U_2 ( words
+ 1 + 2 * i
);
861 ND_PRINT ( "smb_vwv[%u]=%u (0x%X) \n " , i
, v
, v
);
866 bcc
= GET_LE_U_2 ( data
);
867 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
870 smb_fdata ( ndo
, data
+ 2 , f2
, data
+ 2 + bcc
, unicodestr
);
873 ND_PRINT ( "smb_buf[]= \n " );
874 smb_data_print ( ndo
, data
+ 2 , ND_MIN ( bcc
, ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
879 if (( fn
-> flags
& FLG_CHAIN
) == 0 )
883 command
= GET_U_1 ( words
+ 1 );
886 newsmboffset
= GET_LE_U_2 ( words
+ 3 );
888 fn
= smbfind ( command
, smb_fns
);
890 ND_PRINT ( " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
891 fn
-> name
, request
? "REQUEST" : "REPLY" );
892 if ( newsmboffset
<= smboffset
) {
893 ND_PRINT ( "Bad andX offset: %u <= %u \n " , newsmboffset
, smboffset
);
896 smboffset
= newsmboffset
;
902 * print a NBT packet received across tcp on port 139
905 nbt_tcp_print ( netdissect_options
* ndo
,
906 const u_char
* data
, u_int length
)
911 const u_char
* maxbuf
;
913 ndo
-> ndo_protocol
= "nbt_tcp" ;
916 if ( ndo
-> ndo_snapend
< data
)
918 caplen
= ND_BYTES_AVAILABLE_AFTER ( data
);
921 maxbuf
= data
+ caplen
;
922 type
= GET_U_1 ( data
);
923 nbt_len
= GET_BE_U_2 ( data
+ 2 );
929 if ( ndo
-> ndo_vflag
< 2 ) {
930 ND_PRINT ( " NBT Session Packet: " );
933 ND_PRINT ( "Session Message" );
937 ND_PRINT ( "Session Request" );
941 ND_PRINT ( "Session Granted" );
954 ecode
= GET_U_1 ( data
+ 4 );
956 ND_PRINT ( "Session Reject, " );
959 ND_PRINT ( "Not listening on called name" );
962 ND_PRINT ( "Not listening for calling name" );
965 ND_PRINT ( "Called name not present" );
968 ND_PRINT ( "Called name present, but insufficient resources" );
971 ND_PRINT ( "Unspecified error 0x%X" , ecode
);
978 ND_PRINT ( "Session Keepalive" );
982 data
= smb_fdata ( ndo
, data
, "Unknown packet type [rB]" , maxbuf
, 0 );
986 ND_PRINT ( " \n >>> NBT Session Packet \n " );
989 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Message \n Flags=[B] \n Length=[ru] \n " ,
993 if ( nbt_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
994 if ( nbt_len
> caplen
) {
995 if ( nbt_len
> length
)
996 ND_PRINT ( "WARNING: Packet is continued in later TCP segments \n " );
998 ND_PRINT ( "WARNING: Short packet. Try increasing the snap length by %u \n " ,
1001 print_smb ( ndo
, data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
1003 ND_PRINT ( "Session packet:(raw data or continuation?) \n " );
1007 data
= smb_fdata ( ndo
, data
,
1008 "[P1]NBT Session Request \n Flags=[B] \n Length=[ru] \n Destination=[n1] \n Source=[n1] \n " ,
1013 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Granted \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1018 const u_char
* origdata
;
1022 data
= smb_fdata ( ndo
, data
, "[P1]NBT SessionReject \n Flags=[B] \n Length=[ru] \n Reason=[B] \n " ,
1026 if ( nbt_len
>= 1 && caplen
>= 1 ) {
1027 ecode
= GET_U_1 ( origdata
+ 4 );
1030 ND_PRINT ( "Not listening on called name \n " );
1033 ND_PRINT ( "Not listening for calling name \n " );
1036 ND_PRINT ( "Called name not present \n " );
1039 ND_PRINT ( "Called name present, but insufficient resources \n " );
1042 ND_PRINT ( "Unspecified error 0x%X \n " , ecode
);
1050 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Keepalive \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1054 data
= smb_fdata ( ndo
, data
, "NBT - Unknown packet type \n Type=[B] \n " , maxbuf
, 0 );
1060 nd_print_trunc ( ndo
);
1063 static const struct tok opcode_str
[] = {
1065 { 5 , "REGISTRATION" },
1068 { 8 , "REFRESH(8)" },
1070 { 15 , "MULTIHOMED REGISTRATION" },
1075 * print a NBT packet received across udp on port 137
1078 nbt_udp137_print ( netdissect_options
* ndo
,
1079 const u_char
* data
, u_int length
)
1081 const u_char
* maxbuf
= data
+ length
;
1082 u_int name_trn_id
, response
, opcode
, nm_flags
, rcode
;
1083 u_int qdcount
, ancount
, nscount
, arcount
;
1087 ndo
-> ndo_protocol
= "nbt_udp137" ;
1088 name_trn_id
= GET_BE_U_2 ( data
);
1089 response
= ( GET_U_1 ( data
+ 2 ) >> 7 );
1090 opcode
= ( GET_U_1 ( data
+ 2 ) >> 3 ) & 0xF ;
1091 nm_flags
= (( GET_U_1 ( data
+ 2 ) & 0x7 ) << 4 ) + ( GET_U_1 ( data
+ 3 ) >> 4 );
1092 rcode
= GET_U_1 ( data
+ 3 ) & 0xF ;
1093 qdcount
= GET_BE_U_2 ( data
+ 4 );
1094 ancount
= GET_BE_U_2 ( data
+ 6 );
1095 nscount
= GET_BE_U_2 ( data
+ 8 );
1096 arcount
= GET_BE_U_2 ( data
+ 10 );
1102 if ( ndo
-> ndo_vflag
> 1 )
1105 ND_PRINT ( "NBT UDP PACKET(137): %s" , tok2str ( opcode_str
, "OPUNKNOWN" , opcode
));
1107 ND_PRINT ( "; %s" , rcode
? "NEGATIVE" : "POSITIVE" );
1109 ND_PRINT ( "; %s; %s" , response
? "RESPONSE" : "REQUEST" ,
1110 ( nm_flags
& 1 ) ? "BROADCAST" : "UNICAST" );
1112 if ( ndo
-> ndo_vflag
< 2 )
1115 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 " ,
1116 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
1121 total
= ancount
+ nscount
+ arcount
;
1123 if ( qdcount
> 100 || total
> 100 ) {
1124 ND_PRINT ( "Corrupt packet?? \n " );
1129 ND_PRINT ( "QuestionRecords: \n " );
1130 for ( i
= 0 ; i
< qdcount
; i
++) {
1131 p
= smb_fdata ( ndo
, p
,
1132 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
1140 ND_PRINT ( " \n ResourceRecords: \n " );
1141 for ( i
= 0 ; i
< total
; i
++) {
1145 p
= smb_fdata ( ndo
, p
, "Name=[n1] \n #" , maxbuf
, 0 );
1148 restype
= GET_BE_U_2 ( p
);
1149 p
= smb_fdata ( ndo
, p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rU] \n " , p
+ 8 , 0 );
1152 rdlen
= GET_BE_U_2 ( p
);
1153 ND_PRINT ( "ResourceLength=%u \n ResourceData= \n " , rdlen
);
1156 p
= smb_fdata ( ndo
, p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
, 0 );
1160 if ( restype
== 0x21 ) {
1163 numnames
= GET_U_1 ( p
);
1164 p
= smb_fdata ( ndo
, p
, "NumNames=[B] \n " , p
+ 1 , 0 );
1168 p
= smb_fdata ( ndo
, p
, "Name=[n2] \t #" , maxbuf
, 0 );
1174 if ( GET_U_1 ( p
) & 0x80 )
1175 ND_PRINT ( "<GROUP> " );
1176 switch ( GET_U_1 ( p
) & 0x60 ) {
1177 case 0x00 : ND_PRINT ( "B " ); break ;
1178 case 0x20 : ND_PRINT ( "P " ); break ;
1179 case 0x40 : ND_PRINT ( "M " ); break ;
1180 case 0x60 : ND_PRINT ( "_ " ); break ;
1182 if ( GET_U_1 ( p
) & 0x10 )
1183 ND_PRINT ( "<DEREGISTERING> " );
1184 if ( GET_U_1 ( p
) & 0x08 )
1185 ND_PRINT ( "<CONFLICT> " );
1186 if ( GET_U_1 ( p
) & 0x04 )
1187 ND_PRINT ( "<ACTIVE> " );
1188 if ( GET_U_1 ( p
) & 0x02 )
1189 ND_PRINT ( "<PERMANENT> " );
1197 smb_data_print ( ndo
, p
, ND_MIN ( rdlen
, length
- ND_BYTES_BETWEEN ( p
, data
)));
1205 smb_fdata ( ndo
, p
, "AdditionalData: \n " , maxbuf
, 0 );
1210 nd_print_trunc ( ndo
);
1214 * Print an SMB-over-TCP packet received across tcp on port 445
1217 smb_tcp_print ( netdissect_options
* ndo
,
1218 const u_char
* data
, u_int length
)
1222 const u_char
* maxbuf
;
1224 ndo
-> ndo_protocol
= "smb_tcp" ;
1227 if ( ndo
-> ndo_snapend
< data
)
1229 caplen
= ND_BYTES_AVAILABLE_AFTER ( data
);
1232 maxbuf
= data
+ caplen
;
1233 smb_len
= GET_BE_U_3 ( data
+ 1 );
1240 if ( smb_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1241 if ( smb_len
> caplen
) {
1242 if ( smb_len
> length
)
1243 ND_PRINT ( " WARNING: Packet is continued in later TCP segments \n " );
1245 ND_PRINT ( " WARNING: Short packet. Try increasing the snap length by %u \n " ,
1249 print_smb ( ndo
, data
, maxbuf
> data
+ smb_len
? data
+ smb_len
: maxbuf
);
1251 ND_PRINT ( " SMB-over-TCP packet:(raw data or continuation?) \n " );
1254 nd_print_trunc ( ndo
);
1258 * print a NBT packet received across udp on port 138
1261 nbt_udp138_print ( netdissect_options
* ndo
,
1262 const u_char
* data
, u_int length
)
1264 const u_char
* maxbuf
= data
+ length
;
1266 ndo
-> ndo_protocol
= "nbt_udp138" ;
1267 if ( maxbuf
> ndo
-> ndo_snapend
)
1268 maxbuf
= ndo
-> ndo_snapend
;
1273 if ( ndo
-> ndo_vflag
< 2 ) {
1274 ND_PRINT ( "NBT UDP PACKET(138)" );
1278 data
= smb_fdata ( ndo
, data
,
1279 " \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 #" ,
1283 /* If there isn't enough data for "\377SMB", don't check for it. */
1284 if (( data
+ 3 ) >= maxbuf
)
1287 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 )
1288 print_smb ( ndo
, data
, maxbuf
);
1296 print netbeui frames
1298 static struct nbf_strings
{
1300 const char * nonverbose
;
1301 const char * verbose
;
1302 } nbf_strings
[ 0x20 ] = {
1303 { "Add Group Name Query" , ", [P23]Name to add=[n2]#" ,
1304 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1305 { "Add Name Query" , ", [P23]Name to add=[n2]#" ,
1306 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1307 { "Name In Conflict" , NULL
, NULL
},
1308 { "Status Query" , NULL
, NULL
},
1309 { NULL
, NULL
, NULL
}, /* not used */
1310 { NULL
, NULL
, NULL
}, /* not used */
1311 { NULL
, NULL
, NULL
}, /* not used */
1312 { "Terminate Trace" , NULL
, NULL
},
1314 "[P7]Destination=[n2] \n Source=[n2] \n " },
1315 { "Broadcast Datagram" , NULL
,
1316 "[P7]Destination=[n2] \n Source=[n2] \n " },
1317 { "Name Query" , ", [P7]Name=[n2]#" ,
1318 "[P1]SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Name=[n2] \n Name of sender=[n2] \n " },
1319 { NULL
, NULL
, NULL
}, /* not used */
1320 { NULL
, NULL
, NULL
}, /* not used */
1321 { "Add Name Response" , ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#" ,
1322 "AddNameInProcess=[B] \n GroupName=[w] \n TransmitCorrelator=[w][P2] \n Destination=[n2] \n Source=[n2] \n " },
1323 { "Name Recognized" , NULL
,
1324 "[P1]Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " },
1325 { "Status Response" , NULL
, NULL
},
1326 { NULL
, NULL
, NULL
}, /* not used */
1327 { NULL
, NULL
, NULL
}, /* not used */
1328 { NULL
, NULL
, NULL
}, /* not used */
1329 { "Terminate Trace" , NULL
, NULL
},
1331 "[P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1332 { "Data First/Middle" , NULL
,
1333 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1334 { "Data Only/Last" , NULL
,
1335 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1336 { "Session Confirm" , NULL
,
1337 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1338 { "Session End" , NULL
,
1339 "[P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1340 { "Session Initialize" , NULL
,
1341 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1342 { "No Receive" , NULL
,
1343 "Flags=[{|SEND_NO_ACK}] \n DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1344 { "Receive Outstanding" , NULL
,
1345 "[P1]DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1346 { "Receive Continue" , NULL
,
1347 "[P2]TransmitCorrelator=[w] \n [P2]RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1348 { NULL
, NULL
, NULL
}, /* not used */
1349 { NULL
, NULL
, NULL
}, /* not used */
1350 { "Session Alive" , NULL
, NULL
}
1354 netbeui_print ( netdissect_options
* ndo
,
1355 u_short control
, const u_char
* data
, u_int length
)
1357 const u_char
* maxbuf
= data
+ length
;
1360 const u_char
* data2
;
1361 int is_truncated
= 0 ;
1363 ndo
-> ndo_protocol
= "netbeui" ;
1364 if ( maxbuf
> ndo
-> ndo_snapend
)
1365 maxbuf
= ndo
-> ndo_snapend
;
1366 len
= GET_LE_U_2 ( data
);
1367 command
= GET_U_1 ( data
+ 4 );
1369 if ( data2
>= maxbuf
) {
1376 if ( ndo
-> ndo_vflag
< 2 ) {
1377 ND_PRINT ( "NBF Packet: " );
1378 data
= smb_fdata ( ndo
, data
, "[P5]#" , maxbuf
, 0 );
1380 ND_PRINT ( " \n >>> NBF Packet \n Type=0x%X " , control
);
1381 data
= smb_fdata ( ndo
, data
, "Length=[u] Signature=[w] Command=[B] \n #" , maxbuf
, 0 );
1386 if ( command
> 0x1f || nbf_strings
[ command
]. name
== NULL
) {
1387 if ( ndo
-> ndo_vflag
< 2 )
1388 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command#" , data2
, 0 );
1390 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command \n " , data2
, 0 );
1392 if ( ndo
-> ndo_vflag
< 2 ) {
1393 ND_PRINT ( "%s" , nbf_strings
[ command
]. name
);
1394 if ( nbf_strings
[ command
]. nonverbose
!= NULL
)
1395 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. nonverbose
, data2
, 0 );
1397 ND_PRINT ( "%s: \n " , nbf_strings
[ command
]. name
);
1398 if ( nbf_strings
[ command
]. verbose
!= NULL
)
1399 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. verbose
, data2
, 0 );
1405 if ( ndo
-> ndo_vflag
< 2 )
1412 /* data2 was past the end of the buffer */
1416 /* If this isn't a command that would contain an SMB message, quit. */
1417 if ( command
!= 0x08 && command
!= 0x09 && command
!= 0x15 &&
1421 /* If there isn't enough data for "\377SMB", don't look for it. */
1422 if (( data2
+ 3 ) >= maxbuf
)
1425 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1426 print_smb ( ndo
, data2
, maxbuf
);
1429 for ( i
= 0 ; i
< 128 ; i
++) {
1430 if (( data2
+ i
+ 3 ) >= maxbuf
)
1432 if ( memcmp ( data2
+ i
, " \377 SMB" , 4 ) == 0 ) {
1433 ND_PRINT ( "found SMB packet at %u \n " , i
);
1434 print_smb ( ndo
, data2
+ i
, maxbuf
);
1446 * print IPX-Netbios frames
1449 ipx_netbios_print ( netdissect_options
* ndo
,
1450 const u_char
* data
, u_int length
)
1453 * this is a hack till I work out how to parse the rest of the
1454 * NetBIOS-over-IPX stuff
1457 const u_char
* maxbuf
;
1459 ndo
-> ndo_protocol
= "ipx_netbios" ;
1460 maxbuf
= data
+ length
;
1461 /* Don't go past the end of the captured data in the packet. */
1462 if ( maxbuf
> ndo
-> ndo_snapend
)
1463 maxbuf
= ndo
-> ndo_snapend
;
1465 for ( i
= 0 ; i
< 128 ; i
++) {
1466 if (( data
+ i
+ 4 ) > maxbuf
)
1468 if ( memcmp ( data
+ i
, " \377 SMB" , 4 ) == 0 ) {
1469 smb_fdata ( ndo
, data
, " \n >>> IPX transport " , data
+ i
, 0 );
1470 print_smb ( ndo
, data
+ i
, maxbuf
);
1475 smb_fdata ( ndo
, data
, " \n >>> Unknown IPX " , maxbuf
, 0 );