]>
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.16 2001-06-28 03:15:38 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
);
353 fdata ( param
, f3
, MIN ( param
+ paramlen
, maxbuf
));
355 fdata ( data
, f4
, MIN ( data
+ datalen
, maxbuf
));
360 print_negprot ( const uchar
* words
, const uchar
* data
, ...)
362 uchar
* f1
= NULL
, * f2
= NULL
;
367 buf
= va_arg ( ap
, uchar
*);
368 maxbuf
= va_arg ( ap
, uchar
*);
372 f2
= "*|Dialect=[Z] \n " ;
374 if ( CVAL ( words
, 0 ) == 1 )
375 f1
= "Core Protocol \n DialectIndex=[d]" ;
376 else if ( CVAL ( words
, 0 ) == 17 )
377 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=" ;
378 else if ( CVAL ( words
, 0 ) == 13 )
379 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 ,
386 PTR_DIFF ( maxbuf
, words
+ 1 )));
389 fdata ( data
+ 2 , f2
, MIN ( data
+ 2 + SVAL ( data
, 0 ), maxbuf
));
391 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 " ;
413 if ( CVAL ( words
, 0 ) == 3 ) {
414 f1
= "Com2=[w] \n Off2=[d] \n Action=[w] \n " ;
415 } else if ( CVAL ( words
, 0 ) == 13 ) {
416 f1
= "Com2=[B] \n Res=[B] \n Off2=[d] \n Action=[w] \n " ;
417 f2
= "NativeOS=[S] \n NativeLanMan=[S] \n PrimaryDomain=[S] \n " ;
422 fdata ( words
+ 1 , f1
, MIN ( words
+ 1 + CVAL ( words
, 0 ) * 2 , maxbuf
));
424 print_data ( words
+ 1 , MIN ( CVAL ( words
, 0 ) * 2 ,
425 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
[] = {
435 { - 1 , "SMBunknown" , 0 , DEFDESCRIPT
},
437 { SMBtcon
, "SMBtcon" , 0 ,
438 { NULL
, "Path=[Z] \n Password=[Z] \n Device=[Z] \n " ,
439 "MaxXmit=[d] \n TreeId=[d] \n " , NULL
,
442 { SMBtdis
, "SMBtdis" , 0 , DEFDESCRIPT
},
443 { SMBexit
, "SMBexit" , 0 , DEFDESCRIPT
},
444 { SMBioctl
, "SMBioctl" , 0 , DEFDESCRIPT
},
446 { SMBecho
, "SMBecho" , 0 ,
447 { "ReverbCount=[d] \n " , NULL
,
448 "SequenceNum=[d] \n " , NULL
,
451 { SMBulogoffX
, "SMBulogoffX" , FLG_CHAIN
, DEFDESCRIPT
},
453 { SMBgetatr
, "SMBgetatr" , 0 ,
454 { NULL
, "Path=[Z] \n " ,
455 "Attribute=[A] \n Time=[T2]Size=[D] \n Res=([w,w,w,w,w]) \n " , NULL
,
458 { SMBsetatr
, "SMBsetatr" , 0 ,
459 { "Attribute=[A] \n Time=[T2]Res=([w,w,w,w,w]) \n " , "Path=[Z] \n " ,
460 NULL
, NULL
, NULL
} },
462 { SMBchkpth
, "SMBchkpth" , 0 ,
463 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
465 { SMBsearch
, "SMBsearch" , 0 ,
466 { "Count=[d] \n Attrib=[A] \n " ,
467 "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 "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 " ,
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 " ,
477 { SMBcreate
, "SMBcreate" , 0 ,
478 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
480 { SMBmknew
, "SMBmknew" , 0 ,
481 { "Attrib=[A] \n Time=[T2]" , "Path=[Z] \n " , "Handle=[d] \n " , NULL
, NULL
} },
483 { SMBunlink
, "SMBunlink" , 0 ,
484 { "Attrib=[A] \n " , "Path=[Z] \n " , NULL
, NULL
, NULL
} },
486 { SMBread
, "SMBread" , 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 { SMBwrite
, "SMBwrite" , 0 ,
491 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
492 "Count=[d] \n " , NULL
, NULL
} },
494 { SMBclose
, "SMBclose" , 0 ,
495 { "Handle=[d] \n Time=[T2]" , NULL
, NULL
, NULL
, NULL
} },
497 { SMBmkdir
, "SMBmkdir" , 0 ,
498 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
500 { SMBrmdir
, "SMBrmdir" , 0 ,
501 { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
503 { SMBdskattr
, "SMBdskattr" , 0 ,
505 "TotalUnits=[d] \n BlocksPerUnit=[d] \n BlockSize=[d] \n FreeUnits=[d] \n Media=[w] \n " ,
509 { "Attrib=[A] \n " , "OldPath=[Z] \n NewPath=[Z] \n " , NULL
, NULL
, NULL
} },
512 * this is a Pathworks specific call, allowing the
513 * changing of the root path
515 { pSETDIR
, "SMBsetdir" , 0 , { NULL
, "Path=[Z] \n " , NULL
, NULL
, NULL
} },
517 { SMBlseek
, "SMBlseek" , 0 ,
518 { "Handle=[d] \n Mode=[w] \n Offset=[D] \n " , "Offset=[D] \n " , NULL
, NULL
} },
520 { SMBflush
, "SMBflush" , 0 , { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
522 { SMBsplopen
, "SMBsplopen" , 0 ,
523 { "SetupLen=[d] \n Mode=[w] \n " , "Ident=[Z] \n " , "Handle=[d] \n " ,
526 { SMBsplclose
, "SMBsplclose" , 0 ,
527 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
529 { SMBsplretq
, "SMBsplretq" , 0 ,
530 { "MaxCount=[d] \n StartIndex=[d] \n " , NULL
,
531 "Count=[d] \n Index=[d] \n " ,
532 "*Time=[T2]Status=[B] \n JobID=[d] \n Size=[D] \n Res=[B]Name=[s16] \n " ,
535 { SMBsplwr
, "SMBsplwr" , 0 ,
536 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
538 { SMBlock
, "SMBlock" , 0 ,
539 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
541 { SMBunlock
, "SMBunlock" , 0 ,
542 { "Handle=[d] \n Count=[D] \n Offset=[D] \n " , NULL
, NULL
, NULL
, NULL
} },
544 /* CORE+ PROTOCOL FOLLOWS */
546 { SMBreadbraw
, "SMBreadbraw" , 0 ,
547 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[d] \n " ,
548 NULL
, NULL
, NULL
, NULL
} },
550 { SMBwritebraw
, "SMBwritebraw" , 0 ,
551 { "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 " ,
552 NULL
, "WriteRawAck" , NULL
, NULL
} },
554 { SMBwritec
, "SMBwritec" , 0 ,
555 { NULL
, NULL
, "Count=[d] \n " , NULL
, NULL
} },
557 { SMBwriteclose
, "SMBwriteclose" , 0 ,
558 { "Handle=[d] \n Count=[d] \n Offset=[D] \n Time=[T2]Res=([w,w,w,w,w,w])" ,
559 NULL
, "Count=[d] \n " , NULL
, NULL
} },
561 { SMBlockread
, "SMBlockread" , 0 ,
562 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
563 "Count=[d] \n Res=([w,w,w,w]) \n " , NULL
, NULL
} },
565 { SMBwriteunlock
, "SMBwriteunlock" , 0 ,
566 { "Handle=[d] \n ByteCount=[d] \n Offset=[D] \n CountLeft=[d] \n " , NULL
,
567 "Count=[d] \n " , NULL
, NULL
} },
569 { SMBreadBmpx
, "SMBreadBmpx" , 0 ,
570 { "Handle=[d] \n Offset=[D] \n MaxCount=[d] \n MinCount=[d] \n TimeOut=[D] \n Res=[w] \n " ,
572 "Offset=[D] \n TotCount=[d] \n Remaining=[d] \n Res=([w,w]) \n DataSize=[d] \n DataOff=[d] \n " ,
575 { SMBwriteBmpx
, "SMBwriteBmpx" , 0 ,
576 { "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
,
577 "Remaining=[d] \n " , NULL
, NULL
} },
579 { SMBwriteBs
, "SMBwriteBs" , 0 ,
580 { "Handle=[d] \n TotCount=[d] \n Offset=[D] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n " ,
581 NULL
, "Count=[d] \n " , NULL
, NULL
} },
583 { SMBsetattrE
, "SMBsetattrE" , 0 ,
584 { "Handle=[d] \n CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]" , NULL
,
585 NULL
, NULL
, NULL
} },
587 { SMBgetattrE
, "SMBgetattrE" , 0 ,
588 { "Handle=[d] \n " , NULL
,
589 "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D] \n AllocSize=[D] \n Attribute=[A] \n " ,
592 { SMBtranss
, "SMBtranss" , 0 , DEFDESCRIPT
},
593 { SMBioctls
, "SMBioctls" , 0 , DEFDESCRIPT
},
595 { SMBcopy
, "SMBcopy" , 0 ,
596 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
597 "CopyCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
599 { SMBmove
, "SMBmove" , 0 ,
600 { "TreeID2=[d] \n OFun=[w] \n Flags=[w] \n " , "Path=[S] \n NewPath=[S] \n " ,
601 "MoveCount=[d] \n " , "|ErrStr=[S] \n " , NULL
} },
603 { SMBopenX
, "SMBopenX" , FLG_CHAIN
,
604 { "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 " ,
606 "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 " ,
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 " ,
612 "Com2=[w] \n Off2=[d] \n Remaining=[d] \n Res=[W] \n DataSize=[d] \n DataOff=[d] \n Res=([w,w,w,w]) \n " ,
615 { SMBwriteX
, "SMBwriteX" , FLG_CHAIN
,
616 { "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 " ,
618 "Com2=[w] \n Off2=[d] \n Count=[d] \n Remaining=[d] \n Res=[W] \n " ,
621 { SMBlockingX
, "SMBlockingX" , FLG_CHAIN
,
622 { "Com2=[w] \n Off2=[d] \n Handle=[d] \n LockType=[w] \n TimeOut=[D] \n UnlockCount=[d] \n LockCount=[d] \n " ,
623 "*Process=[d] \n Offset=[D] \n Length=[D] \n " ,
624 "Com2=[w] \n Off2=[d] \n " , NULL
, NULL
} },
626 { SMBffirst
, "SMBffirst" , 0 ,
627 { "Count=[d] \n Attrib=[A] \n " ,
628 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
630 "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 " ,
633 { SMBfunique
, "SMBfunique" , 0 ,
634 { "Count=[d] \n Attrib=[A] \n " ,
635 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
637 "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 " ,
640 { SMBfclose
, "SMBfclose" , 0 ,
641 { "Count=[d] \n Attrib=[A] \n " ,
642 "Path=[Z] \n BlkType=[B] \n BlkLen=[d] \n |Res1=[B] \n Mask=[s11] \n Srv1=[B] \n DirIndex=[d] \n Srv2=[w] \n " ,
644 "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 " ,
647 { SMBfindnclose
, "SMBfindnclose" , 0 ,
648 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
650 { SMBfindclose
, "SMBfindclose" , 0 ,
651 { "Handle=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
653 { SMBsends
, "SMBsends" , 0 ,
654 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
656 { SMBsendstrt
, "SMBsendstrt" , 0 ,
657 { NULL
, "Source=[Z] \n Dest=[Z] \n " , "GroupID=[d] \n " , NULL
, NULL
} },
659 { SMBsendend
, "SMBsendend" , 0 ,
660 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
662 { SMBsendtxt
, "SMBsendtxt" , 0 ,
663 { "GroupID=[d] \n " , NULL
, NULL
, NULL
, NULL
} },
665 { SMBsendb
, "SMBsendb" , 0 ,
666 { NULL
, "Source=[Z] \n Dest=[Z] \n " , NULL
, NULL
, NULL
} },
668 { SMBfwdname
, "SMBfwdname" , 0 , DEFDESCRIPT
},
669 { SMBcancelf
, "SMBcancelf" , 0 , DEFDESCRIPT
},
670 { SMBgetmac
, "SMBgetmac" , 0 , DEFDESCRIPT
},
672 { SMBnegprot
, "SMBnegprot" , 0 ,
673 { NULL
, NULL
, NULL
, NULL
, print_negprot
} },
675 { SMBsesssetupX
, "SMBsesssetupX" , FLG_CHAIN
,
676 { NULL
, NULL
, NULL
, NULL
, print_sesssetup
} },
678 { SMBtconX
, "SMBtconX" , FLG_CHAIN
,
679 { "Com2=[w] \n Off2=[d] \n Flags=[w] \n PassLen=[d] \n Passwd&Path&Device= \n " ,
680 NULL
, "Com2=[w] \n Off2=[d] \n " , "ServiceType=[S] \n " , NULL
} },
682 { SMBtrans2
, "SMBtrans2" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans2
} },
684 { SMBtranss2
, "SMBtranss2" , 0 , DEFDESCRIPT
},
685 { SMBctemp
, "SMBctemp" , 0 , DEFDESCRIPT
},
686 { SMBreadBs
, "SMBreadBs" , 0 , DEFDESCRIPT
},
687 { SMBtrans
, "SMBtrans" , 0 , { NULL
, NULL
, NULL
, NULL
, print_trans
} },
689 { SMBnttrans
, "SMBnttrans" , 0 , DEFDESCRIPT
},
690 { SMBnttranss
, "SMBnttranss" , 0 , DEFDESCRIPT
},
692 { SMBntcreateX
, "SMBntcreateX" , FLG_CHAIN
,
693 { "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 " ,
695 "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 " ,
698 { SMBntcancel
, "SMBntcancel" , 0 , DEFDESCRIPT
},
700 { - 1 , NULL
, 0 , DEFDESCRIPT
}
705 * print a SMB message
708 print_smb ( const uchar
* buf
, const uchar
* maxbuf
)
711 const uchar
* words
, * data
;
713 char * fmt_smbheader
=
714 "[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 " ;
716 request
= ( CVAL ( buf
, 9 ) & 0x80 ) ? 0 : 1 ;
718 command
= CVAL ( buf
, 4 );
720 fn
= smbfind ( command
, smb_fns
);
725 printf ( "SMB PACKET: %s (%s) \n " , fn
-> name
, request
? "REQUEST" : "REPLY" );
730 /* print out the header */
731 fdata ( buf
, fmt_smbheader
, buf
+ 33 );
734 int class = CVAL ( buf
, 5 );
735 int num
= SVAL ( buf
, 7 );
736 printf ( "SMBError = %s \n " , smb_errstr ( class , num
));
740 data
= words
+ 1 + CVAL ( words
, 0 )* 2 ;
742 while ( words
&& data
) {
744 int wct
= CVAL ( words
, 0 );
747 f1
= fn
-> descript
. req_f1
;
748 f2
= fn
-> descript
. req_f2
;
750 f1
= fn
-> descript
. rep_f1
;
751 f2
= fn
-> descript
. rep_f2
;
755 fn
-> descript
. fn ( words
, data
, buf
, maxbuf
);
758 printf ( "smbvwv[]= \n " );
759 fdata ( words
+ 1 , f1
, words
+ 1 + wct
* 2 );
763 printf ( "smbvwv[]= \n " );
764 for ( i
= 0 ; i
< wct
; i
++) {
765 v
= SVAL ( words
+ 1 , 2 * i
);
766 printf ( "smb_vwv[%d]=%d (0x%X) \n " , i
, v
, v
);
771 printf ( "smbbuf[]= \n " );
772 fdata ( data
+ 2 , f2
, maxbuf
);
774 int bcc
= SVAL ( data
, 0 );
775 printf ( "smb_bcc=%d \n " , bcc
);
777 printf ( "smb_buf[]= \n " );
778 print_data ( data
+ 2 , MIN ( bcc
, PTR_DIFF ( maxbuf
, data
+ 2 )));
783 if (( fn
-> flags
& FLG_CHAIN
) != 0 && CVAL ( words
, 0 ) &&
784 SVAL ( words
, 1 ) != 0xFF ) {
785 command
= SVAL ( words
, 1 );
786 words
= buf
+ SVAL ( words
, 3 );
787 data
= words
+ 1 + CVAL ( words
, 0 ) * 2 ;
789 fn
= smbfind ( command
, smb_fns
);
791 printf ( " \n SMB PACKET: %s (%s) (CHAINED) \n " ,
792 fn
-> name
, request
? "REQUEST" : "REPLY" );
802 * print a NBT packet received across tcp on port 139
805 nbt_tcp_print ( const uchar
* data
, int length
)
807 const uchar
* maxbuf
= data
+ length
;
808 int flags
= CVAL ( data
, 0 );
809 int nbt_len
= RSVAL ( data
, 2 );
818 printf ( "NBT Packet" );
827 printf ( "flags=0x%x \n " , flags
);
829 data
= fdata ( data
, "NBT Session Packet \n Flags=[rw] \n Length=[rd] \n " ,
833 if ( memcmp ( data
, " \377 SMB" , 4 ) == 0 ) {
834 if ( nbt_len
> PTR_DIFF ( maxbuf
, data
))
835 printf ( "WARNING: Short packet. Try increasing the snap length (%lu) \n " ,
836 ( unsigned long ) PTR_DIFF ( maxbuf
, data
));
837 print_smb ( data
, maxbuf
> data
+ nbt_len
? data
+ nbt_len
: maxbuf
);
839 printf ( "Session packet:(raw data?) \n " );
844 "NBT Session Request \n Flags=[rW] \n Destination=[n1] \n Source=[n1] \n " ,
849 data
= fdata ( data
, "NBT Session Granted \n Flags=[rW] \n " , maxbuf
);
854 int ecode
= CVAL ( data
, 4 );
856 data
= fdata ( data
, "NBT SessionReject \n Flags=[rW] \n Reason=[B] \n " ,
860 printf ( "Not listening on called name \n " );
863 printf ( "Not listening for calling name \n " );
866 printf ( "Called name not present \n " );
869 printf ( "Called name present, but insufficient resources \n " );
872 printf ( "Unspecified error 0x%X \n " , ecode
);
879 data
= fdata ( data
, "NBT Session Keepalive \n Flags=[rW] \n " , maxbuf
);
883 printf ( "flags=0x%x \n " , flags
);
884 data
= fdata ( data
, "NBT - Unknown packet type \n Type=[rW] \n " , maxbuf
);
892 * print a NBT packet received across udp on port 137
895 nbt_udp137_print ( const uchar
* data
, int length
)
897 const uchar
* maxbuf
= data
+ length
;
898 int name_trn_id
= RSVAL ( data
, 0 );
899 int response
= ( CVAL ( data
, 2 ) >> 7 );
900 int opcode
= ( CVAL ( data
, 2 ) >> 3 ) & 0xF ;
901 int nm_flags
= (( CVAL ( data
, 2 ) & 0x7 ) << 4 ) + ( CVAL ( data
, 3 ) >> 4 );
902 int rcode
= CVAL ( data
, 3 ) & 0xF ;
903 int qdcount
= RSVAL ( data
, 4 );
904 int ancount
= RSVAL ( data
, 6 );
905 int nscount
= RSVAL ( data
, 8 );
906 int arcount
= RSVAL ( data
, 10 );
919 printf ( "NBT UDP PACKET(137): " );
922 case 0 : opcodestr
= "QUERY" ; break ;
923 case 5 : opcodestr
= "REGISTRATION" ; break ;
924 case 6 : opcodestr
= "RELEASE" ; break ;
925 case 7 : opcodestr
= "WACK" ; break ;
926 case 8 : opcodestr
= "REFRESH(8)" ; break ;
927 case 9 : opcodestr
= "REFRESH" ; break ;
928 default : opcodestr
= "OPUNKNOWN" ; break ;
930 printf ( "%s" , opcodestr
);
933 printf ( "; NEGATIVE" );
935 printf ( "; POSITIVE" );
939 printf ( "; RESPONSE" );
944 printf ( "; BROADCAST" );
951 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 " ,
952 name_trn_id
, opcode
, nm_flags
, rcode
, qdcount
, ancount
, nscount
,
957 total
= ancount
+ nscount
+ arcount
;
959 if ( qdcount
> 100 || total
> 100 ) {
960 printf ( "Corrupt packet?? \n " );
965 printf ( "QuestionRecords: \n " );
966 for ( i
= 0 ; i
< qdcount
; i
++)
968 "|Name=[n1] \n QuestionType=[rw] \n QuestionClass=[rw] \n #" ,
975 printf ( " \n ResourceRecords: \n " );
976 for ( i
= 0 ; i
< total
; i
++) {
980 p
= fdata ( p
, "Name=[n1] \n #" , maxbuf
);
983 restype
= RSVAL ( p
, 0 );
984 p
= fdata ( p
, "ResType=[rw] \n ResClass=[rw] \n TTL=[rD] \n " , p
+ 8 );
988 printf ( "ResourceLength=%d \n ResourceData= \n " , rdlen
);
991 p
= fdata ( p
, "AddrType=[rw] \n Address=[b.b.b.b] \n " , p
+ rdlen
);
995 if ( restype
== 0x21 ) {
996 int numnames
= CVAL ( p
, 0 );
997 p
= fdata ( p
, "NumNames=[B] \n " , p
+ 1 );
1000 while ( numnames
--) {
1001 p
= fdata ( p
, "Name=[n2] \t #" , maxbuf
);
1004 switch ( p
[ 0 ] & 0x60 ) {
1005 case 0x00 : printf ( "B " ); break ;
1006 case 0x20 : printf ( "P " ); break ;
1007 case 0x40 : printf ( "M " ); break ;
1008 case 0x60 : printf ( "_ " ); break ;
1011 printf ( "<DEREGISTERING> " );
1013 printf ( "<CONFLICT> " );
1015 printf ( "<ACTIVE> " );
1017 printf ( "<PERMANENT> " );
1022 print_data ( p
, min ( rdlen
, length
- (( const uchar
*) p
- data
)));
1029 if (( uchar
*) p
< maxbuf
)
1030 fdata ( p
, "AdditionalData: \n " , maxbuf
);
1040 * print a NBT packet received across udp on port 138
1043 nbt_udp138_print ( const uchar
* data
, int length
)
1045 const uchar
* maxbuf
= data
+ length
;
1047 if ( maxbuf
> snapend
)
1054 printf ( "NBT UDP PACKET(138)" );
1059 " \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 #" ,
1063 print_smb ( data
, maxbuf
);
1071 print netbeui frames
1074 netbeui_print ( u_short control
, const uchar
* data
, int length
)
1076 const uchar
* maxbuf
= data
+ length
;
1080 int is_truncated
= 0 ;
1082 if ( maxbuf
> snapend
)
1084 if (& data
[ 7 ] >= maxbuf
)
1087 command
= CVAL ( data
, 4 );
1089 if ( data2
>= maxbuf
) {
1097 printf ( "NetBeui Packet" );
1101 printf ( " \n >>> NetBeui Packet \n Type=0x%X " , control
);
1102 data
= fdata ( data
, "Length=[d] Signature=[w] Command=[B] \n #" , maxbuf
);
1108 data
= fdata ( data
, "NameQuery:[P1] \n SessionNumber=[B] \n NameType=[B][P2] \n ResponseCorrelator=[w] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1113 "NetbiosDataGram:[P7] \n Destination=[n2] \n Source=[n2] \n " , data2
);
1118 "NameRecognise: \n [P1] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n Destination=[n2] \n Source=[n2] \n " ,
1124 "SessionInitialise: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " ,
1130 "SessionConfirm: \n Data1=[B] \n Data2=[w] \n TransmitCorrelator=[w] \n ResponseCorelator=[w] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " ,
1136 "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 " ,
1142 "NetbiosDataAck: \n [P3]TransmitCorrelator=[w][P2] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " ,
1148 "SessionEnd: \n [P1]Data2=[w][P4] \n RemoteSessionNumber=[B] \n LocalSessionNumber=[B] \n " ,
1153 data
= fdata ( data
, "SessionAlive \n " , data2
);
1157 data
= fdata ( data
, "Unknown Netbios Command " , data2
);
1164 /* data2 was past the end of the buffer */
1168 /* If there isn't enough data for "\377SMB", don't look for it. */
1169 if (& data2
[ 3 ] >= maxbuf
)
1172 if ( memcmp ( data2
, " \377 SMB" , 4 ) == 0 )
1173 print_smb ( data2
, maxbuf
);
1176 for ( i
= 0 ; i
< 128 ; i
++) {
1177 if (& data2
[ i
+ 3 ] >= maxbuf
)
1179 if ( memcmp (& data2
[ i
], " \377 SMB" , 4 ) == 0 ) {
1180 printf ( "found SMB packet at %d \n " , i
);
1181 print_smb (& data2
[ i
], maxbuf
);
1193 * print IPX-Netbios frames
1196 ipx_netbios_print ( const uchar
* data
, u_int length
)
1199 * this is a hack till I work out how to parse the rest of the
1200 * NetBIOS-over-IPX stuff
1203 const uchar
* maxbuf
;
1205 maxbuf
= data
+ length
;
1206 /* Don't go past the end of the captured data in the packet. */
1207 if ( maxbuf
> snapend
)
1210 for ( i
= 0 ; i
< 128 ; i
++) {
1211 if (& data
[ i
+ 4 ] > maxbuf
)
1213 if ( memcmp (& data
[ i
], " \377 SMB" , 4 ) == 0 ) {
1214 fdata ( data
, " \n >>> IPX transport " , & data
[ i
]);
1216 print_smb (& data
[ i
], maxbuf
);
1223 fdata ( data
, " \n >>> Unknown IPX " , maxbuf
);