diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/Makefile.in ./Makefile.in --- /usr/src/redhat/tcpdump-3.4.orig/Makefile.in Fri Jan 9 14:17:03 1998 +++ ./Makefile.in Sat Apr 17 11:15:17 1999 @@ -72,7 +72,7 @@ print-pim.c print-ppp.c print-raw.c print-rip.c print-sl.c \ print-snmp.c print-sunrpc.c print-tcp.c print-tftp.c print-udp.c \ print-wb.c addrtoname.c bpf_dump.c gmt2local.c machdep.c \ - parsenfsfh.c util.c savestr.c setsignal.c + parsenfsfh.c util.c savestr.c setsignal.c print-smb.c smbutil.c LOCALSRC = GENSRC = version.c diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/README.smb ./README.smb --- /usr/src/redhat/tcpdump-3.4.orig/README.smb Thu Jan 1 10:00:00 1970 +++ ./README.smb Sun Jun 6 00:11:13 1999 @@ -0,0 +1,52 @@ +This is set of patches to tcpdump-3.2.1 that gives it the ability to +interpret NBT and SMB packets in a fair bit of detail. + +Please send any feedback to Andrew.Tridgell@anu.edu.au + +Usage: + +To capture all SMB packets going to or from host "fred" try this: + +tcpdump -i eth0 -s 1500 port 139 host fred + +If you want name resolution or browse packets then try ports 137 and +138 respectively. + +if you are sniffing hosts that use unicode then set the environment +variable USE_UNICODE to 1. + +change log: + 0.2: added name server and browse stuff + 0.3: added IPX and Netbeui support + 0.4: added unicode support + +Example Output: + +Here is a sample of a capture of a "SMBsearch" directory search. If +you don't get output that looks like this then you have patched +tcpdump incorrectly. + +NBT Session Packet +Flags=0x0 +Length=57 + +SMB PACKET: SMBsearch (REQUEST) +SMB Command = 0x81 +Error class = 0x0 +Error code = 0 +Flags1 = 0x8 +Flags2 = 0x3 +Tree ID = 2048 +Proc ID = 11787 +UID = 2048 +MID = 11887 +Word Count = 2 +smbvwv[]= +Count=98 +Attrib=HIDDEN SYSTEM DIR +smbbuf[]= +Path=\????????.??? +BlkType=0x5 +BlkLen=0 + + Common subdirectories: /usr/src/redhat/tcpdump-3.4.orig/lbl and ./lbl Common subdirectories: /usr/src/redhat/tcpdump-3.4.orig/linux-include and ./linux-include diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/print-llc.c ./print-llc.c --- /usr/src/redhat/tcpdump-3.4.orig/print-llc.c Thu Jan 2 15:56:48 1997 +++ ./print-llc.c Sat Apr 17 11:15:17 1999 @@ -79,10 +79,12 @@ ipx_print(p, length); return (1); } -#ifdef notyet - else if (p[0] == 0xf0 && p[1] == 0xf0) - netbios_print(p, length); -#endif + else if (p[0] == 0xf0 && p[1] == 0xf0) { + /* we don't actually have a full netbeui parser yet, but the + smb parser can handle many smb-in-netbeui packets, which + is very useful, so we call that */ + netbeui_print(p+2,p+min(caplen,length)); + } if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS && llc.llcui == LLC_UI) { isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst); @@ -157,6 +159,13 @@ caplen -= 3; } } + + if (!strcmp(m,"ui") && f=='C') { + /* we don't have a proper ipx decoder yet, but there + is a partial one in the smb code */ + ipx_netbios_print(p,p+min(caplen,length)); + } + } else { char f; llc.llcis = ntohs(llc.llcis); @@ -185,8 +194,5 @@ caplen -= 4; } (void)printf(" len=%d", length); - if (caplen > 0) { - default_print_unaligned(p, caplen); - } return(1); } diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/print-smb.c ./print-smb.c --- /usr/src/redhat/tcpdump-3.4.orig/print-smb.c Thu Jan 1 10:00:00 1970 +++ ./print-smb.c Mon Jun 28 22:06:55 1999 @@ -0,0 +1,999 @@ +/* + Copyright (C) Andrew Tridgell 1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#include +#include + +#include "smb.h" + +static int request=0; + +uchar *startbuf=NULL; + +struct smbdescript +{ + char *req_f1; + char *req_f2; + char *rep_f1; + char *rep_f2; + void (*fn)(); +}; + +struct smbfns +{ + int id; + char *name; + int flags; + struct smbdescript descript; +}; + +#define DEFDESCRIPT {NULL,NULL,NULL,NULL,NULL} + +#define FLG_CHAIN (1<<0) + +static struct smbfns *smbfind(int id,struct smbfns *list) +{ + int sindex; + + for (sindex=0;list[sindex].name;sindex++) + if (list[sindex].id == id) return(&list[sindex]); + + return(&list[0]); +} + +static void trans2_findfirst(uchar *param,uchar *data,int pcnt,int dcnt) +{ + char *fmt; + + if (request) { + fmt = "Attribute=[A]\nSearchCount=[d]\nFlags=[w]\nLevel=[dP5]\nFile=[S]\n"; + } else { + fmt = "Handle=[w]\nCount=[d]\nEOS=[w]\nEoffset=[d]\nLastNameOfs=[w]\n"; + } + + fdata(param,fmt,param+pcnt); + if (dcnt) { + printf("data:\n"); + print_data(data,dcnt); + } +} + +static void trans2_qfsinfo(uchar *param,uchar *data,int pcnt,int dcnt) +{ + static int level=0; + char *fmt=""; + + if (request) { + level = SVAL(param,0); + fmt = "InfoLevel=[d]\n"; + fdata(param,fmt,param+pcnt); + } else { + switch (level) { + case 1: + fmt = "idFileSystem=[W]\nSectorUnit=[D]\nUnit=[D]\nAvail=[D]\nSectorSize=[d]\n"; + break; + case 2: + fmt = "CreationTime=[T2]VolNameLength=[B]\nVolumeLabel=[s12]\n"; + break; + case 0x105: + fmt = "Capabilities=[W]\nMaxFileLen=[D]\nVolNameLen=[D]\nVolume=[S]\n"; + break; + default: + fmt = "UnknownLevel\n"; + } + fdata(data,fmt,data+dcnt); + } + if (dcnt) { + printf("data:\n"); + print_data(data,dcnt); + } +} + +struct smbfns trans2_fns[] = { +{0,"TRANSACT2_OPEN",0, + {"Flags2=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]\nOFun=[w]\nSize=[D]\nRes=([w,w,w,w,w])\nPath=[S]",NULL, + "Handle=[d]\nAttrib=[A]\nTime=[T2]\nSize=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nInode=[W]\nOffErr=[d]\n|EALength=[d]\n",NULL,NULL}}, + +{1,"TRANSACT2_FINDFIRST",0, + {NULL,NULL,NULL,NULL,trans2_findfirst}}, + +{2,"TRANSACT2_FINDNEXT",0,DEFDESCRIPT}, + +{3,"TRANSACT2_QFSINFO",0, + {NULL,NULL,NULL,NULL,trans2_qfsinfo}}, + +{4,"TRANSACT2_SETFSINFO",0,DEFDESCRIPT}, +{5,"TRANSACT2_QPATHINFO",0,DEFDESCRIPT}, +{6,"TRANSACT2_SETPATHINFO",0,DEFDESCRIPT}, +{7,"TRANSACT2_QFILEINFO",0,DEFDESCRIPT}, +{8,"TRANSACT2_SETFILEINFO",0,DEFDESCRIPT}, +{9,"TRANSACT2_FSCTL",0,DEFDESCRIPT}, +{10,"TRANSACT2_IOCTL",0,DEFDESCRIPT}, +{11,"TRANSACT2_FINDNOTIFYFIRST",0,DEFDESCRIPT}, +{12,"TRANSACT2_FINDNOTIFYNEXT",0,DEFDESCRIPT}, +{13,"TRANSACT2_MKDIR",0,DEFDESCRIPT}, +{-1,NULL,0,DEFDESCRIPT}}; + + +static void print_trans2(uchar *words,uchar *dat,uchar *buf,uchar *maxbuf) +{ + static struct smbfns *fn = &trans2_fns[0]; + uchar *data,*param; + uchar *f1=NULL,*f2=NULL; + int pcnt,dcnt; + + if (request) { + fn = smbfind(SVAL(words+1,14*2),trans2_fns); + data = buf+SVAL(words+1,12*2); + param = buf+SVAL(words+1,10*2); + pcnt = SVAL(words+1,9*2); + dcnt = SVAL(words+1,11*2); + } else { + data = buf+SVAL(words+1,7*2); + param = buf+SVAL(words+1,4*2); + pcnt = SVAL(words+1,3*2); + dcnt = SVAL(words+1,6*2); + } + + printf("%s param_length=%d data_length=%d\n", + fn->name,pcnt,dcnt); + + if (request) { + if (CVAL(words,0) == 8) { + fdata(words+1,"Trans2Secondary\nTotParam=[d]\nTotData=[d]\nParamCnt=[d]\nParamOff=[d]\nParamDisp=[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nHandle=[d]\n",maxbuf); + return; + } else { + fdata(words+1,"TotParam=[d]\nTotData=[d]\nMaxParam=[d]\nMaxData=[d]\nMaxSetup=[d]\nFlags=[w]\nTimeOut=[D]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nDataCnt=[d]\nDataOff=[d]\nSetupCnt=[d]\n",words+1+14*2); + fdata(data+1,"TransactionName=[S]\n%",maxbuf); + } + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; + } else { + if (CVAL(words,0) == 0) { + printf("Trans2Interim\n"); + return; + } else { + fdata(words+1,"TotParam=[d]\nTotData=[d]\nRes1=[w]\nParamCnt=[d]\nParamOff=[d]\nParamDisp[d]\nDataCnt=[d]\nDataOff=[d]\nDataDisp=[d]\nSetupCnt=[d]\n",words+1+10*2); + } + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; + } + + if (fn->descript.fn) { + fn->descript.fn(param,data,pcnt,dcnt); + } else { + fdata(param,f1?f1:(uchar*)"Paramaters=\n",param+pcnt); + fdata(data,f2?f2:(uchar*)"Data=\n",data+dcnt); + } +} + + +static void print_browse(uchar *param,int paramlen,uchar *data,int datalen) +{ + uchar *maxbuf = data + datalen; + int command = CVAL(data,0); + + fdata(param,"BROWSE PACKET\n|Param ",param+paramlen); + + switch (command) { + case 0xF: + data = fdata(data,"BROWSE PACKET:\nType=[B] (LocalMasterAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); + break; + + case 0x1: + data = fdata(data,"BROWSE PACKET:\nType=[B] (HostAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nElectionVersion=[w]\nBrowserConstant=[w]\n",maxbuf); + break; + + case 0x2: + data = fdata(data,"BROWSE PACKET:\nType=[B] (AnnouncementRequest)\nFlags=[B]\nReplySystemName=[S]\n",maxbuf); + break; + + case 0xc: + data = fdata(data,"BROWSE PACKET:\nType=[B] (WorkgroupAnnouncement)\nUpdateCount=[w]\nRes1=[B]\nAnnounceInterval=[d]\nName=[n2]\nMajorVersion=[B]\nMinorVersion=[B]\nServerType=[W]\nCommentPointer=[W]\nServerName=[S]\n",maxbuf); + break; + + case 0x8: + data = fdata(data,"BROWSE PACKET:\nType=[B] (ElectionFrame)\nElectionVersion=[B]\nOSSummary=[W]\nUptime=[(W,W)]\nServerName=[S]\n",maxbuf); + break; + + case 0xb: + data = fdata(data,"BROWSE PACKET:\nType=[B] (BecomeBackupBrowser)\nName=[S]\n",maxbuf); + break; + + case 0x9: + data = fdata(data,"BROWSE PACKET:\nType=[B] (GetBackupList)\nListCount?=[B]\nToken?=[B]\n",maxbuf); + break; + + case 0xa: + data = fdata(data,"BROWSE PACKET:\nType=[B] (BackupListResponse)\nServerCount?=[B]\nToken?=[B]*Name=[S]\n",maxbuf); + break; + + case 0xd: + data = fdata(data,"BROWSE PACKET:\nType=[B] (MasterAnnouncement)\nMasterName=[S]\n",maxbuf); + break; + + case 0xe: + data = fdata(data,"BROWSE PACKET:\nType=[B] (ResetBrowser)\nOptions=[B]\n",maxbuf); + break; + + default: + data = fdata(data,"Unknown Browser Frame ",maxbuf); + break; + } +} + + +static void print_ipc(uchar *param,int paramlen,uchar *data,int datalen) +{ + int command = SVAL(param,0); + if (paramlen) + fdata(param,"Command=[w]\nStr1=[S]\nStr2=[S]\n",param+paramlen); + if (datalen) + fdata(data,"IPC ",data+datalen); +} + + +static void print_trans(uchar *words,uchar *data1,uchar *buf,uchar *maxbuf) +{ + uchar *f1,*f2,*f3,*f4; + uchar *data,*param; + int datalen,paramlen; + int buflen = SVAL(data1,0); + + if (request) { + paramlen = SVAL(words+1,9*2); + param = buf + SVAL(words+1,10*2); + datalen = SVAL(words+1,11*2); + data = buf + SVAL(words+1,12*2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nMaxParmCnt=[d] \nMaxDataCnt=[d]\nMaxSCnt=[d] \nTransFlags=[w] \nRes1=[w] \nRes2=[w] \nRes3=[w]\nParamCnt=[d] \nParamOff=[d] \nDataCnt=[d] \nDataOff=[d] \nSUCnt=[d]\n"; + f2 = "|Name=[S]\n"; + f3 = "|Param "; + f4 = "|Data "; + } else { + paramlen = SVAL(words+1,3*2); + param = buf + SVAL(words+1,4*2); + datalen = SVAL(words+1,6*2); + data = buf + SVAL(words+1,7*2); + f1 = "TotParamCnt=[d] \nTotDataCnt=[d] \nRes1=[d]\nParamCnt=[d] \nParamOff=[d] \nRes2=[d] \nDataCnt=[d] \nDataOff=[d] \nRes3=[d]\nLsetup=[d]\n"; + f2 = "|Unknown "; + f3 = "|Param "; + f4 = "|Data "; + } + + fdata(words+1,f1,MIN(words+1+2*CVAL(words,0),maxbuf)); + fdata(data1+2,f2,maxbuf - (paramlen + datalen)); + + if (!strcmp(data1+2,"\\MAILSLOT\\BROWSE")) { + print_browse(param,paramlen,data,datalen); + return; + } + + if (!strcmp(data1+2,"\\PIPE\\LANMAN")) { + print_ipc(param,paramlen,data,datalen); + return; + } + + if (paramlen) fdata(param,f3,MIN(param+paramlen,maxbuf)); + if (datalen) fdata(data,f4,MIN(data+datalen,maxbuf)); +} + + + +void print_negprot(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) +{ + uchar *f1=NULL,*f2=NULL; + + if (request) { + f2 = "*|Dialect=[Z]\n"; + } else { + if (CVAL(words,0) == 1) { + f1 = "Core Protocol\nDialectIndex=[d]"; + } else if (CVAL(words,0) == 17) { + f1 = "NT1 Protocol\nDialectIndex=[d]\nSecMode=[B]\nMaxMux=[d]\nNumVcs=[d]\nMaxBuffer=[D]\nRawSize=[D]\nSessionKey=[W]\nCapabilities=[W]\nServerTime=[T3]TimeZone=[d]\nCryptKey="; + } else if (CVAL(words,0) == 13) { + f1 = "Coreplus/Lanman1/Lanman2 Protocol\nDialectIndex=[d]\nSecMode=[w]\nMaxXMit=[d]\nMaxMux=[d]\nMaxVcs=[d]\nBlkMode=[w]\nSessionKey=[W]\nServerTime=[T1]TimeZone=[d]\nRes=[W]\nCryptKey="; + } + } + + if (f1) + fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); + else + print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); + + if (f2) + fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); + else + print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); + +} + +void print_sesssetup(uchar *words,uchar *data,uchar *buf,uchar *maxbuf) +{ + int wcnt = CVAL(words,0); + uchar *f1=NULL,*f2=NULL; + + if (request) { + if (wcnt==10) { + f1 = "Com2=[w]\nOff2=[d]\nBufSize=[d]\nMpxMax=[d]\nVcNum=[d]\nSessionKey=[W]\nPassLen=[d]\nCryptLen=[d]\nCryptOff=[d]\nPass&Name=\n"; + } else { + f1 = "Com2=[B]\nRes1=[B]\nOff2=[d]\nMaxBuffer=[d]\nMaxMpx=[d]\nVcNumber=[d]\nSessionKey=[W]\nCaseInsensitivePasswordLength=[d]\nCaseSensitivePasswordLength=[d]\nRes=[W]\nCapabilities=[W]\nPass1&Pass2&Account&Domain&OS&LanMan=\n"; + } + } else { + if (CVAL(words,0) == 3) { + f1 = "Com2=[w]\nOff2=[d]\nAction=[w]\n"; + } else if (CVAL(words,0) == 13) { + f1 = "Com2=[B]\nRes=[B]\nOff2=[d]\nAction=[w]\n"; + f2 = "NativeOS=[S]\nNativeLanMan=[S]\nPrimaryDomain=[S]\n"; + } + } + + if (f1) + fdata(words+1,f1,MIN(words + 1 + CVAL(words,0)*2,maxbuf)); + else + print_data(words+1,MIN(CVAL(words,0)*2,PTR_DIFF(maxbuf,words+1))); + + if (f2) + fdata(data+2,f2,MIN(data + 2 + SVAL(data,0),maxbuf)); + else + print_data(data+2,MIN(SVAL(data,0),PTR_DIFF(maxbuf,data+2))); +} + + +static struct smbfns smb_fns[] = +{ +{-1,"SMBunknown",0,DEFDESCRIPT}, + +{SMBtcon,"SMBtcon",0, + {NULL,"Path=[Z]\nPassword=[Z]\nDevice=[Z]\n", + "MaxXmit=[d]\nTreeId=[d]\n",NULL, + NULL}}, + + +{SMBtdis,"SMBtdis",0,DEFDESCRIPT}, +{SMBexit,"SMBexit",0,DEFDESCRIPT}, +{SMBioctl,"SMBioctl",0,DEFDESCRIPT}, + +{SMBecho,"SMBecho",0, + {"ReverbCount=[d]\n",NULL, + "SequenceNum=[d]\n",NULL, + NULL}}, + +{SMBulogoffX, "SMBulogoffX",FLG_CHAIN,DEFDESCRIPT}, + +{SMBgetatr,"SMBgetatr",0, + {NULL,"Path=[Z]\n", + "Attribute=[A]\nTime=[T2]Size=[D]\nRes=([w,w,w,w,w])\n",NULL, + NULL}}, + +{SMBsetatr,"SMBsetatr",0, + {"Attribute=[A]\nTime=[T2]Res=([w,w,w,w,w])\n","Path=[Z]\n", + NULL,NULL,NULL}}, + +{SMBchkpth,"SMBchkpth",0, + {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + +{SMBsearch,"SMBsearch",0, +{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\n", +"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + + +{SMBopen,"SMBopen",0, + {"Mode=[w]\nAttribute=[A]\n","Path=[Z]\n", + "Handle=[d]\nOAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\n",NULL, + NULL}}, + +{SMBcreate,"SMBcreate",0, + {"Attrib=[A]\nTime=[T2]","Path=[Z]\n", + "Handle=[d]\n",NULL, + NULL}}, + +{SMBmknew,"SMBmknew",0, + {"Attrib=[A]\nTime=[T2]","Path=[Z]\n", + "Handle=[d]\n",NULL, + NULL}}, + +{SMBunlink,"SMBunlink",0, + {"Attrib=[A]\n","Path=[Z]\n",NULL,NULL,NULL}}, + +{SMBread,"SMBread",0, + {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, + "Count=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, + +{SMBwrite,"SMBwrite",0, + {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, + "Count=[d]\n",NULL,NULL}}, + +{SMBclose,"SMBclose",0, + {"Handle=[d]\nTime=[T2]",NULL,NULL,NULL,NULL}}, + +{SMBmkdir,"SMBmkdir",0, + {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + +{SMBrmdir,"SMBrmdir",0, + {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + +{SMBdskattr,"SMBdskattr",0, +{NULL,NULL, +"TotalUnits=[d]\nBlocksPerUnit=[d]\nBlockSize=[d]\nFreeUnits=[d]\nMedia=[w]\n", +NULL,NULL}}, + +{SMBmv,"SMBmv",0, + {"Attrib=[A]\n","OldPath=[Z]\nNewPath=[Z]\n",NULL,NULL,NULL}}, + +/* this is a Pathworks specific call, allowing the + changing of the root path */ +{pSETDIR,"SMBsetdir",0, + {NULL,"Path=[Z]\n",NULL,NULL,NULL}}, + +{SMBlseek,"SMBlseek",0, + {"Handle=[d]\nMode=[w]\nOffset=[D]\n","Offset=[D]\n",NULL,NULL}}, + +{SMBflush,"SMBflush",0, + {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBsplopen,"SMBsplopen",0, + {"SetupLen=[d]\nMode=[w]\n","Ident=[Z]\n","Handle=[d]\n",NULL,NULL}}, + +{SMBsplclose,"SMBsplclose",0, + {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBsplretq,"SMBsplretq",0, + {"MaxCount=[d]\nStartIndex=[d]\n",NULL, + "Count=[d]\nIndex=[d]\n", + "*Time=[T2]Status=[B]\nJobID=[d]\nSize=[D]\nRes=[B]Name=[s16]\n", + NULL}}, + +{SMBsplwr,"SMBsplwr",0, + {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBlock,"SMBlock",0, + {"Handle=[d]\nCount=[D]\nOffset=[D]\n",NULL,NULL,NULL,NULL}}, + +{SMBunlock,"SMBunlock",0, + {"Handle=[d]\nCount=[D]\nOffset=[D]\n",NULL,NULL,NULL,NULL}}, + +/* CORE+ PROTOCOL FOLLOWS */ + +{SMBreadbraw,"SMBreadbraw",0, +{"Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[d]\n", + NULL,NULL,NULL,NULL}}, + +{SMBwritebraw,"SMBwritebraw",0, +{"Handle=[d]\nTotalCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\n|DataSize=[d]\nDataOff=[d]\n", +NULL,"WriteRawAck",NULL,NULL}}, + +{SMBwritec,"SMBwritec",0, + {NULL,NULL,"Count=[d]\n",NULL,NULL}}, + +{SMBwriteclose,"SMBwriteclose",0, + {"Handle=[d]\nCount=[d]\nOffset=[D]\nTime=[T2]Res=([w,w,w,w,w,w])",NULL, + "Count=[d]\n",NULL,NULL}}, + +{SMBlockread,"SMBlockread",0, + {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, + "Count=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, + +{SMBwriteunlock,"SMBwriteunlock",0, + {"Handle=[d]\nByteCount=[d]\nOffset=[D]\nCountLeft=[d]\n",NULL, + "Count=[d]\n",NULL,NULL}}, + +{SMBreadBmpx,"SMBreadBmpx",0, +{"Handle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nRes=[w]\n", +NULL, +"Offset=[D]\nTotCount=[d]\nRemaining=[d]\nRes=([w,w])\nDataSize=[d]\nDataOff=[d]\n", +NULL,NULL}}, + +{SMBwriteBmpx,"SMBwriteBmpx",0, +{"Handle=[d]\nTotCount=[d]\nRes=[w]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nRes2=[W]\nDataSize=[d]\nDataOff=[d]\n",NULL, +"Remaining=[d]\n",NULL,NULL}}, + +{SMBwriteBs,"SMBwriteBs",0, + {"Handle=[d]\nTotCount=[d]\nOffset=[D]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\n",NULL, + "Count=[d]\n",NULL,NULL}}, + +{SMBsetattrE,"SMBsetattrE",0, + {"Handle=[d]\nCreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]",NULL, + NULL,NULL,NULL}}, + +{SMBgetattrE,"SMBgetattrE",0, +{"Handle=[d]\n",NULL, + "CreationTime=[T2]AccessTime=[T2]ModifyTime=[T2]Size=[D]\nAllocSize=[D]\nAttribute=[A]\n",NULL,NULL}}, + +{SMBtranss,"SMBtranss",0,DEFDESCRIPT}, +{SMBioctls,"SMBioctls",0,DEFDESCRIPT}, + +{SMBcopy,"SMBcopy",0, + {"TreeID2=[d]\nOFun=[w]\nFlags=[w]\n","Path=[S]\nNewPath=[S]\n", + "CopyCount=[d]\n","|ErrStr=[S]\n",NULL}}, + +{SMBmove,"SMBmove",0, + {"TreeID2=[d]\nOFun=[w]\nFlags=[w]\n","Path=[S]\nNewPath=[S]\n", + "MoveCount=[d]\n","|ErrStr=[S]\n",NULL}}, + +{SMBopenX,"SMBopenX",FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nFlags=[w]\nMode=[w]\nSearchAttrib=[A]\nAttrib=[A]\nTime=[T2]OFun=[w]\nSize=[D]\nTimeOut=[D]\nRes=[W]\n","Path=[S]\n", +"Com2=[w]\nOff2=[d]\nHandle=[d]\nAttrib=[A]\nTime=[T2]Size=[D]\nAccess=[w]\nType=[w]\nState=[w]\nAction=[w]\nFileID=[W]\nRes=[w]\n",NULL,NULL}}, + +{SMBreadX,"SMBreadX",FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nMaxCount=[d]\nMinCount=[d]\nTimeOut=[D]\nCountLeft=[d]\n",NULL, +"Com2=[w]\nOff2=[d]\nRemaining=[d]\nRes=[W]\nDataSize=[d]\nDataOff=[d]\nRes=([w,w,w,w])\n",NULL,NULL}}, + +{SMBwriteX,"SMBwriteX",FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nHandle=[d]\nOffset=[D]\nTimeOut=[D]\nWMode=[w]\nCountLeft=[d]\nRes=[w]\nDataSize=[d]\nDataOff=[d]\n",NULL, +"Com2=[w]\nOff2=[d]\nCount=[d]\nRemaining=[d]\nRes=[W]\n",NULL,NULL}}, + +{SMBlockingX,"SMBlockingX",FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nHandle=[d]\nLockType=[w]\nTimeOut=[D]\nUnlockCount=[d]\nLockCount=[d]\n", +"*Process=[d]\nOffset=[D]\nLength=[D]\n", +"Com2=[w]\nOff2=[d]\n"}}, + +{SMBffirst,"SMBffirst",0, +{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", +"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + +{SMBfunique,"SMBfunique",0, +{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", +"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + +{SMBfclose,"SMBfclose",0, +{"Count=[d]\nAttrib=[A]\n","Path=[Z]\nBlkType=[B]\nBlkLen=[d]\n|Res1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\n", +"Count=[d]\n","BlkType=[B]\nBlkLen=[d]\n*\nRes1=[B]\nMask=[s11]\nSrv1=[B]\nDirIndex=[d]\nSrv2=[w]\nRes2=[W]\nAttrib=[a]\nTime=[T1]Size=[D]\nName=[s13]\n",NULL}}, + +{SMBfindnclose, "SMBfindnclose", 0, + {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBfindclose, "SMBfindclose", 0, + {"Handle=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBsends,"SMBsends",0, + {NULL,"Source=[Z]\nDest=[Z]\n",NULL,NULL,NULL}}, + +{SMBsendstrt,"SMBsendstrt",0, + {NULL,"Source=[Z]\nDest=[Z]\n","GroupID=[d]\n",NULL,NULL}}, + +{SMBsendend,"SMBsendend",0, + {"GroupID=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBsendtxt,"SMBsendtxt",0, + {"GroupID=[d]\n",NULL,NULL,NULL,NULL}}, + +{SMBsendb,"SMBsendb",0, + {NULL,"Source=[Z]\nDest=[Z]\n",NULL,NULL,NULL}}, + +{SMBfwdname,"SMBfwdname",0,DEFDESCRIPT}, +{SMBcancelf,"SMBcancelf",0,DEFDESCRIPT}, +{SMBgetmac,"SMBgetmac",0,DEFDESCRIPT}, + +{SMBnegprot,"SMBnegprot",0, + {NULL,NULL,NULL,NULL,print_negprot}}, + +{SMBsesssetupX,"SMBsesssetupX",FLG_CHAIN, + {NULL,NULL,NULL,NULL,print_sesssetup}}, + +{SMBtconX,"SMBtconX",FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nFlags=[w]\nPassLen=[d]\nPasswd&Path&Device=\n",NULL, + "Com2=[w]\nOff2=[d]\n","ServiceType=[S]\n",NULL}}, + +{SMBtrans2, "SMBtrans2",0,{NULL,NULL,NULL,NULL,print_trans2}}, + +{SMBtranss2, "SMBtranss2", 0,DEFDESCRIPT}, +{SMBctemp,"SMBctemp",0,DEFDESCRIPT}, +{SMBreadBs,"SMBreadBs",0,DEFDESCRIPT}, +{SMBtrans,"SMBtrans",0,{NULL,NULL,NULL,NULL,print_trans}}, + +{SMBnttrans,"SMBnttrans", 0, DEFDESCRIPT}, +{SMBnttranss,"SMBnttranss", 0, DEFDESCRIPT}, + +{SMBntcreateX,"SMBntcreateX", FLG_CHAIN, +{"Com2=[w]\nOff2=[d]\nRes=[b]\nNameLen=[d]\nFlags=[W]\nRootDirectoryFid=[D]\nAccessMask=[W]\nAllocationSize=[L]\nExtFileAttributes=[W]\nShareAccess=[W]\nCreateDisposition=[W]\nCreateOptions=[W]\nImpersonationLevel=[W]\nSecurityFlags=[b]\n","Path=[S]\n", + "Com2=[w]\nOff2=[d]\nOplockLevel=[b]\nFid=[d]\nCreateAction=[W]\nCreateTime=[T3]LastAccessTime=[T3]LastWriteTime=[T3]ChangeTime=[T3]ExtFileAttributes=[W]\nAllocationSize=[L]\nEndOfFile=[L]\nFileType=[w]\nDeviceState=[w]\nDirectory=[b]\n", NULL}}, + +{SMBntcancel,"SMBntcancel", 0, DEFDESCRIPT}, + +{-1,NULL,0,DEFDESCRIPT}}; + + +/******************************************************************* +print a SMB message +********************************************************************/ +void print_smb(uchar *buf,uchar *maxbuf) +{ + int command; + uchar *words, *data; + struct smbfns *fn; + char *fmt_smbheader = +"[P4]SMB Command = [B]\nError class = [BP1]\nError code = [d]\nFlags1 = [B]\nFlags2 = [B][P13]\nTree ID = [d]\nProc ID = [d]\nUID = [d]\nMID = [d]\nWord Count = [b]\n"; + + request = (CVAL(buf,9)&0x80)?0:1; + + command = CVAL(buf,4); + + fn = smbfind(command,smb_fns); + + printf("\nSMB PACKET: %s (%s)\n",fn->name,request?"REQUEST":"REPLY"); + + /* print out the header */ + fdata(buf,fmt_smbheader,buf+33); + + if (CVAL(buf,5)) { + int class = CVAL(buf,5); + int num = SVAL(buf,7); + printf("SMBError = %s\n",smb_errstr(class,num)); + } + + words = buf+32; + data = words + 1 + CVAL(words,0)*2; + + + while (words && data) + { + char *f1,*f2; + int wct = CVAL(words,0); + + if (request) { + f1 = fn->descript.req_f1; + f2 = fn->descript.req_f2; + } else { + f1 = fn->descript.rep_f1; + f2 = fn->descript.rep_f2; + } + + if (fn->descript.fn) { + fn->descript.fn(words,data,buf,maxbuf); + } else { + if (f1) { + printf("smbvwv[]=\n"); + fdata(words+1,f1,words + 1 + wct*2); + } else if (wct) { + int i; + int v; + printf("smbvwv[]=\n"); + for (i=0;i0) { + printf("smb_buf[]=\n"); + print_data(data+2,MIN(bcc,PTR_DIFF(maxbuf,data+2))); + } + } + } + + if ((fn->flags & FLG_CHAIN) && CVAL(words,0) && SVAL(words,1)!=0xFF) { + command = SVAL(words,1); + words = buf + SVAL(words,3); + data = words + 1 + CVAL(words,0)*2; + + fn = smbfind(command,smb_fns); + + printf("\nSMB PACKET: %s (%s) (CHAINED)\n",fn->name,request?"REQUEST":"REPLY"); + } else { + words = data = NULL; + } + } + + printf("\n"); +} + + +/* + print a NBT packet received across tcp on port 139 +*/ +void nbt_tcp_print(uchar *data,uchar *maxbuf) +{ + int flags = CVAL(data,0); + int nbt_len = RSVAL(data,2); + startbuf = data; + if (maxbuf <= data) return; + + printf("\n>>> NBT Packet\n"); + + switch (flags) { + case 1: + printf("flags=0x%x\n", flags); + case 0: + data = fdata(data,"NBT Session Packet\nFlags=[rw]\nLength=[rd]\n",data+4); + if (memcmp(data,"\377SMB",4)==0) { + if (nbt_len>PTR_DIFF(maxbuf,data)) + printf("WARNING: Short packet. Try increasing the snap length (%d)\n", + PTR_DIFF(maxbuf,data)); + print_smb(data,maxbuf>data+nbt_len?data+nbt_len:maxbuf); + } else { + printf("Session packet:(raw data?)\n"); + } + break; + + case 0x81: + data = fdata(data,"NBT Session Request\nFlags=[rW]\nDestination=[n1]\nSource=[n1]\n",maxbuf); + break; + + case 0x82: + data = fdata(data,"NBT Session Granted\nFlags=[rW]\n",maxbuf); + break; + + case 0x83: + { + int ecode = CVAL(data,4); + data = fdata(data,"NBT SessionReject\nFlags=[rW]\nReason=[B]\n",maxbuf); + switch (ecode) { + case 0x80: + printf("Not listening on called name\n"); + break; + case 0x81: + printf("Not listening for calling name\n"); + break; + case 0x82: + printf("Called name not present\n"); + break; + case 0x83: + printf("Called name present, but insufficient resources\n"); + break; + default: + printf("Unspecified error 0x%X\n",ecode); + break; + } + } + break; + + case 0x85: + data = fdata(data,"NBT Session Keepalive\nFlags=[rW]\n",maxbuf); + break; + + default: + printf("flags=0x%x\n", flags); + data = fdata(data,"NBT - Unknown packet type\nType=[rW]\n",maxbuf); + } + printf("\n"); + fflush(stdout); +} + + +/* + print a NBT packet received across udp on port 137 +*/ +void nbt_udp137_print(uchar *data,uchar *maxbuf) +{ + int name_trn_id = RSVAL(data,0); + int response = (CVAL(data,2)>>7); + int opcode = (CVAL(data,2) >> 3) & 0xF; + int nm_flags = ((CVAL(data,2) & 0x7) << 4) + (CVAL(data,3)>>4); + int rcode = CVAL(data,3) & 0xF; + int qdcount = RSVAL(data,4); + int ancount = RSVAL(data,6); + int nscount = RSVAL(data,8); + int arcount = RSVAL(data,10); + char des[1024]; + char *opcodestr="OPUNKNOWN"; + char *p; + + startbuf = data; + + if (maxbuf <= data) return; + + strcpy(des,"\n>>> NBT UDP PACKET(137): "); + + switch (opcode) { + case 0: opcodestr = "QUERY"; break; + case 5: opcodestr = "REGISTRATION"; break; + case 6: opcodestr = "RELEASE"; break; + case 7: opcodestr = "WACK"; break; + case 8: opcodestr = "REFRESH(8)"; break; + case 9: opcodestr = "REFRESH"; break; + } + strcat(des,opcodestr); + if (response) { + if (rcode) + strcat(des,"; NEGATIVE"); + else + strcat(des,"; POSITIVE"); + } + + if (response) + strcat(des,"; RESPONSE"); + else + strcat(des,"; REQUEST"); + + if (nm_flags&1) + strcat(des,"; BROADCAST"); + else + strcat(des,"; UNICAST"); + + printf("%s\nTrnID=0x%X\nOpCode=%d\nNmFlags=0x%X\nRcode=%d\nQueryCount=%d\nAnswerCount=%d\nAuthorityCount=%d\nAddressRecCount=%d\n", + des,name_trn_id,opcode,nm_flags,rcode,qdcount,ancount,nscount,arcount); + + p = data + 12; + + { + int total = ancount+nscount+arcount; + int i; + + if (qdcount>100 || total>100) { + printf("Corrupt packet??\n"); + return; + } + + if (qdcount) { + printf("QuestionRecords:\n"); + for (i=0;i "); + if (p[0] & 0x60 == 0) strcat(flags,"B "); + if (p[0] & 0x60 == 1) strcat(flags,"P "); + if (p[0] & 0x60 == 2) strcat(flags,"M "); + if (p[0] & 0x60 == 3) strcat(flags,"_ "); + if (p[0] & 0x10) strcat(flags," "); + if (p[0] & 0x08) strcat(flags," "); + if (p[0] & 0x04) strcat(flags," "); + if (p[0] & 0x02) strcat(flags," "); + printf("%s\n",flags); + p += 2; + } + } else { + print_data(p,rdlen); + p += rdlen; + } + } + } + } + } + + if ((uchar*)p < maxbuf) { + fdata(p,"AdditionalData:\n",maxbuf); + } + + printf("\n"); + fflush(stdout); +} + + + +/* + print a NBT packet received across udp on port 138 +*/ +void nbt_udp138_print(uchar *data,uchar *maxbuf) +{ + startbuf = data; + if (maxbuf <= data) return; + + data = fdata(data,"\n>>> NBT UDP PACKET(138) Res=[rw] ID=[rw] IP=[b.b.b.b] Port=[rd] Length=[rd] Res2=[rw]\nSourceName=[n1]\nDestName=[n1]\n#",maxbuf); + + print_smb(data,maxbuf); + + printf("\n"); + fflush(stdout); +} + + + +/* + print netbeui frames +*/ +void netbeui_print(uchar *data,uchar *maxbuf) +{ + int len = SVAL(data,1); + int command = CVAL(data,5); + uchar *data2 = data + 1 + len; + + startbuf = data; + + data = fdata(data,"\n>>> NetBeui Packet\nType=[B] Length=[d] Signature=[w] Command=[B]\n#",maxbuf); + + switch (command) { + case 0xA: + data = fdata(data,"NameQuery:[P1]\nSessionNumber=[B]\nNameType=[B][P2]\nResponseCorrelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0x8: + data = fdata(data,"NetbiosDataGram:[P7]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0xE: + data = fdata(data,"NameRecognise:\n[P1]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nDestination=[n2]\nSource=[n2]\n",data2); + break; + + case 0x19: + data = fdata(data,"SessionInitialise:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x17: + data = fdata(data,"SessionConfirm:\nData1=[B]\nData2=[w]\nTransmitCorrelator=[w]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x16: + data = fdata(data,"NetbiosDataOnlyLast:\nFlags=[{|NO_ACK|PIGGYBACK_ACK_ALLOWED|PIGGYBACK_ACK_INCLUDED|}]\nResyncIndicator=[w][P2]\nResponseCorelator=[w]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x14: + data = fdata(data,"NetbiosDataAck:\n[P3]TransmitCorrelator=[w][P2]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + case 0x18: + data = fdata(data,"SessionEnd:\n[P1]Data2=[w][P4]\nRemoteSessionNumber=[B]\nLocalSessionNumber=[B]\n",data2); + break; + + default: + data = fdata(data,"Unknown Netbios Command ",data2); + break; + } + + if (memcmp(data2,"\377SMB",4)==0) { + print_smb(data2,maxbuf); + } else { + int i; + for (i=0;i<128;i++) { + if (memcmp(&data2[i],"\377SMB",4)==0) { + printf("found SMB packet at %d\n", i); + print_smb(&data2[i],maxbuf); + break; + } + } + } + + printf("\n"); +} + + +/* + print IPX-Netbios frames +*/ +void ipx_netbios_print(uchar *data,uchar *maxbuf) +{ + /* this is a hack till I work out how to parse the rest of the IPX stuff */ + int i; + startbuf = data; + for (i=0;i<128;i++) + if (memcmp(&data[i],"\377SMB",4)==0) { + fdata(data,"\n>>> IPX transport ",&data[i]); + print_smb(&data[i],maxbuf); + printf("\n"); + fflush(stdout); + break; + } + if (i==128) + fdata(data,"\n>>> Unknown IPX ",maxbuf); +} diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/print-tcp.c ./print-tcp.c --- /usr/src/redhat/tcpdump-3.4.orig/print-tcp.c Sun Jun 6 00:00:24 1999 +++ ./print-tcp.c Mon Jun 28 22:03:34 1999 @@ -96,6 +96,8 @@ static struct tcp_seq_hash tcp_seq_hash[TSEQ_HASHSIZE]; +#define NETBIOS_SSN_PORT 139 + void tcp_print(register const u_char *bp, register u_int length, register const u_char *bp2) @@ -367,6 +369,28 @@ } putchar('>'); } + + /* check for specific tcp-based protocols. This will never be + perfect because of the stream nature of tcp but in practice + it does pretty well */ + if (!qflag) { +#define ISPORT(p) (dport == (p) || sport == (p)) + + u_char *data = (u_char *)(tp) + tp->th_off*4; + u_char *data_end; + + if (length < snaplen - sizeof(*tp)) + data_end = data + length; + else + data_end = data + snaplen - sizeof(*tp); + + if (ISPORT(NETBIOS_SSN_PORT)) { + /* netbios-ssn packets, as used for file + sharing by SMB (in for example, windows) */ + nbt_tcp_print(data, data_end); + } + } + return; bad: fputs("[bad opt]", stdout); diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/print-tcp.c.orig ./print-tcp.c.orig --- /usr/src/redhat/tcpdump-3.4.orig/print-tcp.c.orig Mon Jun 16 06:20:28 1997 +++ ./print-tcp.c.orig Sat Apr 17 11:15:17 1999 @@ -106,8 +106,8 @@ register int hlen; register char ch; u_short sport, dport, win, urp; - u_int32_t seq, ack; - + u_int32_t seq, ack,thseq,thack; + int threv; tp = (struct tcphdr *)bp; ip = (struct ip *)bp2; ch = '\0'; @@ -165,7 +165,7 @@ tha.port = dport << 16 | sport; rev = 1; } - + threv = rev; for (th = &tcp_seq_hash[tha.port % TSEQ_HASHSIZE]; th->nxt; th = th->nxt) if (!memcmp((char *)&tha, (char *)&th->addr, @@ -186,6 +186,10 @@ else th->seq = seq, th->ack = ack - 1; } else { + + thseq = th->seq; + thack = th->ack; + if (rev) seq -= th->ack, ack -= th->seq; else @@ -266,18 +270,32 @@ break; case TCPOPT_SACK: - (void)printf("sack"); - datalen = len - 2; - for (i = 0; i < datalen; i += 4) { - LENCHECK(i + 4); - /* block-size@relative-origin */ - (void)printf(" %u@%u", - EXTRACT_16BITS(cp + i + 2), - EXTRACT_16BITS(cp + i)); + { + u_int32_t s, e; + + datalen = len - 2; + if (datalen % 8 != 0) { + (void)printf(" malformed sack "); + } else { + (void)printf(" sack %d ", datalen / 8); + for (i = 0; i < datalen; i += 8) { + LENCHECK(i + 4); + s = EXTRACT_32BITS(cp + i); + LENCHECK(i + 8); + e = EXTRACT_32BITS(cp + i + 4); + if (threv) { + s -= thseq; + e -= thseq; + } else { + s -= thack; + e -= thack; + } + (void)printf("{%u:%u}", s, e); } - if (datalen % 4) - (void)printf("[len %d]", len); - break; + (void)printf(" "); + } + break; + } case TCPOPT_ECHO: (void)printf("echo"); diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/print-udp.c ./print-udp.c --- /usr/src/redhat/tcpdump-3.4.orig/print-udp.c Mon Jul 28 14:58:57 1997 +++ ./print-udp.c Sat Apr 17 11:15:17 1999 @@ -293,6 +293,8 @@ #define SNMPTRAP_PORT 162 /*XXX*/ #define RIP_PORT 520 /*XXX*/ #define KERBEROS_SEC_PORT 750 /*XXX*/ +#define NETBIOS_NS_PORT 137 +#define NETBIOS_DGRAM_PORT 138 void udp_print(register const u_char *bp, u_int length, register const u_char *bp2) @@ -434,6 +436,14 @@ krb_print((const void *)(up + 1), length); else if (dport == 3456) vat_print((const void *)(up + 1), length, up); + else if (ISPORT(NETBIOS_NS_PORT)) { + unsigned char *data = (unsigned char *)(up + 1); + nbt_udp137_print(data,data+length>snapend?snapend:data+length); + } + else if (ISPORT(NETBIOS_DGRAM_PORT)) { + unsigned char *data = (unsigned char *)(up + 1); + nbt_udp138_print(data,data+length>snapend?snapend:data+length); + } /* * Kludge in test for whiteboard packets. */ diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/smb.h ./smb.h --- /usr/src/redhat/tcpdump-3.4.orig/smb.h Thu Jan 1 10:00:00 1970 +++ ./smb.h Tue Jun 8 23:28:56 1999 @@ -0,0 +1,163 @@ +/* + Copyright (C) Andrew Tridgell 1995 + + This program is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software + Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. +*/ + +#define CVAL(buf,pos) (((unsigned char *)(buf))[pos]) +#define PVAL(buf,pos) ((unsigned)CVAL(buf,pos)) +#define SCVAL(buf,pos,val) (CVAL(buf,pos) = (val)) + +#define SVAL(buf,pos) (PVAL(buf,pos)|PVAL(buf,(pos)+1)<<8) +#define IVAL(buf,pos) (SVAL(buf,pos)|SVAL(buf,(pos)+2)<<16) +#define SSVALX(buf,pos,val) (CVAL(buf,pos)=(val)&0xFF,CVAL(buf,pos+1)=(val)>>8) +#define SIVALX(buf,pos,val) (SSVALX(buf,pos,val&0xFFFF),SSVALX(buf,pos+2,val>>16)) +#define SVALS(buf,pos) ((int16)SVAL(buf,pos)) +#define IVALS(buf,pos) ((int32)IVAL(buf,pos)) +#define SSVAL(buf,pos,val) SSVALX((buf),(pos),((uint16)(val))) +#define SIVAL(buf,pos,val) SIVALX((buf),(pos),((uint32)(val))) +#define SSVALS(buf,pos,val) SSVALX((buf),(pos),((int16)(val))) +#define SIVALS(buf,pos,val) SIVALX((buf),(pos),((int32)(val))) + +/* now the reverse routines - these are used in nmb packets (mostly) */ +#define SREV(x) ((((x)&0xFF)<<8) | (((x)>>8)&0xFF)) +#define IREV(x) ((SREV(x)<<16) | (SREV((x)>>16))) + +#define RSVAL(buf,pos) SREV(SVAL(buf,pos)) +#define RIVAL(buf,pos) IREV(IVAL(buf,pos)) +#define RSSVAL(buf,pos,val) SSVAL(buf,pos,SREV(val)) +#define RSIVAL(buf,pos,val) SIVAL(buf,pos,IREV(val)) + +#define uint16 unsigned short +#define uint32 unsigned int +#ifndef uchar +#define uchar unsigned char +#endif + +#ifndef MIN +#define MIN(a,b) ((a)<(b)?(a):(b)) +#endif + +/* the complete */ +#define SMBmkdir 0x00 /* create directory */ +#define SMBrmdir 0x01 /* delete directory */ +#define SMBopen 0x02 /* open file */ +#define SMBcreate 0x03 /* create file */ +#define SMBclose 0x04 /* close file */ +#define SMBflush 0x05 /* flush file */ +#define SMBunlink 0x06 /* delete file */ +#define SMBmv 0x07 /* rename file */ +#define SMBgetatr 0x08 /* get file attributes */ +#define SMBsetatr 0x09 /* set file attributes */ +#define SMBread 0x0A /* read from file */ +#define SMBwrite 0x0B /* write to file */ +#define SMBlock 0x0C /* lock byte range */ +#define SMBunlock 0x0D /* unlock byte range */ +#define SMBctemp 0x0E /* create temporary file */ +#define SMBmknew 0x0F /* make new file */ +#define SMBchkpth 0x10 /* check directory path */ +#define SMBexit 0x11 /* process exit */ +#define SMBlseek 0x12 /* seek */ +#define SMBtcon 0x70 /* tree connect */ +#define SMBtconX 0x75 /* tree connect and X*/ +#define SMBtdis 0x71 /* tree disconnect */ +#define SMBnegprot 0x72 /* negotiate protocol */ +#define SMBdskattr 0x80 /* get disk attributes */ +#define SMBsearch 0x81 /* search directory */ +#define SMBsplopen 0xC0 /* open print spool file */ +#define SMBsplwr 0xC1 /* write to print spool file */ +#define SMBsplclose 0xC2 /* close print spool file */ +#define SMBsplretq 0xC3 /* return print queue */ +#define SMBsends 0xD0 /* send single block message */ +#define SMBsendb 0xD1 /* send broadcast message */ +#define SMBfwdname 0xD2 /* forward user name */ +#define SMBcancelf 0xD3 /* cancel forward */ +#define SMBgetmac 0xD4 /* get machine name */ +#define SMBsendstrt 0xD5 /* send start of multi-block message */ +#define SMBsendend 0xD6 /* send end of multi-block message */ +#define SMBsendtxt 0xD7 /* send text of multi-block message */ + +/* Core+ protocol */ +#define SMBlockread 0x13 /* Lock a range and read */ +#define SMBwriteunlock 0x14 /* Unlock a range then write */ +#define SMBreadbraw 0x1a /* read a block of data with no smb header */ +#define SMBwritebraw 0x1d /* write a block of data with no smb header */ +#define SMBwritec 0x20 /* secondary write request */ +#define SMBwriteclose 0x2c /* write a file then close it */ + +/* dos extended protocol */ +#define SMBreadBraw 0x1A /* read block raw */ +#define SMBreadBmpx 0x1B /* read block multiplexed */ +#define SMBreadBs 0x1C /* read block (secondary response) */ +#define SMBwriteBraw 0x1D /* write block raw */ +#define SMBwriteBmpx 0x1E /* write block multiplexed */ +#define SMBwriteBs 0x1F /* write block (secondary request) */ +#define SMBwriteC 0x20 /* write complete response */ +#define SMBsetattrE 0x22 /* set file attributes expanded */ +#define SMBgetattrE 0x23 /* get file attributes expanded */ +#define SMBlockingX 0x24 /* lock/unlock byte ranges and X */ +#define SMBtrans 0x25 /* transaction - name, bytes in/out */ +#define SMBtranss 0x26 /* transaction (secondary request/response) */ +#define SMBioctl 0x27 /* IOCTL */ +#define SMBioctls 0x28 /* IOCTL (secondary request/response) */ +#define SMBcopy 0x29 /* copy */ +#define SMBmove 0x2A /* move */ +#define SMBecho 0x2B /* echo */ +#define SMBopenX 0x2D /* open and X */ +#define SMBreadX 0x2E /* read and X */ +#define SMBwriteX 0x2F /* write and X */ +#define SMBsesssetupX 0x73 /* Session Set Up & X (including User Logon) */ +#define SMBffirst 0x82 /* find first */ +#define SMBfunique 0x83 /* find unique */ +#define SMBfclose 0x84 /* find close */ +#define SMBinvalid 0xFE /* invalid command */ + +/* Extended 2.0 protocol */ +#define SMBtrans2 0x32 /* TRANS2 protocol set */ +#define SMBtranss2 0x33 /* TRANS2 protocol set, secondary command */ +#define SMBfindclose 0x34 /* Terminate a TRANSACT2_FINDFIRST */ +#define SMBfindnclose 0x35 /* Terminate a TRANSACT2_FINDNOTIFYFIRST */ +#define SMBulogoffX 0x74 /* user logoff */ + +/* NT SMB extensions. */ +#define SMBnttrans 0xA0 /* NT transact */ +#define SMBnttranss 0xA1 /* NT transact secondary */ +#define SMBntcreateX 0xA2 /* NT create and X */ +#define SMBntcancel 0xA4 /* NT cancel */ + +/* pathworks special */ +#define pSETDIR '\377' + + +/* these are the TRANS2 sub commands */ +#define TRANSACT2_OPEN 0 +#define TRANSACT2_FINDFIRST 1 +#define TRANSACT2_FINDNEXT 2 +#define TRANSACT2_QFSINFO 3 +#define TRANSACT2_SETFSINFO 4 +#define TRANSACT2_QPATHINFO 5 +#define TRANSACT2_SETPATHINFO 6 +#define TRANSACT2_QFILEINFO 7 +#define TRANSACT2_SETFILEINFO 8 +#define TRANSACT2_FSCTL 9 +#define TRANSACT2_IOCTL 10 +#define TRANSACT2_FINDNOTIFYFIRST 11 +#define TRANSACT2_FINDNOTIFYNEXT 12 +#define TRANSACT2_MKDIR 13 + +#define PTR_DIFF(p1,p2) ((unsigned long)(((char *)(p1)) - (char *)(p2))) + +/* some protos */ +uchar *fdata(uchar *buf,char *fmt,uchar *maxbuf); diff -u --new-file /usr/src/redhat/tcpdump-3.4.orig/smbutil.c ./smbutil.c --- /usr/src/redhat/tcpdump-3.4.orig/smbutil.c Thu Jan 1 10:00:00 1970 +++ ./smbutil.c Wed Jun 9 00:06:33 1999 @@ -0,0 +1,696 @@ +#include +#include +#include +#include + +#include + +#include +#include + +#include +#include +#include +#include + +#include "smb.h" + +extern uchar *startbuf; + +/******************************************************************* + interpret a 32 bit dos packed date/time to some parameters +********************************************************************/ +static void interpret_dos_date(uint32 date,int *year,int *month,int *day,int *hour,int *minute,int *second) +{ + uint32 p0,p1,p2,p3; + + p0=date&0xFF; p1=((date&0xFF00)>>8)&0xFF; + p2=((date&0xFF0000)>>16)&0xFF; p3=((date&0xFF000000)>>24)&0xFF; + + *second = 2*(p0 & 0x1F); + *minute = ((p0>>5)&0xFF) + ((p1&0x7)<<3); + *hour = (p1>>3)&0xFF; + *day = (p2&0x1F); + *month = ((p2>>5)&0xFF) + ((p3&0x1)<<3) - 1; + *year = ((p3>>1)&0xFF) + 80; +} + +/******************************************************************* + create a unix date from a dos date +********************************************************************/ +time_t make_unix_date(void *date_ptr) +{ + uint32 dos_date=0; + struct tm t; + + dos_date = IVAL(date_ptr,0); + + if (dos_date == 0) return(0); + + interpret_dos_date(dos_date,&t.tm_year,&t.tm_mon, + &t.tm_mday,&t.tm_hour,&t.tm_min,&t.tm_sec); + t.tm_wday = 1; + t.tm_yday = 1; + t.tm_isdst = 0; + + return (mktime(&t)); +} + +/******************************************************************* + create a unix date from a dos date +********************************************************************/ +time_t make_unix_date2(void *date_ptr) +{ + uint32 x,x2; + + x = IVAL(date_ptr,0); + x2 = ((x&0xFFFF)<<16) | ((x&0xFFFF0000)>>16); + SIVAL(&x,0,x2); + + return(make_unix_date((void *)&x)); +} + +/**************************************************************************** +interpret an 8 byte "filetime" structure to a time_t +It's originally in "100ns units since jan 1st 1601" +****************************************************************************/ +time_t interpret_long_date(char *p) +{ + double d; + time_t ret; + + /* this gives us seconds since jan 1st 1601 (approx) */ + d = (IVAL(p,4)*256.0 + CVAL(p,3)) * (1.0e-7 * (1<<24)); + + /* now adjust by 369 years to make the secs since 1970 */ + d -= 369.0*365.25*24*60*60; + + /* and a fudge factor as we got it wrong by a few days */ + d += (3*24*60*60 + 6*60*60 + 2); + + if (d<0) + return(0); + + ret = (time_t)d; + + return(ret); +} + + +/**************************************************************************** +interpret the weird netbios "name". Return the name type +****************************************************************************/ +static int name_interpret(char *in,char *out) +{ + int ret; + int len = (*in++) / 2; + + *out=0; + + if (len > 30 || len<1) return(0); + + while (len--) + { + if (in[0] < 'A' || in[0] > 'P' || in[1] < 'A' || in[1] > 'P') { + *out = 0; + return(0); + } + *out = ((in[0]-'A')<<4) + (in[1]-'A'); + in += 2; + out++; + } + *out = 0; + ret = out[-1]; + + /* Handle any scope names */ + while(*in) + { + *out++ = '.'; + len = *in++; + strncpy(out, in, len); + out += len; + *out=0; + in += len; + } + return(ret); +} + +/**************************************************************************** +find a pointer to a netbios name +****************************************************************************/ +static char *name_ptr(char *buf,int ofs) +{ + unsigned char c = *(unsigned char *)(buf+ofs); + + if ((c & 0xC0) == 0xC0) + { + uint16 l; + char p[2]; + memcpy(p,buf+ofs,2); + p[0] &= ~0xC0; + l = RSVAL(p,0); + return(buf + l); + } + else + return(buf+ofs); +} + +/**************************************************************************** +extract a netbios name from a buf +****************************************************************************/ +static int name_extract(char *buf,int ofs,char *name) +{ + char *p = name_ptr(buf,ofs); + int d = PTR_DIFF(p,buf+ofs); + strcpy(name,""); + return(name_interpret(p,name)); +} + + +/**************************************************************************** +return the total storage length of a mangled name +****************************************************************************/ +static int name_len(unsigned char *s) +{ + char *s0 = s; + unsigned char c = *(unsigned char *)s; + if ((c & 0xC0) == 0xC0) + return(2); + while (*s) s += (*s)+1; + return(PTR_DIFF(s,s0)+1); +} + +void print_asc(unsigned char *buf,int len) +{ + int i; + for (i=0;i8) printf(" "); + while (n--) printf(" "); + + n = MIN(8,i%16); + print_asc(&buf[i-(i%16)],n); printf(" "); + n = (i%16) - n; + if (n>0) print_asc(&buf[i-n],n); + printf("\n"); + } +} + + +static void write_bits(unsigned int val,char *fmt) +{ + char *p = fmt; + int i=0; + + while ((p=strchr(fmt,'|'))) { + int l = PTR_DIFF(p,fmt); + if (l && (val & (1<=maxbuf && *fmt) + printf("END OF BUFFER\n"); + + return(buf); +} + +uchar *fdata(uchar *buf,char *fmt,uchar *maxbuf) +{ + static int depth=0; + char s[128]; + char *p; + + while (*fmt) { + switch (*fmt) { + case '*': + fmt++; + while (buf < maxbuf) { + uchar *buf2; + depth++; + buf2 = fdata(buf,fmt,maxbuf); + depth--; + if (buf2 == buf) return(buf); + buf = buf2; + } + break; + + case '|': + fmt++; + if (buf>=maxbuf) return(buf); + break; + + case '%': + fmt++; + buf=maxbuf; + break; + + case '#': + fmt++; + return(buf); + break; + + case '[': + fmt++; + if (buf>=maxbuf) return(buf); + bzero(s,sizeof(s)); + p = strchr(fmt,']'); + strncpy(s,fmt,p-fmt); + fmt = p+1; + buf = fdata1(buf,s,maxbuf); + break; + + default: + putchar(*fmt); fmt++; + fflush(stdout); + break; + } + } + if (!depth && buf