]>
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
13 static const char rcsid
[] =
14 "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.11 2001-04-03 22:55:33 fenner Exp $" ;
19 #include <sys/types.h>
21 #include "interface.h"
26 const uchar
* startbuf
= NULL
;
34 void (* fn
)(); /* sometimes (u_char *, u_char *, u_char *, u_char *)
35 and sometimes (u_char *, u_char *, int, int) */
43 struct smbdescript descript
;
46 #define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL}
48 #define FLG_CHAIN (1<<0)
50 static struct smbfns
* smbfind ( int id
, struct smbfns
* list
)
54 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
55 if ( list
[ sindex
]. id
== id
) return (& list
[ sindex
]);
60 static void trans2_findfirst ( uchar
* param
, uchar
* data
, int pcnt
, int dcnt
)
65 fmt
= "Attribute=[A] \n SearchCount=[d] \n Flags=[w] \n Level=[dP5] \n File=[S] \n " ;
67 fmt
= "Handle=[w] \n Count=[d] \n EOS=[w] \n Eoffset=[d] \n LastNameOfs=[w] \n " ;
70 fdata ( param
, fmt
, param
+ pcnt
);
73 print_data ( data
, dcnt
);
77 static void trans2_qfsinfo ( uchar
* param
, uchar
* data
, int pcnt
, int dcnt
)
83 level
= SVAL ( param
, 0 );
84 fmt
= "InfoLevel=[d] \n " ;
85 fdata ( param
, fmt
, param
+ pcnt
);
89 fmt
= "idFileSystem=[W] \n SectorUnit=[D] \n Unit=[D] \n Avail=[D] \n SectorSize=[d] \n " ;
92 fmt
= "CreationTime=[T2]VolNameLength=[B] \n VolumeLabel=[s12] \n " ;
95 fmt
= "Capabilities=[W] \n MaxFileLen=[D] \n VolNameLen=[D] \n Volume=[S] \n " ;
98 fmt
= "UnknownLevel \n " ;
100 fdata ( data
, fmt
, data
+ dcnt
);
104 print_data ( data
, dcnt
);
108 struct smbfns trans2_fns
[] = {
109 { 0 , "TRANSACT2_OPEN" , 0 ,
110 { "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
,
111 "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
}},
113 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
114 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
116 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
118 { 3 , "TRANSACT2_QFSINFO" , 0 ,
119 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
121 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
122 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
123 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
124 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
125 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
126 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
127 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
128 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
129 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
130 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
131 {- 1 , NULL
, 0 , DEFDESCRIPT
}};
134 static void print_trans2 ( uchar
* words
, uchar
* dat
, uchar
* buf
, uchar
* maxbuf
)
136 static struct smbfns
* fn
= & trans2_fns
[ 0 ];
138 uchar
* f1
= NULL
,* f2
= NULL
;
142 fn
= smbfind ( SVAL ( words
+ 1 , 14 * 2 ), trans2_fns
);
143 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
144 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
145 pcnt
= SVAL ( words
+ 1 , 9 * 2 );
146 dcnt
= SVAL ( words
+ 1 , 11 * 2 );
148 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
149 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
150 pcnt
= SVAL ( words
+ 1 , 3 * 2 );
151 dcnt
= SVAL ( words
+ 1 , 6 * 2 );
154 printf ( "%s param_length=%d data_length=%d \n " ,
158 if ( CVAL ( words
, 0 ) == 8 ) {
159 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
);
162 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 );
163 fdata ( data
+ 1 , "TransactionName=[S] \n %" , maxbuf
);
165 f1
= fn
-> descript
. req_f1
;
166 f2
= fn
-> descript
. req_f2
;
168 if ( CVAL ( words
, 0 ) == 0 ) {
169 printf ( "Trans2Interim \n " );
172 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 );
174 f1
= fn
-> descript
. rep_f1
;
175 f2
= fn
-> descript
. rep_f2
;
178 if ( fn
-> descript
. fn
) {
179 fn
-> descript
. fn ( param
, data
, pcnt
, dcnt
);
181 fdata ( param
, f1
? f1
:( uchar
*) "Paramaters= \n " , param
+ pcnt
);
182 fdata ( data
, f2
? f2
:( uchar
*) "Data= \n " , data
+ dcnt
);
187 static void print_browse ( uchar
* param
, int paramlen
, const uchar
* data
, int datalen
)
189 const uchar
* maxbuf
= data
+ datalen
;
190 int command
= CVAL ( data
, 0 );
192 fdata ( param
, "BROWSE PACKET \n |Param " , param
+ paramlen
);
196 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
);
200 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
);
204 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " , maxbuf
);
208 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
);
212 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W,W)] \n ServerName=[S] \n " , maxbuf
);
216 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " , maxbuf
);
220 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token?=[B] \n " , maxbuf
);
224 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token?=[B]*Name=[S] \n " , maxbuf
);
228 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " , maxbuf
);
232 data
= fdata ( data
, "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
);
236 data
= fdata ( data
, "Unknown Browser Frame " , maxbuf
);
242 static void print_ipc ( uchar
* param
, int paramlen
, uchar
* data
, int datalen
)
245 fdata ( param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
);
247 fdata ( data
, "IPC " , data
+ datalen
);
251 static void print_trans ( uchar
* words
, uchar
* data1
, uchar
* buf
, uchar
* maxbuf
)
253 uchar
* f1
,* f2
,* f3
,* f4
;
255 int datalen
, paramlen
;
258 paramlen
= SVAL ( words
+ 1 , 9 * 2 );
259 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
260 datalen
= SVAL ( words
+ 1 , 11 * 2 );
261 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
262 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 " ;
267 paramlen
= SVAL ( words
+ 1 , 3 * 2 );
268 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
269 datalen
= SVAL ( words
+ 1 , 6 * 2 );
270 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
271 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 " ;
277 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + 2 * CVAL ( words
, 0 ), maxbuf
));
278 fdata ( data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
));
280 if (! strcmp ( data1
+ 2 , " \\ MAILSLOT \\ BROWSE" )) {
281 print_browse ( param
, paramlen
, data
, datalen
);
285 if (! strcmp ( data1
+ 2 , " \\ PIPE \\ LANMAN" )) {
286 print_ipc ( param
, paramlen
, data
, datalen
);
290 if ( paramlen
) fdata ( param
, f3
, MIN ( param
+ paramlen
, maxbuf
));
291 if ( datalen
) fdata ( data
, f4
, MIN ( data
+ datalen
, maxbuf
));
296 static void print_negprot ( uchar
* words
, uchar
* data
, uchar
* buf
, uchar
* maxbuf
)
298 uchar
* f1
= NULL
,* f2
= NULL
;
301 f2
= "*|Dialect=[Z] \n " ;
303 if ( CVAL ( words
, 0 ) == 1 ) {
304 f1
= "Core Protocol \n DialectIndex=[d]" ;
305 } else if ( CVAL ( words
, 0 ) == 17 ) {
306 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=" ;
307 } else if ( CVAL ( words
, 0 ) == 13 ) {
308 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=" ;
313 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
315 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
318 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
320 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
324 static void print_sesssetup ( uchar
* words
, uchar
* data
, uchar
* buf
, uchar
* maxbuf
)
326 int wcnt
= CVAL ( words
, 0 );
327 uchar
* f1
= NULL
,* f2
= NULL
;
331 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 " ;
333 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 " ;
336 if ( CVAL ( words
, 0 ) == 3 ) {
337 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
338 } else if ( CVAL ( words
, 0 ) == 13 ) {
339 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
340 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
345 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
347 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
350 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
352 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
356 static struct smbfns smb_fns
[] =
358 {- 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
360 { SMBtcon
, "SMBtcon" , 0 ,
361 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
362 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
366 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
367 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
368 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
370 { SMBecho
, "SMBecho" , 0 ,
371 { "ReverbCount=[d] \n " , NULL
,
372 "SequenceNum=[d] \n " , NULL
,
375 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
377 { SMBgetatr
, "SMBgetatr" , 0 ,
379 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
382 { SMBsetatr
, "SMBsetatr" , 0 ,
383 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
386 { SMBchkpth
, "SMBchkpth" , 0 ,
387 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
389 { SMBsearch
, "SMBsearch" , 0 ,
390 { "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 " ,
391 "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
}},
394 { SMBopen
, "SMBopen" , 0 ,
395 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
396 "Handle=[d] \n OAttrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n " , NULL
,
399 { SMBcreate
, "SMBcreate" , 0 ,
400 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
404 { SMBmknew
, "SMBmknew" , 0 ,
405 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
409 { SMBunlink
, "SMBunlink" , 0 ,
410 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
}},
412 { SMBread
, "SMBread" , 0 ,
413 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
414 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
416 { SMBwrite
, "SMBwrite" , 0 ,
417 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
418 "Count=[d] \n " , NULL
, NULL
}},
420 { SMBclose
, "SMBclose" , 0 ,
421 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
}},
423 { SMBmkdir
, "SMBmkdir" , 0 ,
424 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
426 { SMBrmdir
, "SMBrmdir" , 0 ,
427 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
429 { SMBdskattr
, "SMBdskattr" , 0 ,
431 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
435 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
}},
437 /* this is a Pathworks specific call, allowing the
438 changing of the root path */
439 { pSETDIR
, "SMBsetdir" , 0 ,
440 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
442 { SMBlseek
, "SMBlseek" , 0 ,
443 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
}},
445 { SMBflush
, "SMBflush" , 0 ,
446 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
448 { SMBsplopen
, "SMBsplopen" , 0 ,
449 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
}},
451 { SMBsplclose
, "SMBsplclose" , 0 ,
452 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
454 { SMBsplretq
, "SMBsplretq" , 0 ,
455 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
456 "Count=[d] \n Index=[d] \n " ,
457 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
460 { SMBsplwr
, "SMBsplwr" , 0 ,
461 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
463 { SMBlock
, "SMBlock" , 0 ,
464 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
466 { SMBunlock
, "SMBunlock" , 0 ,
467 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
469 /* CORE+ PROTOCOL FOLLOWS */
471 { SMBreadbraw
, "SMBreadbraw" , 0 ,
472 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
473 NULL
, NULL
, NULL
, NULL
}},
475 { SMBwritebraw
, "SMBwritebraw" , 0 ,
476 { "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 " ,
477 NULL
, "WriteRawAck" , NULL
, NULL
}},
479 { SMBwritec
, "SMBwritec" , 0 ,
480 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
}},
482 { SMBwriteclose
, "SMBwriteclose" , 0 ,
483 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" , NULL
,
484 "Count=[d] \n " , NULL
, NULL
}},
486 { SMBlockread
, "SMBlockread" , 0 ,
487 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
488 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
490 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
491 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
492 "Count=[d] \n " , NULL
, NULL
}},
494 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
495 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
497 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
500 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
501 { "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
,
502 "Remaining=[d] \n " , NULL
, NULL
}},
504 { SMBwriteBs
, "SMBwriteBs" , 0 ,
505 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
506 "Count=[d] \n " , NULL
, NULL
}},
508 { SMBsetattrE
, "SMBsetattrE" , 0 ,
509 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
512 { SMBgetattrE
, "SMBgetattrE" , 0 ,
513 { "Handle=[d] \n " , NULL
,
514 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " , NULL
, NULL
}},
516 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
517 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
519 { SMBcopy
, "SMBcopy" , 0 ,
520 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
521 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
523 { SMBmove
, "SMBmove" , 0 ,
524 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
525 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
527 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
528 { "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 " ,
529 "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
}},
531 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
532 { "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
,
533 "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
}},
535 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
536 { "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
,
537 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " , NULL
, NULL
}},
539 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
540 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ,
541 "*Process=[d] \n Offset=[D] \n Length=[D] \n " ,
542 "Com2=[w] \n Off2=[d] \n " }},
544 { SMBffirst
, "SMBffirst" , 0 ,
545 { "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 " ,
546 "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
}},
548 { SMBfunique
, "SMBfunique" , 0 ,
549 { "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 " ,
550 "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
}},
552 { SMBfclose
, "SMBfclose" , 0 ,
553 { "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 " ,
554 "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
}},
556 { SMBfindnclose
, "SMBfindnclose" , 0 ,
557 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
559 { SMBfindclose
, "SMBfindclose" , 0 ,
560 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
562 { SMBsends
, "SMBsends" , 0 ,
563 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
565 { SMBsendstrt
, "SMBsendstrt" , 0 ,
566 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
}},
568 { SMBsendend
, "SMBsendend" , 0 ,
569 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
571 { SMBsendtxt
, "SMBsendtxt" , 0 ,
572 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
574 { SMBsendb
, "SMBsendb" , 0 ,
575 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
577 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
578 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
579 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
581 { SMBnegprot
, "SMBnegprot" , 0 ,
582 { NULL
, NULL
, NULL
, NULL
, print_negprot
}},
584 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
585 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
}},
587 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
588 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " , NULL
,
589 "Com2=[w] \n Off2=[d] \n " , "ServiceType=[S] \n " , NULL
}},
591 { SMBtrans2
, "SMBtrans2" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans2
}},
593 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
594 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
595 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
596 { SMBtrans
, "SMBtrans" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans
}},
598 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
599 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
601 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
602 { "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 " ,
603 "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
}},
605 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
607 {- 1 , NULL
, 0 , DEFDESCRIPT
}};
610 /*******************************************************************
612 ********************************************************************/
613 static void print_smb ( const uchar
* buf
, const uchar
* maxbuf
)
616 const uchar
* words
, * data
;
618 char * fmt_smbheader
=
619 "[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 " ;
621 request
= ( CVAL ( buf
, 9 )& 0x80 )? 0 : 1 ;
623 command
= CVAL ( buf
, 4 );
625 fn
= smbfind ( command
, smb_fns
);
630 printf ( "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
635 /* print out the header */
636 fdata ( buf
, fmt_smbheader
, buf
+ 33 );
639 int class = CVAL ( buf
, 5 );
640 int num
= SVAL ( buf
, 7 );
641 printf ( "SMBError = %s \n " , smb_errstr ( class , num
));
645 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
648 while ( words
&& data
)
651 int wct
= CVAL ( words
, 0 );
654 f1
= fn
-> descript
. req_f1
;
655 f2
= fn
-> descript
. req_f2
;
657 f1
= fn
-> descript
. rep_f1
;
658 f2
= fn
-> descript
. rep_f2
;
661 if ( fn
-> descript
. fn
) {
662 fn
-> descript
. fn ( words
, data
, buf
, maxbuf
);
665 printf ( "smbvwv[]= \n " );
666 fdata ( words
+ 1 , f1
, words
+ 1 + wct
* 2 );
670 printf ( "smbvwv[]= \n " );
671 for ( i
= 0 ; i
< wct
; i
++) {
672 v
= SVAL ( words
+ 1 , 2 * i
);
673 printf ( "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
);
678 printf ( "smbbuf[]= \n " );
679 fdata ( data
+ 2 , f2
, maxbuf
);
681 int bcc
= SVAL ( data
, 0 );
682 printf ( "smb_bcc=%d \n " , bcc
);
684 printf ( "smb_buf[]= \n " );
685 print_data ( data
+ 2 , MIN ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
690 if (( fn
-> flags
& FLG_CHAIN
) && CVAL ( words
, 0 ) && SVAL ( words
, 1 )!= 0xFF ) {
691 command
= SVAL ( words
, 1 );
692 words
= buf
+ SVAL ( words
, 3 );
693 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
695 fn
= smbfind ( command
, smb_fns
);
697 printf ( " \n SMB PACKET: %s (%s) (CHAINED) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
708 print a NBT packet received across tcp on port 139
710 void nbt_tcp_print ( const uchar
* data
, int length
)
712 const uchar
* maxbuf
= data
+ length
;
713 int flags
= CVAL ( data
, 0 );
714 int nbt_len
= RSVAL ( data
, 2 );
717 if ( maxbuf
<= data
) return ;
722 printf ( "NBT Packet" );
731 printf ( "flags=0x%x \n " , flags
);
733 data
= fdata ( data
, "NBT Session Packet \n Flags=[rw] \n Length=[rd] \n " , data
+ 4 );
736 if ( memcmp ( data
, " \377 SMB" , 4 )== 0 ) {
737 if ( nbt_len
> PTR_DIFF ( maxbuf
, data
))
738 printf ( "WARNING: Short packet. Try increasing the snap length (%ld) \n " ,
739 PTR_DIFF ( maxbuf
, data
));
740 print_smb ( data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
742 printf ( "Session packet:(raw data?) \n " );
747 data
= fdata ( data
, "NBT Session Request \n Flags=[rW] \n Destination=[n1] \n Source=[n1] \n " , maxbuf
);
751 data
= fdata ( data
, "NBT Session Granted \n Flags=[rW] \n " , maxbuf
);
756 int ecode
= CVAL ( data
, 4 );
757 data
= fdata ( data
, "NBT SessionReject \n Flags=[rW] \n Reason=[B] \n " , maxbuf
);
760 printf ( "Not listening on called name \n " );
763 printf ( "Not listening for calling name \n " );
766 printf ( "Called name not present \n " );
769 printf ( "Called name present, but insufficient resources \n " );
772 printf ( "Unspecified error 0x%X \n " , ecode
);
779 data
= fdata ( data
, "NBT Session Keepalive \n Flags=[rW] \n " , maxbuf
);
783 printf ( "flags=0x%x \n " , flags
);
784 data
= fdata ( data
, "NBT - Unknown packet type \n Type=[rW] \n " , maxbuf
);
792 print a NBT packet received across udp on port 137
794 void nbt_udp137_print ( const uchar
* data
, int length
)
796 const uchar
* maxbuf
= data
+ length
;
797 int name_trn_id
= RSVAL ( data
, 0 );
798 int response
= ( CVAL ( data
, 2 )>> 7 );
799 int opcode
= ( CVAL ( data
, 2 ) >> 3 ) & 0xF ;
800 int nm_flags
= (( CVAL ( data
, 2 ) & 0x7 ) << 4 ) + ( CVAL ( data
, 3 )>> 4 );
801 int rcode
= CVAL ( data
, 3 ) & 0xF ;
802 int qdcount
= RSVAL ( data
, 4 );
803 int ancount
= RSVAL ( data
, 6 );
804 int nscount
= RSVAL ( data
, 8 );
805 int arcount
= RSVAL ( data
, 10 );
811 if ( maxbuf
<= data
) return ;
816 printf ( "NBT UDP PACKET(137): " );
819 case 0 : opcodestr
= "QUERY" ; break ;
820 case 5 : opcodestr
= "REGISTRATION" ; break ;
821 case 6 : opcodestr
= "RELEASE" ; break ;
822 case 7 : opcodestr
= "WACK" ; break ;
823 case 8 : opcodestr
= "REFRESH(8)" ; break ;
824 case 9 : opcodestr
= "REFRESH" ; break ;
825 default : opcodestr
= "OPUNKNOWN" ; break ;
827 printf ( "%s" , opcodestr
);
830 printf ( "; NEGATIVE" );
832 printf ( "; POSITIVE" );
836 printf ( "; RESPONSE" );
841 printf ( "; BROADCAST" );
848 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 " ,
849 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
, arcount
);
854 int total
= ancount
+ nscount
+ arcount
;
857 if ( qdcount
> 100 || total
> 100 ) {
858 printf ( "Corrupt packet?? \n " );
863 printf ( "QuestionRecords: \n " );
864 for ( i
= 0 ; i
< qdcount
; i
++)
865 p
= fdata ( p
, "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" , maxbuf
);
871 printf ( " \n ResourceRecords: \n " );
872 for ( i
= 0 ; i
< total
; i
++) {
875 p
= fdata ( p
, "Name=[n1] \n #" , maxbuf
);
878 restype
= RSVAL ( p
, 0 );
879 p
= fdata ( p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 );
883 printf ( "ResourceLength=%d \n ResourceData= \n " , rdlen
);
886 p
= fdata ( p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
);
890 if ( restype
== 0x21 ) {
891 int numnames
= CVAL ( p
, 0 );
892 p
= fdata ( p
, "NumNames=[B] \n " , p
+ 1 );
896 p
= fdata ( p
, "Name=[n2] \t #" , maxbuf
);
897 if ( p
[ 0 ] & 0x80 ) printf ( "<GROUP> " );
898 switch ( p
[ 0 ] & 0x60 ) {
899 case 0x00 : printf ( "B " ); break ;
900 case 0x20 : printf ( "P " ); break ;
901 case 0x40 : printf ( "M " ); break ;
902 case 0x60 : printf ( "_ " ); break ;
904 if ( p
[ 0 ] & 0x10 ) printf ( "<DEREGISTERING> " );
905 if ( p
[ 0 ] & 0x08 ) printf ( "<CONFLICT> " );
906 if ( p
[ 0 ] & 0x04 ) printf ( "<ACTIVE> " );
907 if ( p
[ 0 ] & 0x02 ) printf ( "<PERMANENT> " );
912 print_data ( p
, min ( rdlen
, length
- (( const uchar
*) p
- data
)));
920 if (( uchar
*) p
< maxbuf
) {
921 fdata ( p
, "AdditionalData: \n " , maxbuf
);
932 print a NBT packet received across udp on port 138
934 void nbt_udp138_print ( const uchar
* data
, int length
)
936 const uchar
* maxbuf
= data
+ length
;
938 if ( maxbuf
> snapend
) maxbuf
= snapend
;
939 if ( maxbuf
<= data
) return ;
943 printf ( "NBT UDP PACKET(138)" );
947 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
);
950 print_smb ( data
, maxbuf
);
961 void netbeui_print ( u_short control
, const uchar
* data
, int length
)
963 const uchar
* maxbuf
= data
+ length
;
967 int is_truncated
= 0 ;
969 if ( maxbuf
> snapend
)
971 if (& data
[ 7 ] >= maxbuf
)
974 command
= CVAL ( data
, 4 );
976 if ( data2
>= maxbuf
) {
984 printf ( "NetBeui Packet" );
988 printf ( " \n >>> NetBeui Packet \n Type=0x%X " , control
);
989 data
= fdata ( data
, "Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
);
995 data
= fdata ( data
, "NameQuery:[P1] \n SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
999 data
= fdata ( data
, "NetbiosDataGram:[P7] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1003 data
= fdata ( data
, "NameRecognise: \n [P1] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1007 data
= fdata ( data
, "SessionInitialise: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1011 data
= fdata ( data
, "SessionConfirm: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1015 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
);
1019 data
= fdata ( data
, "NetbiosDataAck: \n [P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1023 data
= fdata ( data
, "SessionEnd: \n [P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1027 data
= fdata ( data
, "SessionAlive \n " , data2
);
1031 data
= fdata ( data
, "Unknown Netbios Command " , data2
);
1038 /* data2 was past the end of the buffer */
1042 /* If there isn't enough data for "\377SMB", don't look for it. */
1043 if (& data2
[ 3 ] >= maxbuf
)
1046 if ( memcmp ( data2
, " \377 SMB" , 4 )== 0 ) {
1047 print_smb ( data2
, maxbuf
);
1050 for ( i
= 0 ; i
< 128 ; i
++) {
1051 if (& data2
[ i
+ 3 ] >= maxbuf
)
1053 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 )== 0 ) {
1054 printf ( "found SMB packet at %d \n " , i
);
1055 print_smb (& data2
[ i
], maxbuf
);
1067 print IPX-Netbios frames
1069 void ipx_netbios_print ( const uchar
* data
, u_int length
)
1071 /* this is a hack till I work out how to parse the rest of the
1072 NetBIOS-over-IPX stuff */
1074 const uchar
* maxbuf
;
1076 maxbuf
= data
+ length
;
1077 /* Don't go past the end of the captured data in the packet. */
1078 if ( maxbuf
> snapend
)
1081 for ( i
= 0 ; i
< 128 ; i
++) {
1082 if (& data
[ i
+ 3 ] >= maxbuf
)
1084 if ( memcmp (& data
[ i
], " \377 SMB" , 4 )== 0 ) {
1085 fdata ( data
, " \n >>> IPX transport " ,& data
[ i
]);
1087 print_smb (& data
[ i
], maxbuf
);
1094 fdata ( data
, " \n >>> Unknown IPX " , maxbuf
);