]>
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
14 #include <sys/types.h>
16 #include "interface.h"
21 const uchar
* startbuf
= NULL
;
29 void (* fn
)(); /* sometimes (u_char *, u_char *, u_char *, u_char *)
30 and sometimes (u_char *, u_char *, int, int) */
38 struct smbdescript descript
;
41 #define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL}
43 #define FLG_CHAIN (1<<0)
45 static struct smbfns
* smbfind ( int id
, struct smbfns
* list
)
49 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
50 if ( list
[ sindex
]. id
== id
) return (& list
[ sindex
]);
55 static void trans2_findfirst ( uchar
* param
, uchar
* data
, int pcnt
, int dcnt
)
60 fmt
= "Attribute=[A] \n SearchCount=[d] \n Flags=[w] \n Level=[dP5] \n File=[S] \n " ;
62 fmt
= "Handle=[w] \n Count=[d] \n EOS=[w] \n Eoffset=[d] \n LastNameOfs=[w] \n " ;
65 fdata ( param
, fmt
, param
+ pcnt
);
68 print_data ( data
, dcnt
);
72 static void trans2_qfsinfo ( uchar
* param
, uchar
* data
, int pcnt
, int dcnt
)
78 level
= SVAL ( param
, 0 );
79 fmt
= "InfoLevel=[d] \n " ;
80 fdata ( param
, fmt
, param
+ pcnt
);
84 fmt
= "idFileSystem=[W] \n SectorUnit=[D] \n Unit=[D] \n Avail=[D] \n SectorSize=[d] \n " ;
87 fmt
= "CreationTime=[T2]VolNameLength=[B] \n VolumeLabel=[s12] \n " ;
90 fmt
= "Capabilities=[W] \n MaxFileLen=[D] \n VolNameLen=[D] \n Volume=[S] \n " ;
93 fmt
= "UnknownLevel \n " ;
95 fdata ( data
, fmt
, data
+ dcnt
);
99 print_data ( data
, dcnt
);
103 struct smbfns trans2_fns
[] = {
104 { 0 , "TRANSACT2_OPEN" , 0 ,
105 { "Flags2=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2] \n OFun=[w] \n Size=[D] \n Res=([w,w,w,w,w]) \n Path=[S]" , NULL
,
106 "Handle=[d] \n Attrib=[A] \n Time=[T2] \n Size=[D] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n Inode=[W] \n OffErr=[d] \n |EALength=[d] \n " , NULL
, NULL
}},
108 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
109 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
111 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
113 { 3 , "TRANSACT2_QFSINFO" , 0 ,
114 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
116 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
117 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
118 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
119 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
120 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
121 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
122 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
123 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
124 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
125 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
126 {- 1 , NULL
, 0 , DEFDESCRIPT
}};
129 static void print_trans2 ( uchar
* words
, uchar
* dat
, uchar
* buf
, uchar
* maxbuf
)
131 static struct smbfns
* fn
= & trans2_fns
[ 0 ];
133 uchar
* f1
= NULL
,* f2
= NULL
;
137 fn
= smbfind ( SVAL ( words
+ 1 , 14 * 2 ), trans2_fns
);
138 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
139 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
140 pcnt
= SVAL ( words
+ 1 , 9 * 2 );
141 dcnt
= SVAL ( words
+ 1 , 11 * 2 );
143 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
144 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
145 pcnt
= SVAL ( words
+ 1 , 3 * 2 );
146 dcnt
= SVAL ( words
+ 1 , 6 * 2 );
149 printf ( "%s param_length=%d data_length=%d \n " ,
153 if ( CVAL ( words
, 0 ) == 8 ) {
154 fdata ( words
+ 1 , "Trans2Secondary \n TotParam=[d] \n TotData=[d] \n ParamCnt=[d] \n ParamOff=[d] \n ParamDisp=[d] \n DataCnt=[d] \n DataOff=[d] \n DataDisp=[d] \n Handle=[d] \n " , maxbuf
);
157 fdata ( words
+ 1 , "TotParam=[d] \n TotData=[d] \n MaxParam=[d] \n MaxData=[d] \n MaxSetup=[d] \n Flags=[w] \n TimeOut=[D] \n Res1=[w] \n ParamCnt=[d] \n ParamOff=[d] \n DataCnt=[d] \n DataOff=[d] \n SetupCnt=[d] \n " , words
+ 1 + 14 * 2 );
158 fdata ( data
+ 1 , "TransactionName=[S] \n %" , maxbuf
);
160 f1
= fn
-> descript
. req_f1
;
161 f2
= fn
-> descript
. req_f2
;
163 if ( CVAL ( words
, 0 ) == 0 ) {
164 printf ( "Trans2Interim \n " );
167 fdata ( words
+ 1 , "TotParam=[d] \n TotData=[d] \n Res1=[w] \n ParamCnt=[d] \n ParamOff=[d] \n ParamDisp[d] \n DataCnt=[d] \n DataOff=[d] \n DataDisp=[d] \n SetupCnt=[d] \n " , words
+ 1 + 10 * 2 );
169 f1
= fn
-> descript
. rep_f1
;
170 f2
= fn
-> descript
. rep_f2
;
173 if ( fn
-> descript
. fn
) {
174 fn
-> descript
. fn ( param
, data
, pcnt
, dcnt
);
176 fdata ( param
, f1
? f1
:( uchar
*) "Paramaters= \n " , param
+ pcnt
);
177 fdata ( data
, f2
? f2
:( uchar
*) "Data= \n " , data
+ dcnt
);
182 static void print_browse ( uchar
* param
, int paramlen
, const uchar
* data
, int datalen
)
184 const uchar
* maxbuf
= data
+ datalen
;
185 int command
= CVAL ( data
, 0 );
187 fdata ( param
, "BROWSE PACKET \n |Param " , param
+ paramlen
);
191 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (LocalMasterAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " , maxbuf
);
195 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (HostAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n ElectionVersion=[w] \n BrowserConstant=[w] \n " , maxbuf
);
199 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " , maxbuf
);
203 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (WorkgroupAnnouncement) \n UpdateCount=[w] \n Res1=[B] \n AnnounceInterval=[d] \n Name=[n2] \n MajorVersion=[B] \n MinorVersion=[B] \n ServerType=[W] \n CommentPointer=[W] \n ServerName=[S] \n " , maxbuf
);
207 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W,W)] \n ServerName=[S] \n " , maxbuf
);
211 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " , maxbuf
);
215 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token?=[B] \n " , maxbuf
);
219 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token?=[B]*Name=[S] \n " , maxbuf
);
223 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " , maxbuf
);
227 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
);
231 data
= fdata ( data
, "Unknown Browser Frame " , maxbuf
);
237 static void print_ipc ( uchar
* param
, int paramlen
, uchar
* data
, int datalen
)
240 fdata ( param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
);
242 fdata ( data
, "IPC " , data
+ datalen
);
246 static void print_trans ( uchar
* words
, uchar
* data1
, uchar
* buf
, uchar
* maxbuf
)
248 uchar
* f1
,* f2
,* f3
,* f4
;
250 int datalen
, paramlen
;
253 paramlen
= SVAL ( words
+ 1 , 9 * 2 );
254 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
255 datalen
= SVAL ( words
+ 1 , 11 * 2 );
256 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
257 f1
= "TotParamCnt=[d] \n TotDataCnt=[d] \n MaxParmCnt=[d] \n MaxDataCnt=[d] \n MaxSCnt=[d] \n TransFlags=[w] \n Res1=[w] \n Res2=[w] \n Res3=[w] \n ParamCnt=[d] \n ParamOff=[d] \n DataCnt=[d] \n DataOff=[d] \n SUCnt=[d] \n " ;
262 paramlen
= SVAL ( words
+ 1 , 3 * 2 );
263 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
264 datalen
= SVAL ( words
+ 1 , 6 * 2 );
265 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
266 f1
= "TotParamCnt=[d] \n TotDataCnt=[d] \n Res1=[d] \n ParamCnt=[d] \n ParamOff=[d] \n Res2=[d] \n DataCnt=[d] \n DataOff=[d] \n Res3=[d] \n Lsetup=[d] \n " ;
272 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + 2 * CVAL ( words
, 0 ), maxbuf
));
273 fdata ( data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
));
275 if (! strcmp ( data1
+ 2 , " \\ MAILSLOT \\ BROWSE" )) {
276 print_browse ( param
, paramlen
, data
, datalen
);
280 if (! strcmp ( data1
+ 2 , " \\ PIPE \\ LANMAN" )) {
281 print_ipc ( param
, paramlen
, data
, datalen
);
285 if ( paramlen
) fdata ( param
, f3
, MIN ( param
+ paramlen
, maxbuf
));
286 if ( datalen
) fdata ( data
, f4
, MIN ( data
+ datalen
, maxbuf
));
291 static void print_negprot ( uchar
* words
, uchar
* data
, uchar
* buf
, uchar
* maxbuf
)
293 uchar
* f1
= NULL
,* f2
= NULL
;
296 f2
= "*|Dialect=[Z] \n " ;
298 if ( CVAL ( words
, 0 ) == 1 ) {
299 f1
= "Core Protocol \n DialectIndex=[d]" ;
300 } else if ( CVAL ( words
, 0 ) == 17 ) {
301 f1
= "NT1 Protocol \n DialectIndex=[d] \n SecMode=[B] \n MaxMux=[d] \n NumVcs=[d] \n MaxBuffer=[D] \n RawSize=[D] \n SessionKey=[W] \n Capabilities=[W] \n ServerTime=[T3]TimeZone=[d] \n CryptKey=" ;
302 } else if ( CVAL ( words
, 0 ) == 13 ) {
303 f1
= "Coreplus/Lanman1/Lanman2 Protocol \n DialectIndex=[d] \n SecMode=[w] \n MaxXMit=[d] \n MaxMux=[d] \n MaxVcs=[d] \n BlkMode=[w] \n SessionKey=[W] \n ServerTime=[T1]TimeZone=[d] \n Res=[W] \n CryptKey=" ;
308 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
310 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
313 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
315 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
319 static void print_sesssetup ( uchar
* words
, uchar
* data
, uchar
* buf
, uchar
* maxbuf
)
321 int wcnt
= CVAL ( words
, 0 );
322 uchar
* f1
= NULL
,* f2
= NULL
;
326 f1
= "Com2=[w] \n Off2=[d] \n BufSize=[d] \n MpxMax=[d] \n VcNum=[d] \n SessionKey=[W] \n PassLen=[d] \n CryptLen=[d] \n CryptOff=[d] \n Pass&Name= \n " ;
328 f1
= "Com2=[B] \n Res1=[B] \n Off2=[d] \n MaxBuffer=[d] \n MaxMpx=[d] \n VcNumber=[d] \n SessionKey=[W] \n CaseInsensitivePasswordLength=[d] \n CaseSensitivePasswordLength=[d] \n Res=[W] \n Capabilities=[W] \n Pass1&Pass2&Account&Domain&OS&LanMan= \n " ;
331 if ( CVAL ( words
, 0 ) == 3 ) {
332 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
333 } else if ( CVAL ( words
, 0 ) == 13 ) {
334 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
335 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
340 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
342 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
345 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
347 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
351 static struct smbfns smb_fns
[] =
353 {- 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
355 { SMBtcon
, "SMBtcon" , 0 ,
356 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
357 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
361 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
362 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
363 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
365 { SMBecho
, "SMBecho" , 0 ,
366 { "ReverbCount=[d] \n " , NULL
,
367 "SequenceNum=[d] \n " , NULL
,
370 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
372 { SMBgetatr
, "SMBgetatr" , 0 ,
374 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
377 { SMBsetatr
, "SMBsetatr" , 0 ,
378 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
381 { SMBchkpth
, "SMBchkpth" , 0 ,
382 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
384 { SMBsearch
, "SMBsearch" , 0 ,
385 { "Count=[d] \n Attrib=[A] \n " , "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n " ,
386 "Count=[d] \n " , "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " , NULL
}},
389 { SMBopen
, "SMBopen" , 0 ,
390 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
391 "Handle=[d] \n OAttrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n " , NULL
,
394 { SMBcreate
, "SMBcreate" , 0 ,
395 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
399 { SMBmknew
, "SMBmknew" , 0 ,
400 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
404 { SMBunlink
, "SMBunlink" , 0 ,
405 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
}},
407 { SMBread
, "SMBread" , 0 ,
408 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
409 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
411 { SMBwrite
, "SMBwrite" , 0 ,
412 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
413 "Count=[d] \n " , NULL
, NULL
}},
415 { SMBclose
, "SMBclose" , 0 ,
416 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
}},
418 { SMBmkdir
, "SMBmkdir" , 0 ,
419 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
421 { SMBrmdir
, "SMBrmdir" , 0 ,
422 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
424 { SMBdskattr
, "SMBdskattr" , 0 ,
426 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
430 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
}},
432 /* this is a Pathworks specific call, allowing the
433 changing of the root path */
434 { pSETDIR
, "SMBsetdir" , 0 ,
435 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
437 { SMBlseek
, "SMBlseek" , 0 ,
438 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
}},
440 { SMBflush
, "SMBflush" , 0 ,
441 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
443 { SMBsplopen
, "SMBsplopen" , 0 ,
444 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
}},
446 { SMBsplclose
, "SMBsplclose" , 0 ,
447 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
449 { SMBsplretq
, "SMBsplretq" , 0 ,
450 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
451 "Count=[d] \n Index=[d] \n " ,
452 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
455 { SMBsplwr
, "SMBsplwr" , 0 ,
456 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
458 { SMBlock
, "SMBlock" , 0 ,
459 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
461 { SMBunlock
, "SMBunlock" , 0 ,
462 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
464 /* CORE+ PROTOCOL FOLLOWS */
466 { SMBreadbraw
, "SMBreadbraw" , 0 ,
467 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
468 NULL
, NULL
, NULL
, NULL
}},
470 { SMBwritebraw
, "SMBwritebraw" , 0 ,
471 { "Handle=[d] \n TotalCount=[d] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n |DataSize=[d] \n DataOff=[d] \n " ,
472 NULL
, "WriteRawAck" , NULL
, NULL
}},
474 { SMBwritec
, "SMBwritec" , 0 ,
475 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
}},
477 { SMBwriteclose
, "SMBwriteclose" , 0 ,
478 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" , NULL
,
479 "Count=[d] \n " , NULL
, NULL
}},
481 { SMBlockread
, "SMBlockread" , 0 ,
482 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
483 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
485 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
486 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
487 "Count=[d] \n " , NULL
, NULL
}},
489 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
490 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
492 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
495 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
496 { "Handle=[d] \n TotCount=[d] \n Res=[w] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n Res2=[W] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
497 "Remaining=[d] \n " , NULL
, NULL
}},
499 { SMBwriteBs
, "SMBwriteBs" , 0 ,
500 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
501 "Count=[d] \n " , NULL
, NULL
}},
503 { SMBsetattrE
, "SMBsetattrE" , 0 ,
504 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
507 { SMBgetattrE
, "SMBgetattrE" , 0 ,
508 { "Handle=[d] \n " , NULL
,
509 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " , NULL
, NULL
}},
511 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
512 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
514 { SMBcopy
, "SMBcopy" , 0 ,
515 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
516 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
518 { SMBmove
, "SMBmove" , 0 ,
519 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
520 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
522 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
523 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n Mode=[w] \n SearchAttrib=[A] \n Attrib=[A] \n Time=[T2]OFun=[w] \n Size=[D] \n TimeOut=[D] \n Res=[W] \n " , "Path=[S] \n " ,
524 "Com2=[w] \n Off2=[d] \n Handle=[d] \n Attrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n Type=[w] \n State=[w] \n Action=[w] \n FileID=[W] \n Res=[w] \n " , NULL
, NULL
}},
526 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
527 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n CountLeft=[d] \n " , NULL
,
528 "Com2=[w] \n Off2=[d] \n Remaining=[d] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
530 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
531 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n Offset=[D] \n TimeOut=[D] \n WMode=[w] \n CountLeft=[d] \n Res=[w] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
532 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " , NULL
, NULL
}},
534 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
535 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ,
536 "*Process=[d] \n Offset=[D] \n Length=[D] \n " ,
537 "Com2=[w] \n Off2=[d] \n " }},
539 { SMBffirst
, "SMBffirst" , 0 ,
540 { "Count=[d] \n Attrib=[A] \n " , "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
541 "Count=[d] \n " , "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " , NULL
}},
543 { SMBfunique
, "SMBfunique" , 0 ,
544 { "Count=[d] \n Attrib=[A] \n " , "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
545 "Count=[d] \n " , "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " , NULL
}},
547 { SMBfclose
, "SMBfclose" , 0 ,
548 { "Count=[d] \n Attrib=[A] \n " , "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
549 "Count=[d] \n " , "BlkType=[B] \n BlkLen=[d] \n * \n Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n Res2=[W] \n Attrib=[a] \n Time=[T1]Size=[D] \n Name=[s13] \n " , NULL
}},
551 { SMBfindnclose
, "SMBfindnclose" , 0 ,
552 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
554 { SMBfindclose
, "SMBfindclose" , 0 ,
555 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
557 { SMBsends
, "SMBsends" , 0 ,
558 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
560 { SMBsendstrt
, "SMBsendstrt" , 0 ,
561 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
}},
563 { SMBsendend
, "SMBsendend" , 0 ,
564 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
566 { SMBsendtxt
, "SMBsendtxt" , 0 ,
567 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
569 { SMBsendb
, "SMBsendb" , 0 ,
570 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
572 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
573 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
574 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
576 { SMBnegprot
, "SMBnegprot" , 0 ,
577 { NULL
, NULL
, NULL
, NULL
, print_negprot
}},
579 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
580 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
}},
582 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
583 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " , NULL
,
584 "Com2=[w] \n Off2=[d] \n " , "ServiceType=[S] \n " , NULL
}},
586 { SMBtrans2
, "SMBtrans2" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans2
}},
588 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
589 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
590 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
591 { SMBtrans
, "SMBtrans" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans
}},
593 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
594 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
596 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
597 { "Com2=[w] \n Off2=[d] \n Res=[b] \n NameLen=[d] \n Flags=[W] \n RootDirectoryFid=[D] \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 " , "Path=[S] \n " ,
598 "Com2=[w] \n Off2=[d] \n OplockLevel=[b] \n Fid=[d] \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 " , NULL
}},
600 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
602 {- 1 , NULL
, 0 , DEFDESCRIPT
}};
605 /*******************************************************************
607 ********************************************************************/
608 static void print_smb ( const uchar
* buf
, const uchar
* maxbuf
)
611 const uchar
* words
, * data
;
613 char * fmt_smbheader
=
614 "[P4]SMB Command = [B] \n Error class = [BP1] \n Error code = [d] \n Flags1 = [B] \n Flags2 = [B][P13] \n Tree ID = [d] \n Proc ID = [d] \n UID = [d] \n MID = [d] \n Word Count = [b] \n " ;
616 request
= ( CVAL ( buf
, 9 )& 0x80 )? 0 : 1 ;
618 command
= CVAL ( buf
, 4 );
620 fn
= smbfind ( command
, smb_fns
);
622 printf ( " \n SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
624 if ( vflag
== 0 ) return ;
626 /* print out the header */
627 fdata ( buf
, fmt_smbheader
, buf
+ 33 );
630 int class = CVAL ( buf
, 5 );
631 int num
= SVAL ( buf
, 7 );
632 printf ( "SMBError = %s \n " , smb_errstr ( class , num
));
636 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
639 while ( words
&& data
)
642 int wct
= CVAL ( words
, 0 );
645 f1
= fn
-> descript
. req_f1
;
646 f2
= fn
-> descript
. req_f2
;
648 f1
= fn
-> descript
. rep_f1
;
649 f2
= fn
-> descript
. rep_f2
;
652 if ( fn
-> descript
. fn
) {
653 fn
-> descript
. fn ( words
, data
, buf
, maxbuf
);
656 printf ( "smbvwv[]= \n " );
657 fdata ( words
+ 1 , f1
, words
+ 1 + wct
* 2 );
661 printf ( "smbvwv[]= \n " );
662 for ( i
= 0 ; i
< wct
; i
++) {
663 v
= SVAL ( words
+ 1 , 2 * i
);
664 printf ( "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
);
669 printf ( "smbbuf[]= \n " );
670 fdata ( data
+ 2 , f2
, maxbuf
);
672 int bcc
= SVAL ( data
, 0 );
673 printf ( "smb_bcc=%d \n " , bcc
);
675 printf ( "smb_buf[]= \n " );
676 print_data ( data
+ 2 , MIN ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
681 if (( fn
-> flags
& FLG_CHAIN
) && CVAL ( words
, 0 ) && SVAL ( words
, 1 )!= 0xFF ) {
682 command
= SVAL ( words
, 1 );
683 words
= buf
+ SVAL ( words
, 3 );
684 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
686 fn
= smbfind ( command
, smb_fns
);
688 printf ( " \n SMB PACKET: %s (%s) (CHAINED) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
699 print a NBT packet received across tcp on port 139
701 void nbt_tcp_print ( const uchar
* data
, int length
)
703 const uchar
* maxbuf
= data
+ length
;
704 int flags
= CVAL ( data
, 0 );
705 int nbt_len
= RSVAL ( data
, 2 );
708 if ( maxbuf
<= data
) return ;
710 printf ( " \n >>> NBT Packet \n " );
714 printf ( "flags=0x%x \n " , flags
);
716 data
= fdata ( data
, "NBT Session Packet \n Flags=[rw] \n Length=[rd] \n " , data
+ 4 );
717 if ( memcmp ( data
, " \377 SMB" , 4 )== 0 ) {
718 if ( nbt_len
> PTR_DIFF ( maxbuf
, data
))
719 printf ( "WARNING: Short packet. Try increasing the snap length (%ld) \n " ,
720 PTR_DIFF ( maxbuf
, data
));
721 print_smb ( data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
723 printf ( "Session packet:(raw data?) \n " );
728 data
= fdata ( data
, "NBT Session Request \n Flags=[rW] \n Destination=[n1] \n Source=[n1] \n " , maxbuf
);
732 data
= fdata ( data
, "NBT Session Granted \n Flags=[rW] \n " , maxbuf
);
737 int ecode
= CVAL ( data
, 4 );
738 data
= fdata ( data
, "NBT SessionReject \n Flags=[rW] \n Reason=[B] \n " , maxbuf
);
741 printf ( "Not listening on called name \n " );
744 printf ( "Not listening for calling name \n " );
747 printf ( "Called name not present \n " );
750 printf ( "Called name present, but insufficient resources \n " );
753 printf ( "Unspecified error 0x%X \n " , ecode
);
760 data
= fdata ( data
, "NBT Session Keepalive \n Flags=[rW] \n " , maxbuf
);
764 printf ( "flags=0x%x \n " , flags
);
765 data
= fdata ( data
, "NBT - Unknown packet type \n Type=[rW] \n " , maxbuf
);
773 print a NBT packet received across udp on port 137
775 void nbt_udp137_print ( const uchar
* data
, int length
)
777 const uchar
* maxbuf
= data
+ length
;
778 int name_trn_id
= RSVAL ( data
, 0 );
779 int response
= ( CVAL ( data
, 2 )>> 7 );
780 int opcode
= ( CVAL ( data
, 2 ) >> 3 ) & 0xF ;
781 int nm_flags
= (( CVAL ( data
, 2 ) & 0x7 ) << 4 ) + ( CVAL ( data
, 3 )>> 4 );
782 int rcode
= CVAL ( data
, 3 ) & 0xF ;
783 int qdcount
= RSVAL ( data
, 4 );
784 int ancount
= RSVAL ( data
, 6 );
785 int nscount
= RSVAL ( data
, 8 );
786 int arcount
= RSVAL ( data
, 10 );
788 char * opcodestr
= "OPUNKNOWN" ;
793 if ( maxbuf
<= data
) return ;
795 strcpy ( des
, " \n >>> NBT UDP PACKET(137): " );
798 case 0 : opcodestr
= "QUERY" ; break ;
799 case 5 : opcodestr
= "REGISTRATION" ; break ;
800 case 6 : opcodestr
= "RELEASE" ; break ;
801 case 7 : opcodestr
= "WACK" ; break ;
802 case 8 : opcodestr
= "REFRESH(8)" ; break ;
803 case 9 : opcodestr
= "REFRESH" ; break ;
805 strcat ( des
, opcodestr
);
808 strcat ( des
, "; NEGATIVE" );
810 strcat ( des
, "; POSITIVE" );
814 strcat ( des
, "; RESPONSE" );
816 strcat ( des
, "; REQUEST" );
819 strcat ( des
, "; BROADCAST" );
821 strcat ( des
, "; UNICAST" );
825 if ( vflag
== 0 ) return ;
827 printf ( " \n TrnID=0x%X \n OpCode=%d \n NmFlags=0x%X \n Rcode=%d \n QueryCount=%d \n AnswerCount=%d \n AuthorityCount=%d \n AddressRecCount=%d \n " ,
828 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
, arcount
);
833 int total
= ancount
+ nscount
+ arcount
;
836 if ( qdcount
> 100 || total
> 100 ) {
837 printf ( "Corrupt packet?? \n " );
842 printf ( "QuestionRecords: \n " );
843 for ( i
= 0 ; i
< qdcount
; i
++)
844 p
= fdata ( p
, "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" , maxbuf
);
848 printf ( " \n ResourceRecords: \n " );
849 for ( i
= 0 ; i
< total
; i
++) {
852 p
= fdata ( p
, "Name=[n1] \n #" , maxbuf
);
853 restype
= RSVAL ( p
, 0 );
854 p
= fdata ( p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 );
856 printf ( "ResourceLength=%d \n ResourceData= \n " , rdlen
);
859 p
= fdata ( p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
);
861 if ( restype
== 0x21 ) {
862 int numnames
= CVAL ( p
, 0 );
863 p
= fdata ( p
, "NumNames=[B] \n " , p
+ 1 );
866 p
= fdata ( p
, "Name=[n2] \t #" , maxbuf
);
867 if ( p
[ 0 ] & 0x80 ) strcat ( flags
, "<GROUP> " );
868 if (( p
[ 0 ] & 0x60 ) == 0x00 ) strcat ( flags
, "B " );
869 if (( p
[ 0 ] & 0x60 ) == 0x20 ) strcat ( flags
, "P " );
870 if (( p
[ 0 ] & 0x60 ) == 0x40 ) strcat ( flags
, "M " );
871 if (( p
[ 0 ] & 0x60 ) == 0x60 ) strcat ( flags
, "_ " );
872 if ( p
[ 0 ] & 0x10 ) strcat ( flags
, "<DEREGISTERING> " );
873 if ( p
[ 0 ] & 0x08 ) strcat ( flags
, "<CONFLICT> " );
874 if ( p
[ 0 ] & 0x04 ) strcat ( flags
, "<ACTIVE> " );
875 if ( p
[ 0 ] & 0x02 ) strcat ( flags
, "<PERMANENT> " );
876 printf ( "%s \n " , flags
);
888 if (( uchar
*) p
< maxbuf
) {
889 fdata ( p
, "AdditionalData: \n " , maxbuf
);
899 print a NBT packet received across udp on port 138
901 void nbt_udp138_print ( const uchar
* data
, int length
)
903 const uchar
* maxbuf
= data
+ length
;
905 if ( maxbuf
<= data
) return ;
907 data
= fdata ( data
, " \n >>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw] \n SourceName=[n1] \n DestName=[n1] \n #" , maxbuf
);
909 print_smb ( data
, maxbuf
);
920 void netbeui_print ( const uchar
* data
, const uchar
* maxbuf
)
922 int len
= SVAL ( data
, 1 );
923 int command
= CVAL ( data
, 5 );
924 const uchar
* data2
= data
+ 1 + len
;
928 data
= fdata ( data
, " \n >>> NetBeui Packet \n Type=[B] Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
);
932 data
= fdata ( data
, "NameQuery:[P1] \n SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
936 data
= fdata ( data
, "NetbiosDataGram:[P7] \n Destination=[n2] \n Source=[n2] \n " , data2
);
940 data
= fdata ( data
, "NameRecognise: \n [P1] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
944 data
= fdata ( data
, "SessionInitialise: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
948 data
= fdata ( data
, "SessionConfirm: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
952 data
= fdata ( data
, "NetbiosDataOnlyLast: \n Flags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}] \n ResyncIndicator=[w][P2] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
956 data
= fdata ( data
, "NetbiosDataAck: \n [P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
960 data
= fdata ( data
, "SessionEnd: \n [P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
964 data
= fdata ( data
, "Unknown Netbios Command " , data2
);
968 if ( memcmp ( data2
, " \377 SMB" , 4 )== 0 ) {
969 print_smb ( data2
, maxbuf
);
972 for ( i
= 0 ; i
< 128 ; i
++) {
973 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 )== 0 ) {
974 printf ( "found SMB packet at %d \n " , i
);
975 print_smb (& data2
[ i
], maxbuf
);
986 print IPX-Netbios frames
988 void ipx_netbios_print ( const uchar
* data
, const uchar
* maxbuf
)
990 /* this is a hack till I work out how to parse the rest of the IPX stuff */
994 if ( memcmp (& data
[ i
], " \377 SMB" , 4 )== 0 ) {
995 fdata ( data
, " \n >>> IPX transport " ,& data
[ i
]);
996 print_smb (& data
[ i
], maxbuf
);
1002 fdata ( data
, " \n >>> Unknown IPX " , maxbuf
);