]>
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 static const char rcsid
[] =
15 "@(#) $Header: /tcpdump/master/tcpdump/print-smb.c,v 1.13 2001-06-25 18:58:07 itojun Exp $" ;
20 #include <sys/types.h>
22 #include "interface.h"
25 static int request
= 0 ;
27 const uchar
* startbuf
= NULL
;
35 * sometimes (u_char *, u_char *, u_char *, u_char *) and
36 * sometimes (u_char *, u_char *, int, int)
38 void (* fn
)( const u_char
*, const u_char
*, ...);
46 struct smbdescript descript
;
49 #define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL}
51 #define FLG_CHAIN (1<<0)
53 static struct smbfns
*
54 smbfind ( int id
, struct smbfns
* list
)
58 for ( sindex
= 0 ; list
[ sindex
]. name
; sindex
++)
59 if ( list
[ sindex
]. id
== id
)
60 return (& list
[ sindex
]);
66 trans2_findfirst ( const uchar
* param
, const uchar
* data
, ...)
73 pcnt
= va_arg ( ap
, int );
74 dcnt
= va_arg ( ap
, int );
78 fmt
= "Attribute=[A] \n SearchCount=[d] \n Flags=[w] \n Level=[dP5] \n File=[S] \n " ;
80 fmt
= "Handle=[w] \n Count=[d] \n EOS=[w] \n Eoffset=[d] \n LastNameOfs=[w] \n " ;
82 fdata ( param
, fmt
, param
+ pcnt
);
85 print_data ( data
, dcnt
);
90 trans2_qfsinfo ( const uchar
* param
, const uchar
* data
, ...)
98 pcnt
= va_arg ( ap
, int );
99 dcnt
= va_arg ( ap
, int );
103 level
= SVAL ( param
, 0 );
104 fmt
= "InfoLevel=[d] \n " ;
105 fdata ( param
, fmt
, param
+ pcnt
);
109 fmt
= "idFileSystem=[W] \n SectorUnit=[D] \n Unit=[D] \n Avail=[D] \n SectorSize=[d] \n " ;
112 fmt
= "CreationTime=[T2]VolNameLength=[B] \n VolumeLabel=[s12] \n " ;
115 fmt
= "Capabilities=[W] \n MaxFileLen=[D] \n VolNameLen=[D] \n Volume=[S] \n " ;
118 fmt
= "UnknownLevel \n " ;
121 fdata ( data
, fmt
, data
+ dcnt
);
125 print_data ( data
, dcnt
);
129 struct smbfns trans2_fns
[] = {
130 { 0 , "TRANSACT2_OPEN" , 0 ,
131 { "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]" ,
133 "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 " ,
135 { 1 , "TRANSACT2_FINDFIRST" , 0 ,
136 { NULL
, NULL
, NULL
, NULL
, trans2_findfirst
}},
137 { 2 , "TRANSACT2_FINDNEXT" , 0 , DEFDESCRIPT
},
138 { 3 , "TRANSACT2_QFSINFO" , 0 ,
139 { NULL
, NULL
, NULL
, NULL
, trans2_qfsinfo
}},
140 { 4 , "TRANSACT2_SETFSINFO" , 0 , DEFDESCRIPT
},
141 { 5 , "TRANSACT2_QPATHINFO" , 0 , DEFDESCRIPT
},
142 { 6 , "TRANSACT2_SETPATHINFO" , 0 , DEFDESCRIPT
},
143 { 7 , "TRANSACT2_QFILEINFO" , 0 , DEFDESCRIPT
},
144 { 8 , "TRANSACT2_SETFILEINFO" , 0 , DEFDESCRIPT
},
145 { 9 , "TRANSACT2_FSCTL" , 0 , DEFDESCRIPT
},
146 { 10 , "TRANSACT2_IOCTL" , 0 , DEFDESCRIPT
},
147 { 11 , "TRANSACT2_FINDNOTIFYFIRST" , 0 , DEFDESCRIPT
},
148 { 12 , "TRANSACT2_FINDNOTIFYNEXT" , 0 , DEFDESCRIPT
},
149 { 13 , "TRANSACT2_MKDIR" , 0 , DEFDESCRIPT
},
150 { - 1 , NULL
, 0 , DEFDESCRIPT
}
155 print_trans2 ( const uchar
* words
, const uchar
* dat
, ...)
157 static struct smbfns
* fn
= & trans2_fns
[ 0 ];
159 uchar
* f1
= NULL
, * f2
= NULL
;
165 buf
= va_arg ( ap
, uchar
*);
166 maxbuf
= va_arg ( ap
, uchar
*);
170 fn
= smbfind ( SVAL ( words
+ 1 , 14 * 2 ), trans2_fns
);
171 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
172 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
173 pcnt
= SVAL ( words
+ 1 , 9 * 2 );
174 dcnt
= SVAL ( words
+ 1 , 11 * 2 );
176 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
177 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
178 pcnt
= SVAL ( words
+ 1 , 3 * 2 );
179 dcnt
= SVAL ( words
+ 1 , 6 * 2 );
182 printf ( "%s param_length=%d data_length=%d \n " , fn
-> name
, pcnt
, dcnt
);
185 if ( CVAL ( words
, 0 ) == 8 ) {
187 "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 " ,
192 "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 " ,
194 fdata ( data
+ 1 , "TransactionName=[S] \n %" , maxbuf
);
196 f1
= fn
-> descript
. req_f1
;
197 f2
= fn
-> descript
. req_f2
;
199 if ( CVAL ( words
, 0 ) == 0 ) {
200 printf ( "Trans2Interim \n " );
204 "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 " ,
207 f1
= fn
-> descript
. rep_f1
;
208 f2
= fn
-> descript
. rep_f2
;
212 fn
-> descript
. fn ( param
, data
, pcnt
, dcnt
);
214 fdata ( param
, f1
? f1
: ( uchar
*) "Paramaters= \n " , param
+ pcnt
);
215 fdata ( data
, f2
? f2
: ( uchar
*) "Data= \n " , data
+ dcnt
);
221 print_browse ( uchar
* param
, int paramlen
, const uchar
* data
, int datalen
)
223 const uchar
* maxbuf
= data
+ datalen
;
224 int command
= CVAL ( data
, 0 );
226 fdata ( param
, "BROWSE PACKET \n |Param " , param
+ paramlen
);
231 "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 " ,
237 "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 " ,
243 "BROWSE PACKET: \n Type=[B] (AnnouncementRequest) \n Flags=[B] \n ReplySystemName=[S] \n " ,
249 "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 " ,
255 "BROWSE PACKET: \n Type=[B] (ElectionFrame) \n ElectionVersion=[B] \n OSSummary=[W] \n Uptime=[(W, W)] \n ServerName=[S] \n " ,
261 "BROWSE PACKET: \n Type=[B] (BecomeBackupBrowser) \n Name=[S] \n " ,
267 "BROWSE PACKET: \n Type=[B] (GetBackupList) \n ListCount?=[B] \n Token?=[B] \n " ,
273 "BROWSE PACKET: \n Type=[B] (BackupListResponse) \n ServerCount?=[B] \n Token?=[B]*Name=[S] \n " ,
279 "BROWSE PACKET: \n Type=[B] (MasterAnnouncement) \n MasterName=[S] \n " ,
285 "BROWSE PACKET: \n Type=[B] (ResetBrowser) \n Options=[B] \n " , maxbuf
);
289 data
= fdata ( data
, "Unknown Browser Frame " , maxbuf
);
296 print_ipc ( uchar
* param
, int paramlen
, uchar
* data
, int datalen
)
299 fdata ( param
, "Command=[w] \n Str1=[S] \n Str2=[S] \n " , param
+ paramlen
);
301 fdata ( data
, "IPC " , data
+ datalen
);
306 print_trans ( const uchar
* words
, const uchar
* data1
, ...)
308 uchar
* f1
,* f2
,* f3
,* f4
;
310 int datalen
, paramlen
;
315 buf
= va_arg ( ap
, uchar
*);
316 maxbuf
= va_arg ( ap
, uchar
*);
320 paramlen
= SVAL ( words
+ 1 , 9 * 2 );
321 param
= buf
+ SVAL ( words
+ 1 , 10 * 2 );
322 datalen
= SVAL ( words
+ 1 , 11 * 2 );
323 data
= buf
+ SVAL ( words
+ 1 , 12 * 2 );
324 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 " ;
329 paramlen
= SVAL ( words
+ 1 , 3 * 2 );
330 param
= buf
+ SVAL ( words
+ 1 , 4 * 2 );
331 datalen
= SVAL ( words
+ 1 , 6 * 2 );
332 data
= buf
+ SVAL ( words
+ 1 , 7 * 2 );
333 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 " ;
339 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + 2 * CVAL ( words
, 0 ), maxbuf
));
340 fdata ( data1
+ 2 , f2
, maxbuf
- ( paramlen
+ datalen
));
342 if (! strcmp ( data1
+ 2 , " \\ MAILSLOT \\ BROWSE" )) {
343 print_browse ( param
, paramlen
, data
, datalen
);
347 if (! strcmp ( data1
+ 2 , " \\ PIPE \\ LANMAN" )) {
348 print_ipc ( param
, paramlen
, data
, datalen
);
352 if ( paramlen
) fdata ( param
, f3
, MIN ( param
+ paramlen
, maxbuf
));
353 if ( datalen
) fdata ( data
, f4
, MIN ( data
+ datalen
, maxbuf
));
359 print_negprot ( const uchar
* words
, const uchar
* data
, ...)
361 uchar
* f1
= NULL
,* f2
= NULL
;
366 buf
= va_arg ( ap
, uchar
*);
367 maxbuf
= va_arg ( ap
, uchar
*);
371 f2
= "*|Dialect=[Z] \n " ;
373 if ( CVAL ( words
, 0 ) == 1 ) {
374 f1
= "Core Protocol \n DialectIndex=[d]" ;
375 } else if ( CVAL ( words
, 0 ) == 17 ) {
376 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=" ;
377 } else if ( CVAL ( words
, 0 ) == 13 ) {
378 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=" ;
383 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
385 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
388 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
390 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
395 print_sesssetup ( const uchar
* words
, const uchar
* data
, ...)
397 int wcnt
= CVAL ( words
, 0 );
398 uchar
* f1
= NULL
,* f2
= NULL
;
403 buf
= va_arg ( ap
, uchar
*);
404 maxbuf
= va_arg ( ap
, uchar
*);
409 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 " ;
411 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 " ;
414 if ( CVAL ( words
, 0 ) == 3 ) {
415 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
416 } else if ( CVAL ( words
, 0 ) == 13 ) {
417 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
418 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
423 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 )* 2 , maxbuf
));
425 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 )* 2 , PTR_DIFF ( maxbuf
, words
+ 1 )));
428 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
430 print_data ( data
+ 2 , MIN ( SVAL ( data
, 0 ), PTR_DIFF ( maxbuf
, data
+ 2 )));
434 static struct smbfns smb_fns
[] =
436 {- 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
438 { SMBtcon
, "SMBtcon" , 0 ,
439 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
440 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
444 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
445 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
446 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
448 { SMBecho
, "SMBecho" , 0 ,
449 { "ReverbCount=[d] \n " , NULL
,
450 "SequenceNum=[d] \n " , NULL
,
453 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
455 { SMBgetatr
, "SMBgetatr" , 0 ,
457 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
460 { SMBsetatr
, "SMBsetatr" , 0 ,
461 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
464 { SMBchkpth
, "SMBchkpth" , 0 ,
465 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
467 { SMBsearch
, "SMBsearch" , 0 ,
468 { "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 " ,
469 "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
}},
472 { SMBopen
, "SMBopen" , 0 ,
473 { "Mode=[w] \n Attribute=[A] \n " , "Path=[Z] \n " ,
474 "Handle=[d] \n OAttrib=[A] \n Time=[T2]Size=[D] \n Access=[w] \n " , NULL
,
477 { SMBcreate
, "SMBcreate" , 0 ,
478 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
482 { SMBmknew
, "SMBmknew" , 0 ,
483 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " ,
487 { SMBunlink
, "SMBunlink" , 0 ,
488 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
}},
490 { SMBread
, "SMBread" , 0 ,
491 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
492 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
494 { SMBwrite
, "SMBwrite" , 0 ,
495 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
496 "Count=[d] \n " , NULL
, NULL
}},
498 { SMBclose
, "SMBclose" , 0 ,
499 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
}},
501 { SMBmkdir
, "SMBmkdir" , 0 ,
502 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
504 { SMBrmdir
, "SMBrmdir" , 0 ,
505 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
507 { SMBdskattr
, "SMBdskattr" , 0 ,
509 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
513 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
}},
515 /* this is a Pathworks specific call, allowing the
516 changing of the root path */
517 { pSETDIR
, "SMBsetdir" , 0 ,
518 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
}},
520 { SMBlseek
, "SMBlseek" , 0 ,
521 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
}},
523 { SMBflush
, "SMBflush" , 0 ,
524 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
526 { SMBsplopen
, "SMBsplopen" , 0 ,
527 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
}},
529 { SMBsplclose
, "SMBsplclose" , 0 ,
530 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
532 { SMBsplretq
, "SMBsplretq" , 0 ,
533 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
534 "Count=[d] \n Index=[d] \n " ,
535 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
538 { SMBsplwr
, "SMBsplwr" , 0 ,
539 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
541 { SMBlock
, "SMBlock" , 0 ,
542 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
544 { SMBunlock
, "SMBunlock" , 0 ,
545 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
}},
547 /* CORE+ PROTOCOL FOLLOWS */
549 { SMBreadbraw
, "SMBreadbraw" , 0 ,
550 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
551 NULL
, NULL
, NULL
, NULL
}},
553 { SMBwritebraw
, "SMBwritebraw" , 0 ,
554 { "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 " ,
555 NULL
, "WriteRawAck" , NULL
, NULL
}},
557 { SMBwritec
, "SMBwritec" , 0 ,
558 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
}},
560 { SMBwriteclose
, "SMBwriteclose" , 0 ,
561 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" , NULL
,
562 "Count=[d] \n " , NULL
, NULL
}},
564 { SMBlockread
, "SMBlockread" , 0 ,
565 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
566 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
}},
568 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
569 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
570 "Count=[d] \n " , NULL
, NULL
}},
572 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
573 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
575 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
578 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
579 { "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
,
580 "Remaining=[d] \n " , NULL
, NULL
}},
582 { SMBwriteBs
, "SMBwriteBs" , 0 ,
583 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " , NULL
,
584 "Count=[d] \n " , NULL
, NULL
}},
586 { SMBsetattrE
, "SMBsetattrE" , 0 ,
587 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
590 { SMBgetattrE
, "SMBgetattrE" , 0 ,
591 { "Handle=[d] \n " , NULL
,
592 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " , NULL
, NULL
}},
594 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
595 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
597 { SMBcopy
, "SMBcopy" , 0 ,
598 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
599 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
601 { SMBmove
, "SMBmove" , 0 ,
602 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
603 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
}},
605 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
606 { "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 " ,
607 "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
}},
609 { SMBreadX
, "SMBreadX" , FLG_CHAIN
,
610 { "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
,
611 "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
}},
613 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
614 { "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
,
615 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " , NULL
, NULL
}},
617 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
618 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ,
619 "*Process=[d] \n Offset=[D] \n Length=[D] \n " ,
620 "Com2=[w] \n Off2=[d] \n " }},
622 { SMBffirst
, "SMBffirst" , 0 ,
623 { "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 " ,
624 "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
}},
626 { SMBfunique
, "SMBfunique" , 0 ,
627 { "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 " ,
628 "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
}},
630 { SMBfclose
, "SMBfclose" , 0 ,
631 { "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 " ,
632 "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
}},
634 { SMBfindnclose
, "SMBfindnclose" , 0 ,
635 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
637 { SMBfindclose
, "SMBfindclose" , 0 ,
638 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
640 { SMBsends
, "SMBsends" , 0 ,
641 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
643 { SMBsendstrt
, "SMBsendstrt" , 0 ,
644 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
}},
646 { SMBsendend
, "SMBsendend" , 0 ,
647 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
649 { SMBsendtxt
, "SMBsendtxt" , 0 ,
650 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
}},
652 { SMBsendb
, "SMBsendb" , 0 ,
653 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
}},
655 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
656 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
657 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
659 { SMBnegprot
, "SMBnegprot" , 0 ,
660 { NULL
, NULL
, NULL
, NULL
, print_negprot
}},
662 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
663 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
}},
665 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
666 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " , NULL
,
667 "Com2=[w] \n Off2=[d] \n " , "ServiceType=[S] \n " , NULL
}},
669 { SMBtrans2
, "SMBtrans2" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans2
}},
671 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
672 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
673 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
674 { SMBtrans
, "SMBtrans" , 0 ,{ NULL
, NULL
, NULL
, NULL
, print_trans
}},
676 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
677 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
679 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
680 { "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 " ,
681 "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
}},
683 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
685 {- 1 , NULL
, 0 , DEFDESCRIPT
}};
689 * print a SMB message
692 print_smb ( const uchar
* buf
, const uchar
* maxbuf
)
695 const uchar
* words
, * data
;
697 char * fmt_smbheader
=
698 "[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 " ;
700 request
= ( CVAL ( buf
, 9 ) & 0x80 ) ? 0 : 1 ;
702 command
= CVAL ( buf
, 4 );
704 fn
= smbfind ( command
, smb_fns
);
709 printf ( "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
714 /* print out the header */
715 fdata ( buf
, fmt_smbheader
, buf
+ 33 );
718 int class = CVAL ( buf
, 5 );
719 int num
= SVAL ( buf
, 7 );
720 printf ( "SMBError = %s \n " , smb_errstr ( class , num
));
724 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
726 while ( words
&& data
) {
728 int wct
= CVAL ( words
, 0 );
731 f1
= fn
-> descript
. req_f1
;
732 f2
= fn
-> descript
. req_f2
;
734 f1
= fn
-> descript
. rep_f1
;
735 f2
= fn
-> descript
. rep_f2
;
739 fn
-> descript
. fn ( words
, data
, buf
, maxbuf
);
742 printf ( "smbvwv[]= \n " );
743 fdata ( words
+ 1 , f1
, words
+ 1 + wct
* 2 );
747 printf ( "smbvwv[]= \n " );
748 for ( i
= 0 ; i
< wct
; i
++) {
749 v
= SVAL ( words
+ 1 , 2 * i
);
750 printf ( "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
);
755 printf ( "smbbuf[]= \n " );
756 fdata ( data
+ 2 , f2
, maxbuf
);
758 int bcc
= SVAL ( data
, 0 );
759 printf ( "smb_bcc=%d \n " , bcc
);
761 printf ( "smb_buf[]= \n " );
762 print_data ( data
+ 2 , MIN ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
767 if (( fn
-> flags
& FLG_CHAIN
) != 0 && CVAL ( words
, 0 ) &&
768 SVAL ( words
, 1 ) != 0xFF ) {
769 command
= SVAL ( words
, 1 );
770 words
= buf
+ SVAL ( words
, 3 );
771 data
= words
+ 1 + CVAL ( words
, 0 ) * 2 ;
773 fn
= smbfind ( command
, smb_fns
);
775 printf ( " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
776 fn
-> name
, request
? "REQUEST" : "REPLY" );
786 * print a NBT packet received across tcp on port 139
789 nbt_tcp_print ( const uchar
* data
, int length
)
791 const uchar
* maxbuf
= data
+ length
;
792 int flags
= CVAL ( data
, 0 );
793 int nbt_len
= RSVAL ( data
, 2 );
802 printf ( "NBT Packet" );
811 printf ( "flags=0x%x \n " , flags
);
813 data
= fdata ( data
, "NBT Session Packet \n Flags=[rw] \n Length=[rd] \n " ,
817 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
818 if ( nbt_len
> PTR_DIFF ( maxbuf
, data
))
819 printf ( "WARNING: Short packet. Try increasing the snap length (%lu) \n " ,
820 ( unsigned long ) PTR_DIFF ( maxbuf
, data
));
821 print_smb ( data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
823 printf ( "Session packet:(raw data?) \n " );
828 "NBT Session Request \n Flags=[rW] \n Destination=[n1] \n Source=[n1] \n " ,
833 data
= fdata ( data
, "NBT Session Granted \n Flags=[rW] \n " , maxbuf
);
838 int ecode
= CVAL ( data
, 4 );
840 data
= fdata ( data
, "NBT SessionReject \n Flags=[rW] \n Reason=[B] \n " ,
844 printf ( "Not listening on called name \n " );
847 printf ( "Not listening for calling name \n " );
850 printf ( "Called name not present \n " );
853 printf ( "Called name present, but insufficient resources \n " );
856 printf ( "Unspecified error 0x%X \n " , ecode
);
863 data
= fdata ( data
, "NBT Session Keepalive \n Flags=[rW] \n " , maxbuf
);
867 printf ( "flags=0x%x \n " , flags
);
868 data
= fdata ( data
, "NBT - Unknown packet type \n Type=[rW] \n " , maxbuf
);
876 * print a NBT packet received across udp on port 137
879 nbt_udp137_print ( const uchar
* data
, int length
)
881 const uchar
* maxbuf
= data
+ length
;
882 int name_trn_id
= RSVAL ( data
, 0 );
883 int response
= ( CVAL ( data
, 2 )>> 7 );
884 int opcode
= ( CVAL ( data
, 2 ) >> 3 ) & 0xF ;
885 int nm_flags
= (( CVAL ( data
, 2 ) & 0x7 ) << 4 ) + ( CVAL ( data
, 3 )>> 4 );
886 int rcode
= CVAL ( data
, 3 ) & 0xF ;
887 int qdcount
= RSVAL ( data
, 4 );
888 int ancount
= RSVAL ( data
, 6 );
889 int nscount
= RSVAL ( data
, 8 );
890 int arcount
= RSVAL ( data
, 10 );
896 if ( maxbuf
<= data
) return ;
901 printf ( "NBT UDP PACKET(137): " );
904 case 0 : opcodestr
= "QUERY" ; break ;
905 case 5 : opcodestr
= "REGISTRATION" ; break ;
906 case 6 : opcodestr
= "RELEASE" ; break ;
907 case 7 : opcodestr
= "WACK" ; break ;
908 case 8 : opcodestr
= "REFRESH(8)" ; break ;
909 case 9 : opcodestr
= "REFRESH" ; break ;
910 default : opcodestr
= "OPUNKNOWN" ; break ;
912 printf ( "%s" , opcodestr
);
915 printf ( "; NEGATIVE" );
917 printf ( "; POSITIVE" );
921 printf ( "; RESPONSE" );
926 printf ( "; BROADCAST" );
933 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 " ,
934 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
, arcount
);
939 int total
= ancount
+ nscount
+ arcount
;
942 if ( qdcount
> 100 || total
> 100 ) {
943 printf ( "Corrupt packet?? \n " );
948 printf ( "QuestionRecords: \n " );
949 for ( i
= 0 ; i
< qdcount
; i
++)
950 p
= fdata ( p
, "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" , maxbuf
);
956 printf ( " \n ResourceRecords: \n " );
957 for ( i
= 0 ; i
< total
; i
++) {
960 p
= fdata ( p
, "Name=[n1] \n #" , maxbuf
);
963 restype
= RSVAL ( p
, 0 );
964 p
= fdata ( p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 );
968 printf ( "ResourceLength=%d \n ResourceData= \n " , rdlen
);
971 p
= fdata ( p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
);
975 if ( restype
== 0x21 ) {
976 int numnames
= CVAL ( p
, 0 );
977 p
= fdata ( p
, "NumNames=[B] \n " , p
+ 1 );
981 p
= fdata ( p
, "Name=[n2] \t #" , maxbuf
);
982 if ( p
[ 0 ] & 0x80 ) printf ( "<GROUP> " );
983 switch ( p
[ 0 ] & 0x60 ) {
984 case 0x00 : printf ( "B " ); break ;
985 case 0x20 : printf ( "P " ); break ;
986 case 0x40 : printf ( "M " ); break ;
987 case 0x60 : printf ( "_ " ); break ;
989 if ( p
[ 0 ] & 0x10 ) printf ( "<DEREGISTERING> " );
990 if ( p
[ 0 ] & 0x08 ) printf ( "<CONFLICT> " );
991 if ( p
[ 0 ] & 0x04 ) printf ( "<ACTIVE> " );
992 if ( p
[ 0 ] & 0x02 ) printf ( "<PERMANENT> " );
997 print_data ( p
, min ( rdlen
, length
- (( const uchar
*) p
- data
)));
1005 if (( uchar
*) p
< maxbuf
) {
1006 fdata ( p
, "AdditionalData: \n " , maxbuf
);
1017 * print a NBT packet received across udp on port 138
1019 void nbt_udp138_print ( const uchar
* data
, int length
)
1021 const uchar
* maxbuf
= data
+ length
;
1023 if ( maxbuf
> snapend
) maxbuf
= snapend
;
1024 if ( maxbuf
<= data
) return ;
1028 printf ( "NBT UDP PACKET(138)" );
1032 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
);
1035 print_smb ( data
, maxbuf
);
1044 print netbeui frames
1046 void netbeui_print ( u_short control
, const uchar
* data
, int length
)
1048 const uchar
* maxbuf
= data
+ length
;
1052 int is_truncated
= 0 ;
1054 if ( maxbuf
> snapend
)
1056 if (& data
[ 7 ] >= maxbuf
)
1059 command
= CVAL ( data
, 4 );
1061 if ( data2
>= maxbuf
) {
1069 printf ( "NetBeui Packet" );
1073 printf ( " \n >>> NetBeui Packet \n Type=0x%X " , control
);
1074 data
= fdata ( data
, "Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
);
1080 data
= fdata ( data
, "NameQuery:[P1] \n SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1084 data
= fdata ( data
, "NetbiosDataGram:[P7] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1088 data
= fdata ( data
, "NameRecognise: \n [P1] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1092 data
= fdata ( data
, "SessionInitialise: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1096 data
= fdata ( data
, "SessionConfirm: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1100 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
);
1104 data
= fdata ( data
, "NetbiosDataAck: \n [P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1108 data
= fdata ( data
, "SessionEnd: \n [P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " , data2
);
1112 data
= fdata ( data
, "SessionAlive \n " , data2
);
1116 data
= fdata ( data
, "Unknown Netbios Command " , data2
);
1123 /* data2 was past the end of the buffer */
1127 /* If there isn't enough data for "\377SMB", don't look for it. */
1128 if (& data2
[ 3 ] >= maxbuf
)
1131 if ( memcmp ( data2
, " \377 SMB" , 4 )== 0 ) {
1132 print_smb ( data2
, maxbuf
);
1135 for ( i
= 0 ; i
< 128 ; i
++) {
1136 if (& data2
[ i
+ 3 ] >= maxbuf
)
1138 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 )== 0 ) {
1139 printf ( "found SMB packet at %d \n " , i
);
1140 print_smb (& data2
[ i
], maxbuf
);
1152 * print IPX-Netbios frames
1154 void ipx_netbios_print ( const uchar
* data
, u_int length
)
1157 * this is a hack till I work out how to parse the rest of the
1158 * NetBIOS-over-IPX stuff
1161 const uchar
* maxbuf
;
1163 maxbuf
= data
+ length
;
1164 /* Don't go past the end of the captured data in the packet. */
1165 if ( maxbuf
> snapend
)
1168 for ( i
= 0 ; i
< 128 ; i
++) {
1169 if (& data
[ i
+ 4 ] > maxbuf
)
1171 if ( memcmp (& data
[ i
], " \377 SMB" , 4 ) == 0 ) {
1172 fdata ( data
, " \n >>> IPX transport " , & data
[ i
]);
1174 print_smb (& data
[ i
], maxbuf
);
1181 fdata ( data
, " \n >>> Unknown IPX " , maxbuf
);