]>
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 ;
118 level
= GET_LE_U_2 ( param
);
119 fmt
= "InfoLevel=[u] \n " ;
120 smb_fdata ( ndo
, param
, fmt
, param
+ pcnt
, unicodestr
);
124 fmt
= "idFileSystem=[W] \n SectorUnit=[U] \n Unit=[U] \n Avail=[U] \n SectorSize=[u] \n " ;
127 fmt
= "CreationTime=[T2]VolNameLength=[lb] \n VolumeLabel=[c] \n " ;
130 fmt
= "Capabilities=[W] \n MaxFileLen=[U] \n VolNameLen=[lU] \n Volume=[C] \n " ;
133 fmt
= "UnknownLevel \n " ;
136 smb_fdata ( ndo
, data
, fmt
, data
+ dcnt
, unicodestr
);
140 smb_data_print ( ndo
, data
, dcnt
);
147 static const struct smbfnsint trans2_fns
[] = {
148 { 0 , "TRANSACT2_OPEN" , 0 ,
149 { "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]" ,
151 "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 " ,
153 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
154 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
155 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
156 { 3 , "TRANSACT2_QFSINFO" , 0 ,
157 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
158 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
159 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
160 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
161 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
162 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
163 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
164 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
165 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
166 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
167 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
168 { - 1 , NULL
, 0 , DEFDESCRIPT
}
173 print_trans2 ( netdissect_options
* ndo
,
174 const u_char
* words
, const u_char
* dat
, const u_char
* buf
, const u_char
* maxbuf
)
177 static const struct smbfnsint
* fn
= & trans2_fns
[ 0 ];
178 const u_char
* data
, * param
;
179 const u_char
* w
= words
+ 1 ;
180 const char * f1
= NULL
, * f2
= NULL
;
185 ND_TCHECK_2 ( w
+ ( 14 * 2 ));
186 pcnt
= GET_LE_U_2 ( w
+ 9 * 2 );
187 param
= buf
+ GET_LE_U_2 ( w
+ 10 * 2 );
188 dcnt
= GET_LE_U_2 ( w
+ 11 * 2 );
189 data
= buf
+ GET_LE_U_2 ( w
+ 12 * 2 );
190 fn
= smbfindint ( GET_LE_U_2 ( w
+ 14 * 2 ), trans2_fns
);
192 if ( GET_U_1 ( words
) == 0 ) {
193 ND_PRINT ( "%s \n " , fn
-> name
);
194 ND_PRINT ( "Trans2Interim \n " );
197 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
198 pcnt
= GET_LE_U_2 ( w
+ 3 * 2 );
199 param
= buf
+ GET_LE_U_2 ( w
+ 4 * 2 );
200 dcnt
= GET_LE_U_2 ( w
+ 6 * 2 );
201 data
= buf
+ GET_LE_U_2 ( w
+ 7 * 2 );
204 ND_PRINT ( "%s param_length=%u data_length=%u \n " , fn
-> name
, pcnt
, dcnt
);
207 if ( GET_U_1 ( words
) == 8 ) {
208 smb_fdata ( ndo
, words
+ 1 ,
209 "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 " ,
213 smb_fdata ( ndo
, words
+ 1 ,
214 "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 " ,
215 words
+ 1 + 14 * 2 , unicodestr
);
217 f1
= fn
-> descript
. req_f1
;
218 f2
= fn
-> descript
. req_f2
;
220 smb_fdata ( ndo
, words
+ 1 ,
221 "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 " ,
222 words
+ 1 + 10 * 2 , unicodestr
);
223 f1
= fn
-> descript
. rep_f1
;
224 f2
= fn
-> descript
. rep_f2
;
228 bcc
= GET_LE_U_2 ( dat
);
229 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
231 (* fn
-> descript
. fn
)( ndo
, param
, data
, pcnt
, dcnt
);
233 smb_fdata ( ndo
, param
, f1
? f1
: "Parameters= \n " , param
+ pcnt
, unicodestr
);
234 smb_fdata ( ndo
, data
, f2
? f2
: "Data= \n " , data
+ dcnt
, unicodestr
);
242 print_browse ( netdissect_options
* ndo
,
243 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
245 const u_char
* maxbuf
= data
+ datalen
;
249 command
= GET_U_1 ( data
);
251 smb_fdata ( ndo
, param
, "BROWSE PACKET \n |Param " , param
+ paramlen
, unicodestr
);
255 data
= smb_fdata ( ndo
, data
,
256 "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 " ,
261 data
= smb_fdata ( ndo
, data
,
262 "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 " ,
267 data
= smb_fdata ( ndo
, data
,
268 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
273 data
= smb_fdata ( ndo
, data
,
274 "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 " ,
279 data
= smb_fdata ( ndo
, data
,
280 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
285 data
= smb_fdata ( ndo
, data
,
286 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
291 data
= smb_fdata ( ndo
, data
,
292 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token=[W] \n " ,
297 data
= smb_fdata ( ndo
, data
,
298 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token=[W] \n *Name=[S] \n " ,
303 data
= smb_fdata ( ndo
, data
,
304 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
309 data
= smb_fdata ( ndo
, data
,
310 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
, unicodestr
);
314 data
= smb_fdata ( ndo
, data
, "Unknown Browser Frame " , maxbuf
, unicodestr
);
324 print_ipc ( netdissect_options
* ndo
,
325 const u_char
* param
, u_int paramlen
, const u_char
* data
, u_int datalen
)
328 smb_fdata ( ndo
, param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
,
331 smb_fdata ( ndo
, data
, "IPC " , data
+ datalen
, unicodestr
);
336 print_trans ( netdissect_options
* ndo
,
337 const u_char
* words
, const u_char
* data1
, const u_char
* buf
, const u_char
* maxbuf
)
340 const char * f1
, * f2
, * f3
, * f4
;
341 const u_char
* data
, * param
;
342 const u_char
* w
= words
+ 1 ;
343 u_int datalen
, paramlen
;
346 ND_TCHECK_2 ( w
+ ( 12 * 2 ));
347 paramlen
= GET_LE_U_2 ( w
+ 9 * 2 );
348 param
= buf
+ GET_LE_U_2 ( w
+ 10 * 2 );
349 datalen
= GET_LE_U_2 ( w
+ 11 * 2 );
350 data
= buf
+ GET_LE_U_2 ( w
+ 12 * 2 );
351 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 " ;
356 ND_TCHECK_2 ( w
+ ( 7 * 2 ));
357 paramlen
= GET_LE_U_2 ( w
+ 3 * 2 );
358 param
= buf
+ GET_LE_U_2 ( w
+ 4 * 2 );
359 datalen
= GET_LE_U_2 ( w
+ 6 * 2 );
360 data
= buf
+ GET_LE_U_2 ( w
+ 7 * 2 );
361 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 " ;
367 smb_fdata ( ndo
, words
+ 1 , f1
,
368 min ( words
+ 1 + 2 * GET_U_1 ( words
), maxbuf
),
372 bcc
= GET_LE_U_2 ( data1
);
373 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
375 smb_fdata ( ndo
, data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
), unicodestr
);
377 #define MAILSLOT_BROWSE_STR " \\ MAILSLOT \\ BROWSE"
378 ND_TCHECK_LEN ( data1
+ 2 , strlen ( MAILSLOT_BROWSE_STR
) + 1 );
379 if ( strcmp (( const char *)( data1
+ 2 ), MAILSLOT_BROWSE_STR
) == 0 ) {
380 print_browse ( ndo
, param
, paramlen
, data
, datalen
);
383 #undef MAILSLOT_BROWSE_STR
385 #define PIPE_LANMAN_STR " \\ PIPE \\ LANMAN"
386 ND_TCHECK_LEN ( data1
+ 2 , strlen ( PIPE_LANMAN_STR
) + 1 );
387 if ( strcmp (( const char *)( data1
+ 2 ), PIPE_LANMAN_STR
) == 0 ) {
388 print_ipc ( ndo
, param
, paramlen
, data
, datalen
);
391 #undef PIPE_LANMAN_STR
394 smb_fdata ( ndo
, param
, f3
, min ( param
+ paramlen
, maxbuf
), unicodestr
);
396 smb_fdata ( ndo
, data
, f4
, min ( data
+ datalen
, maxbuf
), unicodestr
);
405 print_negprot ( netdissect_options
* ndo
,
406 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
409 const char * f1
= NULL
, * f2
= NULL
;
412 wct
= GET_U_1 ( words
);
414 f2
= "*|Dialect=[Y] \n " ;
417 f1
= "Core Protocol \n DialectIndex=[u]" ;
419 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=" ;
421 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=" ;
425 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
428 smb_data_print ( ndo
, words
+ 1 , min ( wct
* 2 , ND_BYTES_BETWEEN ( maxbuf
, words
+ 1 )));
431 bcc
= GET_LE_U_2 ( data
);
432 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
435 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + GET_LE_U_2 ( data
),
436 maxbuf
), unicodestr
);
438 smb_data_print ( ndo
, data
+ 2 ,
439 min ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
447 print_sesssetup ( netdissect_options
* ndo
,
448 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
451 const char * f1
= NULL
, * f2
= NULL
;
454 wct
= GET_U_1 ( words
);
457 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 " ;
459 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 " ;
462 f1
= "Com2=[w] \n Off2=[u] \n Action=[w] \n " ;
463 } else if ( wct
== 13 ) {
464 f1
= "Com2=[B] \n Res=[B] \n Off2=[u] \n Action=[w] \n " ;
465 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
470 smb_fdata ( ndo
, words
+ 1 , f1
, min ( words
+ 1 + wct
* 2 , maxbuf
),
473 smb_data_print ( ndo
, words
+ 1 , min ( wct
* 2 , ND_BYTES_BETWEEN ( maxbuf
, words
+ 1 )));
476 bcc
= GET_LE_U_2 ( data
);
477 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
480 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + GET_LE_U_2 ( data
),
481 maxbuf
), unicodestr
);
483 smb_data_print ( ndo
, data
+ 2 ,
484 min ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
492 print_lockingandx ( netdissect_options
* ndo
,
493 const u_char
* words
, const u_char
* data
, const u_char
* buf _U_
, const u_char
* maxbuf
)
496 const u_char
* maxwords
;
497 const char * f1
= NULL
, * f2
= NULL
;
500 wct
= GET_U_1 ( words
);
502 f1
= "Com2=[w] \n Off2=[u] \n Handle=[u] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[u] \n LockCount=[u] \n " ;
503 ND_TCHECK_1 ( words
+ 7 );
504 if ( GET_U_1 ( words
+ 7 ) & 0x10 )
505 f2
= "*Process=[u] \n [P2]Offset=[M] \n Length=[M] \n " ;
507 f2
= "*Process=[u] \n Offset=[D] \n Length=[U] \n " ;
509 f1
= "Com2=[w] \n Off2=[u] \n " ;
512 maxwords
= min ( words
+ 1 + wct
* 2 , maxbuf
);
514 smb_fdata ( ndo
, words
+ 1 , f1
, maxwords
, unicodestr
);
517 bcc
= GET_LE_U_2 ( data
);
518 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
521 smb_fdata ( ndo
, data
+ 2 , f2
, min ( data
+ 2 + GET_LE_U_2 ( data
),
522 maxbuf
), unicodestr
);
524 smb_data_print ( ndo
, data
+ 2 ,
525 min ( GET_LE_U_2 ( data
), ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
533 static const struct smbfns smb_fns
[] = {
534 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
536 { SMBtcon
, "SMBtcon" , 0 ,
537 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
538 "MaxXmit=[u] \n TreeId=[u] \n " , NULL
,
541 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
542 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
543 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
545 { SMBecho
, "SMBecho" , 0 ,
546 { "ReverbCount=[u] \n " , NULL
,
547 "SequenceNum=[u] \n " , NULL
,
550 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
552 { SMBgetatr
, "SMBgetatr" , 0 ,
553 { NULL
, "Path=[Z] \n " ,
554 "Attribute=[A] \n Time=[T2]Size=[U] \n Res=([w,w,w,w,w]) \n " , NULL
,
557 { SMBsetatr
, "SMBsetatr" , 0 ,
558 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
559 NULL
, NULL
, NULL
} },
561 { SMBchkpth
, "SMBchkpth" , 0 ,
562 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
564 { SMBsearch
, "SMBsearch" , 0 ,
565 { "Count=[u] \n Attrib=[A] \n " ,
566 "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 " ,
568 "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 " ,
571 { SMBopen
, "SMBopen" , 0 ,
572 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
573 "Handle=[u] \n OAttrib=[A] \n Time=[T2]Size=[U] \n Access=[w] \n " ,
576 { SMBcreate
, "SMBcreate" , 0 ,
577 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
579 { SMBmknew
, "SMBmknew" , 0 ,
580 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[u] \n " , NULL
, NULL
} },
582 { SMBunlink
, "SMBunlink" , 0 ,
583 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
585 { SMBread
, "SMBread" , 0 ,
586 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
587 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
589 { SMBwrite
, "SMBwrite" , 0 ,
590 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
591 "Count=[u] \n " , NULL
, NULL
} },
593 { SMBclose
, "SMBclose" , 0 ,
594 { "Handle=[u] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
596 { SMBmkdir
, "SMBmkdir" , 0 ,
597 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
599 { SMBrmdir
, "SMBrmdir" , 0 ,
600 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
602 { SMBdskattr
, "SMBdskattr" , 0 ,
604 "TotalUnits=[u] \n BlocksPerUnit=[u] \n BlockSize=[u] \n FreeUnits=[u] \n Media=[w] \n " ,
608 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
611 * this is a Pathworks specific call, allowing the
612 * changing of the root path
614 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
616 { SMBlseek
, "SMBlseek" , 0 ,
617 { "Handle=[u] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
, NULL
} },
619 { SMBflush
, "SMBflush" , 0 , { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
621 { SMBsplopen
, "SMBsplopen" , 0 ,
622 { "SetupLen=[u] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[u] \n " ,
625 { SMBsplclose
, "SMBsplclose" , 0 ,
626 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
628 { SMBsplretq
, "SMBsplretq" , 0 ,
629 { "MaxCount=[u] \n StartIndex=[u] \n " , NULL
,
630 "Count=[u] \n Index=[u] \n " ,
631 "*Time=[T2]Status=[B] \n JobID=[u] \n Size=[U] \n Res=[B]Name=[s16] \n " ,
634 { SMBsplwr
, "SMBsplwr" , 0 ,
635 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
637 { SMBlock
, "SMBlock" , 0 ,
638 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
640 { SMBunlock
, "SMBunlock" , 0 ,
641 { "Handle=[u] \n Count=[U] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
643 /* CORE+ PROTOCOL FOLLOWS */
645 { SMBreadbraw
, "SMBreadbraw" , 0 ,
646 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[u] \n " ,
647 NULL
, NULL
, NULL
, NULL
} },
649 { SMBwritebraw
, "SMBwritebraw" , 0 ,
650 { "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 " ,
651 NULL
, "WriteRawAck" , NULL
, NULL
} },
653 { SMBwritec
, "SMBwritec" , 0 ,
654 { NULL
, NULL
, "Count=[u] \n " , NULL
, NULL
} },
656 { SMBwriteclose
, "SMBwriteclose" , 0 ,
657 { "Handle=[u] \n Count=[u] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
658 NULL
, "Count=[u] \n " , NULL
, NULL
} },
660 { SMBlockread
, "SMBlockread" , 0 ,
661 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
662 "Count=[u] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
664 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
665 { "Handle=[u] \n ByteCount=[u] \n Offset=[D] \n CountLeft=[u] \n " , NULL
,
666 "Count=[u] \n " , NULL
, NULL
} },
668 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
669 { "Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n Res=[w] \n " ,
671 "Offset=[D] \n TotCount=[u] \n Remaining=[u] \n Res=([w,w]) \n DataSize=[u] \n DataOff=[u] \n " ,
674 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
675 { "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
,
676 "Remaining=[u] \n " , NULL
, NULL
} },
678 { SMBwriteBs
, "SMBwriteBs" , 0 ,
679 { "Handle=[u] \n TotCount=[u] \n Offset=[D] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n " ,
680 NULL
, "Count=[u] \n " , NULL
, NULL
} },
682 { SMBsetattrE
, "SMBsetattrE" , 0 ,
683 { "Handle=[u] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
684 NULL
, NULL
, NULL
} },
686 { SMBgetattrE
, "SMBgetattrE" , 0 ,
687 { "Handle=[u] \n " , NULL
,
688 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[U] \n AllocSize=[U] \n Attribute=[A] \n " ,
691 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
692 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
694 { SMBcopy
, "SMBcopy" , 0 ,
695 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
696 "CopyCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
698 { SMBmove
, "SMBmove" , 0 ,
699 { "TreeID2=[u] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
700 "MoveCount=[u] \n " , "|ErrStr=[S] \n " , NULL
} },
702 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
703 { "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 " ,
705 "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 " ,
708 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
709 { "Com2=[w] \n Off2=[u] \n Handle=[u] \n Offset=[D] \n MaxCount=[u] \n MinCount=[u] \n TimeOut=[D] \n CountLeft=[u] \n " ,
711 "Com2=[w] \n Off2=[u] \n Remaining=[u] \n Res=[W] \n DataSize=[u] \n DataOff=[u] \n Res=([w,w,w,w]) \n " ,
714 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
715 { "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 " ,
717 "Com2=[w] \n Off2=[u] \n Count=[u] \n Remaining=[u] \n Res=[W] \n " ,
720 { SMBffirst
, "SMBffirst" , 0 ,
721 { "Count=[u] \n Attrib=[A] \n " ,
722 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
724 "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 " ,
727 { SMBfunique
, "SMBfunique" , 0 ,
728 { "Count=[u] \n Attrib=[A] \n " ,
729 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
731 "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 " ,
734 { SMBfclose
, "SMBfclose" , 0 ,
735 { "Count=[u] \n Attrib=[A] \n " ,
736 "Path=[Z] \n BlkType=[B] \n BlkLen=[u] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[u] \n Srv2=[w] \n " ,
738 "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 " ,
741 { SMBfindnclose
, "SMBfindnclose" , 0 ,
742 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
744 { SMBfindclose
, "SMBfindclose" , 0 ,
745 { "Handle=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
747 { SMBsends
, "SMBsends" , 0 ,
748 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
750 { SMBsendstrt
, "SMBsendstrt" , 0 ,
751 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[u] \n " , NULL
, NULL
} },
753 { SMBsendend
, "SMBsendend" , 0 ,
754 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
756 { SMBsendtxt
, "SMBsendtxt" , 0 ,
757 { "GroupID=[u] \n " , NULL
, NULL
, NULL
, NULL
} },
759 { SMBsendb
, "SMBsendb" , 0 ,
760 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
762 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
763 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
764 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
766 { SMBnegprot
, "SMBnegprot" , 0 ,
767 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
769 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
770 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
772 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
773 { "Com2=[w] \n Off2=[u] \n Flags=[w] \n PassLen=[u] \n Passwd&Path&Device= \n " ,
774 NULL
, "Com2=[w] \n Off2=[u] \n " , "ServiceType=[R] \n " , NULL
} },
776 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
777 { NULL
, NULL
, NULL
, NULL
, print_lockingandx
} },
779 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
781 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
782 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
783 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
784 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
786 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
787 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
789 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
790 { "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 " ,
792 "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 " ,
795 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
797 { - 1 , NULL
, 0 , DEFDESCRIPT
}
802 * print a SMB message
805 print_smb ( netdissect_options
* ndo
,
806 const u_char
* buf
, const u_char
* maxbuf
)
812 const u_char
* words
, * maxwords
, * data
;
813 const struct smbfns
* fn
;
814 const char * fmt_smbheader
=
815 "[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 " ;
818 ndo
-> ndo_protocol
= "smb" ;
820 ND_TCHECK_1 ( buf
+ 9 );
821 request
= ( GET_U_1 ( buf
+ 9 ) & 0x80 ) ? 0 : 1 ;
824 command
= GET_U_1 ( buf
+ 4 );
826 fn
= smbfind ( command
, smb_fns
);
828 if ( ndo
-> ndo_vflag
> 1 )
831 ND_PRINT ( "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
833 if ( ndo
-> ndo_vflag
< 2 )
836 ND_TCHECK_2 ( buf
+ 10 );
837 flags2
= GET_LE_U_2 ( buf
+ 10 );
838 unicodestr
= flags2
& 0x8000 ;
839 nterrcodes
= flags2
& 0x4000 ;
841 /* print out the header */
842 smb_fdata ( ndo
, buf
, fmt_smbheader
, buf
+ 33 , unicodestr
);
845 nterror
= GET_LE_U_4 ( buf
+ 5 );
847 ND_PRINT ( "NTError = %s \n " , nt_errstr ( nterror
));
849 if ( GET_U_1 ( buf
+ 5 ))
850 ND_PRINT ( "SMBError = %s \n " , smb_errstr ( GET_U_1 ( buf
+ 5 ),
851 GET_LE_U_2 ( buf
+ 7 )));
862 words
= buf
+ smboffset
;
864 wct
= GET_U_1 ( words
);
865 data
= words
+ 1 + wct
* 2 ;
866 maxwords
= min ( data
, maxbuf
);
869 f1
= fn
-> descript
. req_f1
;
870 f2
= fn
-> descript
. req_f2
;
872 f1
= fn
-> descript
. rep_f1
;
873 f2
= fn
-> descript
. rep_f2
;
878 (* fn
-> descript
. fn
)( ndo
, words
, data
, buf
, maxbuf
);
882 smb_fdata ( ndo
, words
+ 1 , f1
, words
+ 1 + wct
* 2 , unicodestr
);
887 for ( i
= 0 ; words
+ 1 + 2 * i
< maxwords
; i
++) {
888 ND_TCHECK_2 ( words
+ 1 + 2 * i
);
889 v
= GET_LE_U_2 ( words
+ 1 + 2 * i
);
890 ND_PRINT ( "smb_vwv[%u]=%u (0x%X) \n " , i
, v
, v
);
896 bcc
= GET_LE_U_2 ( data
);
897 ND_PRINT ( "smb_bcc=%u \n " , bcc
);
900 smb_fdata ( ndo
, data
+ 2 , f2
, data
+ 2 + bcc
, unicodestr
);
903 ND_PRINT ( "smb_buf[]= \n " );
904 smb_data_print ( ndo
, data
+ 2 , min ( bcc
, ND_BYTES_BETWEEN ( maxbuf
, data
+ 2 )));
909 if (( fn
-> flags
& FLG_CHAIN
) == 0 )
913 ND_TCHECK_1 ( words
+ 1 );
914 command
= GET_U_1 ( words
+ 1 );
917 ND_TCHECK_2 ( words
+ 3 );
918 newsmboffset
= GET_LE_U_2 ( words
+ 3 );
920 fn
= smbfind ( command
, smb_fns
);
922 ND_PRINT ( " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
923 fn
-> name
, request
? "REQUEST" : "REPLY" );
924 if ( newsmboffset
<= smboffset
) {
925 ND_PRINT ( "Bad andX offset: %u <= %u \n " , newsmboffset
, smboffset
);
928 smboffset
= newsmboffset
;
939 * print a NBT packet received across tcp on port 139
942 nbt_tcp_print ( netdissect_options
* ndo
,
943 const u_char
* data
, u_int length
)
948 const u_char
* maxbuf
;
950 ndo
-> ndo_protocol
= "nbt_tcp" ;
953 if ( ndo
-> ndo_snapend
< data
)
955 caplen
= ndo
-> ndo_snapend
- data
;
958 maxbuf
= data
+ caplen
;
960 type
= GET_U_1 ( data
);
961 ND_TCHECK_2 ( data
+ 2 );
962 nbt_len
= GET_BE_U_2 ( data
+ 2 );
968 if ( ndo
-> ndo_vflag
< 2 ) {
969 ND_PRINT ( " NBT Session Packet: " );
972 ND_PRINT ( "Session Message" );
976 ND_PRINT ( "Session Request" );
980 ND_PRINT ( "Session Granted" );
993 ecode
= GET_U_1 ( data
+ 4 );
995 ND_PRINT ( "Session Reject, " );
998 ND_PRINT ( "Not listening on called name" );
1001 ND_PRINT ( "Not listening for calling name" );
1004 ND_PRINT ( "Called name not present" );
1007 ND_PRINT ( "Called name present, but insufficient resources" );
1010 ND_PRINT ( "Unspecified error 0x%X" , ecode
);
1017 ND_PRINT ( "Session Keepalive" );
1021 data
= smb_fdata ( ndo
, data
, "Unknown packet type [rB]" , maxbuf
, 0 );
1025 ND_PRINT ( " \n >>> NBT Session Packet \n " );
1028 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Message \n Flags=[B] \n Length=[ru] \n " ,
1032 if ( nbt_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1033 if ( nbt_len
> caplen
) {
1034 if ( nbt_len
> length
)
1035 ND_PRINT ( "WARNING: Packet is continued in later TCP segments \n " );
1037 ND_PRINT ( "WARNING: Short packet. Try increasing the snap length by %u \n " ,
1040 print_smb ( ndo
, data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
1042 ND_PRINT ( "Session packet:(raw data or continuation?) \n " );
1046 data
= smb_fdata ( ndo
, data
,
1047 "[P1]NBT Session Request \n Flags=[B] \n Length=[ru] \n Destination=[n1] \n Source=[n1] \n " ,
1052 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Granted \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1057 const u_char
* origdata
;
1061 data
= smb_fdata ( ndo
, data
, "[P1]NBT SessionReject \n Flags=[B] \n Length=[ru] \n Reason=[B] \n " ,
1065 if ( nbt_len
>= 1 && caplen
>= 1 ) {
1066 ecode
= GET_U_1 ( origdata
+ 4 );
1069 ND_PRINT ( "Not listening on called name \n " );
1072 ND_PRINT ( "Not listening for calling name \n " );
1075 ND_PRINT ( "Called name not present \n " );
1078 ND_PRINT ( "Called name present, but insufficient resources \n " );
1081 ND_PRINT ( "Unspecified error 0x%X \n " , ecode
);
1089 data
= smb_fdata ( ndo
, data
, "[P1]NBT Session Keepalive \n Flags=[B] \n Length=[ru] \n " , maxbuf
, 0 );
1093 data
= smb_fdata ( ndo
, data
, "NBT - Unknown packet type \n Type=[B] \n " , maxbuf
, 0 );
1100 nd_print_trunc ( ndo
);
1103 static const struct tok opcode_str
[] = {
1105 { 5 , "REGISTRATION" },
1108 { 8 , "REFRESH(8)" },
1110 { 15 , "MULTIHOMED REGISTRATION" },
1115 * print a NBT packet received across udp on port 137
1118 nbt_udp137_print ( netdissect_options
* ndo
,
1119 const u_char
* data
, u_int length
)
1121 const u_char
* maxbuf
= data
+ length
;
1122 u_int name_trn_id
, response
, opcode
, nm_flags
, rcode
;
1123 u_int qdcount
, ancount
, nscount
, arcount
;
1127 ndo
-> ndo_protocol
= "nbt_udp137" ;
1128 ND_TCHECK_2 ( data
+ 10 );
1129 name_trn_id
= GET_BE_U_2 ( data
);
1130 response
= ( GET_U_1 ( data
+ 2 ) >> 7 );
1131 opcode
= ( GET_U_1 ( data
+ 2 ) >> 3 ) & 0xF ;
1132 nm_flags
= (( GET_U_1 ( data
+ 2 ) & 0x7 ) << 4 ) + ( GET_U_1 ( data
+ 3 ) >> 4 );
1133 rcode
= GET_U_1 ( data
+ 3 ) & 0xF ;
1134 qdcount
= GET_BE_U_2 ( data
+ 4 );
1135 ancount
= GET_BE_U_2 ( data
+ 6 );
1136 nscount
= GET_BE_U_2 ( data
+ 8 );
1137 arcount
= GET_BE_U_2 ( data
+ 10 );
1143 if ( ndo
-> ndo_vflag
> 1 )
1146 ND_PRINT ( "NBT UDP PACKET(137): %s" , tok2str ( opcode_str
, "OPUNKNOWN" , opcode
));
1148 ND_PRINT ( "; %s" , rcode
? "NEGATIVE" : "POSITIVE" );
1150 ND_PRINT ( "; %s; %s" , response
? "RESPONSE" : "REQUEST" ,
1151 ( nm_flags
& 1 ) ? "BROADCAST" : "UNICAST" );
1153 if ( ndo
-> ndo_vflag
< 2 )
1156 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 " ,
1157 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
1162 total
= ancount
+ nscount
+ arcount
;
1164 if ( qdcount
> 100 || total
> 100 ) {
1165 ND_PRINT ( "Corrupt packet?? \n " );
1170 ND_PRINT ( "QuestionRecords: \n " );
1171 for ( i
= 0 ; i
< qdcount
; i
++) {
1172 p
= smb_fdata ( ndo
, p
,
1173 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
1181 ND_PRINT ( " \n ResourceRecords: \n " );
1182 for ( i
= 0 ; i
< total
; i
++) {
1186 p
= smb_fdata ( ndo
, p
, "Name=[n1] \n #" , maxbuf
, 0 );
1190 restype
= GET_BE_U_2 ( p
);
1191 p
= smb_fdata ( ndo
, p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rU] \n " , p
+ 8 , 0 );
1195 rdlen
= GET_BE_U_2 ( p
);
1196 ND_PRINT ( "ResourceLength=%u \n ResourceData= \n " , rdlen
);
1199 p
= smb_fdata ( ndo
, p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
, 0 );
1203 if ( restype
== 0x21 ) {
1207 numnames
= GET_U_1 ( p
);
1208 p
= smb_fdata ( ndo
, p
, "NumNames=[B] \n " , p
+ 1 , 0 );
1212 p
= smb_fdata ( ndo
, p
, "Name=[n2] \t #" , maxbuf
, 0 );
1218 if ( GET_U_1 ( p
) & 0x80 )
1219 ND_PRINT ( "<GROUP> " );
1220 switch ( GET_U_1 ( p
) & 0x60 ) {
1221 case 0x00 : ND_PRINT ( "B " ); break ;
1222 case 0x20 : ND_PRINT ( "P " ); break ;
1223 case 0x40 : ND_PRINT ( "M " ); break ;
1224 case 0x60 : ND_PRINT ( "_ " ); break ;
1226 if ( GET_U_1 ( p
) & 0x10 )
1227 ND_PRINT ( "<DEREGISTERING> " );
1228 if ( GET_U_1 ( p
) & 0x08 )
1229 ND_PRINT ( "<CONFLICT> " );
1230 if ( GET_U_1 ( p
) & 0x04 )
1231 ND_PRINT ( "<ACTIVE> " );
1232 if ( GET_U_1 ( p
) & 0x02 )
1233 ND_PRINT ( "<PERMANENT> " );
1241 smb_data_print ( ndo
, p
, min ( rdlen
, length
- ( p
- data
)));
1249 smb_fdata ( ndo
, p
, "AdditionalData: \n " , maxbuf
, 0 );
1255 nd_print_trunc ( ndo
);
1259 * Print an SMB-over-TCP packet received across tcp on port 445
1262 smb_tcp_print ( netdissect_options
* ndo
,
1263 const u_char
* data
, u_int length
)
1267 const u_char
* maxbuf
;
1269 ndo
-> ndo_protocol
= "smb_tcp" ;
1272 if ( ndo
-> ndo_snapend
< data
)
1274 caplen
= ndo
-> ndo_snapend
- data
;
1277 maxbuf
= data
+ caplen
;
1278 smb_len
= GET_BE_U_3 ( data
+ 1 );
1285 if ( smb_len
>= 4 && caplen
>= 4 && memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
1286 if ( smb_len
> caplen
) {
1287 if ( smb_len
> length
)
1288 ND_PRINT ( " WARNING: Packet is continued in later TCP segments \n " );
1290 ND_PRINT ( " WARNING: Short packet. Try increasing the snap length by %u \n " ,
1294 print_smb ( ndo
, data
, maxbuf
> data
+ smb_len
? data
+ smb_len
: maxbuf
);
1296 ND_PRINT ( " SMB-over-TCP packet:(raw data or continuation?) \n " );
1299 nd_print_trunc ( ndo
);
1303 * print a NBT packet received across udp on port 138
1306 nbt_udp138_print ( netdissect_options
* ndo
,
1307 const u_char
* data
, u_int length
)
1309 const u_char
* maxbuf
= data
+ length
;
1311 ndo
-> ndo_protocol
= "nbt_udp138" ;
1312 if ( maxbuf
> ndo
-> ndo_snapend
)
1313 maxbuf
= ndo
-> ndo_snapend
;
1318 if ( ndo
-> ndo_vflag
< 2 ) {
1319 ND_PRINT ( "NBT UDP PACKET(138)" );
1323 data
= smb_fdata ( ndo
, data
,
1324 " \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 #" ,
1328 /* If there isn't enough data for "\377SMB", don't check for it. */
1329 if (( data
+ 3 ) >= maxbuf
)
1332 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 )
1333 print_smb ( ndo
, data
, maxbuf
);
1341 print netbeui frames
1343 static struct nbf_strings
{
1345 const char * nonverbose
;
1346 const char * verbose
;
1347 } nbf_strings
[ 0x20 ] = {
1348 { "Add Group Name Query" , ", [P23]Name to add=[n2]#" ,
1349 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1350 { "Add Name Query" , ", [P23]Name to add=[n2]#" ,
1351 "[P5]ResponseCorrelator=[w] \n [P16]Name to add=[n2] \n " },
1352 { "Name In Conflict" , NULL
, NULL
},
1353 { "Status Query" , NULL
, NULL
},
1354 { NULL
, NULL
, NULL
}, /* not used */
1355 { NULL
, NULL
, NULL
}, /* not used */
1356 { NULL
, NULL
, NULL
}, /* not used */
1357 { "Terminate Trace" , NULL
, NULL
},
1359 "[P7]Destination=[n2] \n Source=[n2] \n " },
1360 { "Broadcast Datagram" , NULL
,
1361 "[P7]Destination=[n2] \n Source=[n2] \n " },
1362 { "Name Query" , ", [P7]Name=[n2]#" ,
1363 "[P1]SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Name=[n2] \n Name of sender=[n2] \n " },
1364 { NULL
, NULL
, NULL
}, /* not used */
1365 { NULL
, NULL
, NULL
}, /* not used */
1366 { "Add Name Response" , ", [P1]GroupName=[w] [P4]Destination=[n2] Source=[n2]#" ,
1367 "AddNameInProcess=[B] \n GroupName=[w] \n TransmitCorrelator=[w][P2] \n Destination=[n2] \n Source=[n2] \n " },
1368 { "Name Recognized" , NULL
,
1369 "[P1]Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " },
1370 { "Status Response" , NULL
, NULL
},
1371 { NULL
, NULL
, NULL
}, /* not used */
1372 { NULL
, NULL
, NULL
}, /* not used */
1373 { NULL
, NULL
, NULL
}, /* not used */
1374 { "Terminate Trace" , NULL
, NULL
},
1376 "[P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1377 { "Data First/Middle" , NULL
,
1378 "Flags=[{RECEIVE_CONTINUE|NO_ACK||PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1379 { "Data Only/Last" , NULL
,
1380 "Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1381 { "Session Confirm" , NULL
,
1382 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1383 { "Session End" , NULL
,
1384 "[P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1385 { "Session Initialize" , NULL
,
1386 "Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1387 { "No Receive" , NULL
,
1388 "Flags=[{|SEND_NO_ACK}] \n DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1389 { "Receive Outstanding" , NULL
,
1390 "[P1]DataBytesAccepted=[b][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1391 { "Receive Continue" , NULL
,
1392 "[P2]TransmitCorrelator=[w] \n [P2]RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " },
1393 { NULL
, NULL
, NULL
}, /* not used */
1394 { NULL
, NULL
, NULL
}, /* not used */
1395 { "Session Alive" , NULL
, NULL
}
1399 netbeui_print ( netdissect_options
* ndo
,
1400 u_short control
, const u_char
* data
, u_int length
)
1402 const u_char
* maxbuf
= data
+ length
;
1405 const u_char
* data2
;
1406 int is_truncated
= 0 ;
1408 ndo
-> ndo_protocol
= "netbeui" ;
1409 if ( maxbuf
> ndo
-> ndo_snapend
)
1410 maxbuf
= ndo
-> ndo_snapend
;
1411 ND_TCHECK_1 ( data
+ 4 );
1412 len
= GET_LE_U_2 ( data
);
1413 command
= GET_U_1 ( data
+ 4 );
1415 if ( data2
>= maxbuf
) {
1422 if ( ndo
-> ndo_vflag
< 2 ) {
1423 ND_PRINT ( "NBF Packet: " );
1424 data
= smb_fdata ( ndo
, data
, "[P5]#" , maxbuf
, 0 );
1426 ND_PRINT ( " \n >>> NBF Packet \n Type=0x%X " , control
);
1427 data
= smb_fdata ( ndo
, data
, "Length=[u] Signature=[w] Command=[B] \n #" , maxbuf
, 0 );
1432 if ( command
> 0x1f || nbf_strings
[ command
]. name
== NULL
) {
1433 if ( ndo
-> ndo_vflag
< 2 )
1434 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command#" , data2
, 0 );
1436 data
= smb_fdata ( ndo
, data
, "Unknown NBF Command \n " , data2
, 0 );
1438 if ( ndo
-> ndo_vflag
< 2 ) {
1439 ND_PRINT ( "%s" , nbf_strings
[ command
]. name
);
1440 if ( nbf_strings
[ command
]. nonverbose
!= NULL
)
1441 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. nonverbose
, data2
, 0 );
1443 ND_PRINT ( "%s: \n " , nbf_strings
[ command
]. name
);
1444 if ( nbf_strings
[ command
]. verbose
!= NULL
)
1445 data
= smb_fdata ( ndo
, data
, nbf_strings
[ command
]. verbose
, data2
, 0 );
1451 if ( ndo
-> ndo_vflag
< 2 )
1458 /* data2 was past the end of the buffer */
1462 /* If this isn't a command that would contain an SMB message, quit. */
1463 if ( command
!= 0x08 && command
!= 0x09 && command
!= 0x15 &&
1467 /* If there isn't enough data for "\377SMB", don't look for it. */
1468 if (( data2
+ 3 ) >= maxbuf
)
1471 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1472 print_smb ( ndo
, data2
, maxbuf
);
1475 for ( i
= 0 ; i
< 128 ; i
++) {
1476 if (( data2
+ i
+ 3 ) >= maxbuf
)
1478 if ( memcmp ( data2
+ i
, " \377 SMB" , 4 ) == 0 ) {
1479 ND_PRINT ( "found SMB packet at %u \n " , i
);
1480 print_smb ( ndo
, data2
+ i
, maxbuf
);
1490 nd_print_trunc ( ndo
);
1495 * print IPX-Netbios frames
1498 ipx_netbios_print ( netdissect_options
* ndo
,
1499 const u_char
* data
, u_int length
)
1502 * this is a hack till I work out how to parse the rest of the
1503 * NetBIOS-over-IPX stuff
1506 const u_char
* maxbuf
;
1508 ndo
-> ndo_protocol
= "ipx_netbios" ;
1509 maxbuf
= data
+ length
;
1510 /* Don't go past the end of the captured data in the packet. */
1511 if ( maxbuf
> ndo
-> ndo_snapend
)
1512 maxbuf
= ndo
-> ndo_snapend
;
1514 for ( i
= 0 ; i
< 128 ; i
++) {
1515 if (( data
+ i
+ 4 ) > maxbuf
)
1517 if ( memcmp ( data
+ i
, " \377 SMB" , 4 ) == 0 ) {
1518 smb_fdata ( ndo
, data
, " \n >>> IPX transport " , data
+ i
, 0 );
1519 print_smb ( ndo
, data
+ i
, maxbuf
);
1525 smb_fdata ( ndo
, data
, " \n >>> Unknown IPX " , maxbuf
, 0 );