⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 tcpdump.1

📁 TCPDUMP的C语言源代码,是在数据链路层的应用
💻 1
📖 第 1 页 / 共 4 页
字号:
\fIFlags\fP are some combination of S (SYN),F (FIN), P (PUSH), R (RST), W (ECN CWR) or E (ECN-Echo), or a single`.' (no flags).\fIData-seqno\fP describes the portion of sequence space coveredby the data in this packet (see example below).\fIAck\fP is sequence number of the next data expected the otherdirection on this connection.\fIWindow\fP is the number of bytes of receive buffer space availablethe other direction on this connection.\fIUrg\fP indicates there is `urgent' data in the packet.\fIOptions\fP are tcp options enclosed in angle brackets (e.g., <mss 1024>)..LP\fISrc, dst\fP and \fIflags\fP are always present.The other fieldsdepend on the contents of the packet's tcp protocol header andare output only if appropriate..LPHere is the opening portion of an rlogin from host \fIrtsg\fP tohost \fIcsam\fP..RS.nf.sp .5\s-2\f(CWrtsg.1023 > csam.login: S 768512:768512(0) win 4096 <mss 1024>csam.login > rtsg.1023: S 947648:947648(0) ack 768513 win 4096 <mss 1024>rtsg.1023 > csam.login: . ack 1 win 4096rtsg.1023 > csam.login: P 1:2(1) ack 1 win 4096csam.login > rtsg.1023: . ack 2 win 4096rtsg.1023 > csam.login: P 2:21(19) ack 1 win 4096csam.login > rtsg.1023: P 1:2(1) ack 21 win 4077csam.login > rtsg.1023: P 2:3(1) ack 21 win 4077 urg 1csam.login > rtsg.1023: P 3:4(1) ack 21 win 4077 urg 1\fR\s+2.sp .5.fi.REThe first line says that tcp port 1023 on rtsg sent a packetto port \fIlogin\fPon csam.The \fBS\fP indicates that the \fISYN\fP flag was set.The packet sequence number was 768512 and it contained no data.(The notation is `first:last(nbytes)' which means `sequencenumbers \fIfirst\fPup to but not including \fIlast\fP which is \fInbytes\fP bytes of user data'.)There was no piggy-backed ack, the available receive window was 4096bytes and there was a max-segment-size option requesting an mss of1024 bytes..LPCsam replies with a similar packet except it includes a piggy-backedack for rtsg's SYN.Rtsg then acks csam's SYN.The `.' means noflags were set.The packet contained no data so there is no data sequence number.Note that the ack sequencenumber is a small integer (1).The first time \fItcpdump\fP sees atcp `conversation', it prints the sequence number from the packet.On subsequent packets of the conversation, the difference betweenthe current packet's sequence number and this initial sequence numberis printed.This means that sequence numbers after thefirst can be interpretedas relative byte positions in the conversation's data stream (with thefirst data byte each direction being `1').`-S' will override thisfeature, causing the original sequence numbers to be output..LPOn the 6th line, rtsg sends csam 19 bytes of data (bytes 2 through 20in the rtsg \(-> csam side of the conversation).The PUSH flag is set in the packet.On the 7th line, csam says it's received data sent by rtsg up tobut not including byte 21.Most of this data is apparently sitting in thesocket buffer since csam's receive window has gotten 19 bytes smaller.Csam also sends one byte of data to rtsg in this packet.On the 8th and 9th lines,csam sends two bytes of urgent, pushed data to rtsg..LPIf the snapshot was small enough that \fItcpdump\fP didn't capturethe full TCP header, it interprets as much of the header as it canand then reports ``[|\fItcp\fP]'' to indicate the remainder could notbe interpreted.If the header contains a bogus option (one with a lengththat's either too small or beyond the end of the header), \fItcpdump\fPreports it as ``[\fIbad opt\fP]'' and does not interpret any furtheroptions (since it's impossible to tell where they start).If the headerlength indicates options are present but the IP datagram length is notlong enough for the options to actually be there, \fItcpdump\fP reportsit as ``[\fIbad hdr length\fP]''..HD.B Capturing TCP packets with particular flag combinations (SYN-ACK, URG-ACK, etc.).PPThere are 8 bits in the control bits section of the TCP header:.IP.I CWR | ECE | URG | ACK | PSH | RST | SYN | FIN.PPLet's assume that we want to watch packets used in establishinga TCP connection.Recall that TCP uses a 3-way handshake protocolwhen it initializes a new connection; the connection sequence withregard to the TCP control bits is.PP.RS1) Caller sends SYN.RE.RS2) Recipient responds with SYN, ACK.RE.RS3) Caller sends ACK.RE.PPNow we're interested in capturing packets that have only theSYN bit set (Step 1).Note that we don't want packets from step 2(SYN-ACK), just a plain initial SYN.What we need is a correct filterexpression for \fItcpdump\fP..PPRecall the structure of a TCP header without options:.PP.nf 0                            15                              31-----------------------------------------------------------------|          source port          |       destination port        |-----------------------------------------------------------------|                        sequence number                        |-----------------------------------------------------------------|                     acknowledgment number                     |-----------------------------------------------------------------|  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |-----------------------------------------------------------------|         TCP checksum          |       urgent pointer          |-----------------------------------------------------------------.fi.PPA TCP header usually holds 20 octets of data, unless options arepresent.The first line of the graph contains octets 0 - 3, thesecond line shows octets 4 - 7 etc..PPStarting to count with 0, the relevant TCP control bits are containedin octet 13:.PP.nf 0             7|             15|             23|             31----------------|---------------|---------------|----------------|  HL   | rsvd  |C|E|U|A|P|R|S|F|        window size            |----------------|---------------|---------------|----------------|               |  13th octet   |               |               |.fi.PPLet's have a closer look at octet no. 13:.PP.nf                |               |                |---------------|                |C|E|U|A|P|R|S|F|                |---------------|                |7   5   3     0|.fi.PPThese are the TCP control bits we are interestedin.We have numbered the bits in this octet from 0 to 7, right toleft, so the PSH bit is bit number 3, while the URG bit is number 5..PPRecall that we want to capture packets with only SYN set.Let's see what happens to octet 13 if a TCP datagram arriveswith the SYN bit set in its header:.PP.nf                |C|E|U|A|P|R|S|F|                |---------------|                |0 0 0 0 0 0 1 0|                |---------------|                |7 6 5 4 3 2 1 0|.fi.PPLooking at thecontrol bits section we see that only bit number 1 (SYN) is set..PPAssuming that octet number 13 is an 8-bit unsigned integer innetwork byte order, the binary value of this octet is.IP00000010.PPand its decimal representation is.PP.nf   7     6     5     4     3     2     1     00*2 + 0*2 + 0*2 + 0*2 + 0*2 + 0*2 + 1*2 + 0*2  =  2.fi.PPWe're almost done, because now we know that if only SYN is set,the value of the 13th octet in the TCP header, when interpretedas a 8-bit unsigned integer in network byte order, must be exactly 2..PPThis relationship can be expressed as.RS.Btcp[13] == 2.RE.PPWe can use this expression as the filter for \fItcpdump\fP in orderto watch packets which have only SYN set:.RS.Btcpdump -i xl0 tcp[13] == 2.RE.PPThe expression says "let the 13th octet of a TCP datagram havethe decimal value 2", which is exactly what we want..PPNow, let's assume that we need to capture SYN packets, but wedon't care if ACK or any other TCP control bit is set at thesame time.Let's see what happens to octet 13 when a TCP datagramwith SYN-ACK set arrives:.PP.nf     |C|E|U|A|P|R|S|F|     |---------------|     |0 0 0 1 0 0 1 0|     |---------------|     |7 6 5 4 3 2 1 0|.fi.PPNow bits 1 and 4 are set in the 13th octet.The binary value ofoctet 13 is.IP     00010010.PPwhich translates to decimal.PP.nf   7     6     5     4     3     2     1     00*2 + 0*2 + 0*2 + 1*2 + 0*2 + 0*2 + 1*2 + 0*2   = 18.fi.PPNow we can't just use 'tcp[13] == 18' in the \fItcpdump\fP filterexpression, because that would select only those packets that haveSYN-ACK set, but not those with only SYN set.Remember that we don't careif ACK or any other control bit is set as long as SYN is set..PPIn order to achieve our goal, we need to logically AND thebinary value of octet 13 with some other value to preservethe SYN bit.We know that we want SYN to be set in any case,so we'll logically AND the value in the 13th octet withthe binary value of a SYN:.PP.nf          00010010 SYN-ACK              00000010 SYN     AND  00000010 (we want SYN)   AND  00000010 (we want SYN)          --------                      --------     =    00000010                 =    00000010.fi.PPWe see that this AND operation delivers the same resultregardless whether ACK or another TCP control bit is set.The decimal representation of the AND value as well asthe result of this operation is 2 (binary 00000010),so we know that for packets with SYN set the followingrelation must hold true:.IP( ( value of octet 13 ) AND ( 2 ) ) == ( 2 ).PPThis points us to the \fItcpdump\fP filter expression.RS.B     tcpdump -i xl0 'tcp[13] & 2 == 2'.RE.PPNote that you should use single quotes or a backslashin the expression to hide the AND ('&') special characterfrom the shell..HD.BUDP Packets.LPUDP format is illustrated by this rwho packet:.RS.nf.sp .5\f(CWactinide.who > broadcast.who: udp 84\fP.sp .5.fi.REThis says that port \fIwho\fP on host \fIactinide\fP sent a udpdatagram to port \fIwho\fP on host \fIbroadcast\fP, the Internetbroadcast address.The packet contained 84 bytes of user data..LPSome UDP services are recognized (from the source or destinationport number) and the higher level protocol information printed.In particular, Domain Name service requests (RFC-1034/1035) and SunRPC calls (RFC-1050) to NFS..HDUDP Name Server Requests.LP\fI(N.B.:The following description assumes familiarity withthe Domain Service protocol described in RFC-1035.If you are not familiarwith the protocol, the following description will appear to be writtenin greek.)\fP.LPName server requests are formatted as.RS.nf.sp .5\fIsrc > dst: id op? flags qtype qclass name (len)\fP.sp .5\f(CWh2opolo.1538 > helios.domain: 3+ A? ucbvax.berkeley.edu. (37)\fR.sp .5.fi.REHost \fIh2opolo\fP asked the domain server on \fIhelios\fP for anaddress record (qtype=A) associated with the name \fIucbvax.berkeley.edu.\fPThe query id was `3'.The `+' indicates the \fIrecursion desired\fP flagwas set.The query length was 37 bytes, not including the UDP andIP protocol headers.The query operation was the normal one, \fIQuery\fP,so the op field was omitted.If the op had been anything else, it wouldhave been printed between the `3' and the `+'.Similarly, the qclass was the normal one,\fIC_IN\fP, and omitted.Any other qclass would have been printedimmediately after the `A'..LPA few anomalies are checked and may result in extra fields enclosed insquare brackets:  If a query contains an answer, authority records oradditional records section,.IR ancount ,.IR nscount ,or.I arcountare printed as `[\fIn\fPa]', `[\fIn\fPn]' or  `[\fIn\fPau]' where \fIn\fPis the appropriate count.If any of the response bits are set (AA, RA or rcode) or any of the`must be zero' bits are set in bytes two and three, `[b2&3=\fIx\fP]'is printed, where \fIx\fP is the hex value of header bytes two and three..HDUDP Name Server Responses.LPName server responses are formatted as.RS.nf.sp .5\fIsrc > dst:  id op rcode flags a/n/au type class data (len)\fP.sp .5\f(CWhelios.domain > h2opolo.1538: 3 3/3/7 A 128.32.137.3 (273)helios.domain > h2opolo.1537: 2 NXDomain* 0/1/0 (97)\fR.sp .5.fi.REIn the first example, \fIhelios\fP responds to query id 3 from \fIh2opolo\fPwith 3 answer records, 3 name server records and 7 additional records.The first answer record is type A (address) and its data is internetaddress 128.32.137.3.The total size of the response was 273 bytes,excluding UDP and IP headers.The op (Query) and response code(NoError) were omitted, as was the class (C_IN) of the A record..LPIn the second example, \fIhelios\fP responds to query 2 with aresponse code of non-existent domain (NXDomain) with no answers,one name server and no authority records.The `*' indicates thatthe \fIauthoritative answer\fP bit was set.Since there were noanswers, no type, class or data were printed..LPOther flag characters that might appear are `\-' (recursion available,RA, \fInot\fP set) and `|' (truncated message, TC, set).If the`question' section doesn't contain exactly one entry, `[\fIn\fPq]'is printed..LPNote that name server requests and responses tend to be large and thedefault \fIsnaplen\fP of 68 bytes may not capture enough of the packetto print.Use the \fB\-s\fP flag to increase the snaplen if youneed to seriously investigate name server traffic.`\fB\-s 128\fP'has worked well for me..HDSMB/CIFS decoding.LP\fItcpdump\fP now includes fairly extensive SMB/CIFS/NBT decoding for dataon UDP/137, UDP/138 and TCP/139.Some primitive decoding of IPX andNetBEUI SMB data is also done.By default a fairly minimal decode is done, with a much more detaileddecode done if -v is used.Be warned that with -v a single SMB packetmay take up a page or more, so only use -v if you really want all thegory details.For information on SMB packet formats and what all te fields mean seewww.cifs.org or the pub/samba/specs/ directory on your favoritesamba.org mirror site.The SMB patches were written by Andrew Tridgell(tridge@samba.org)..HDNFS Requests and Replies.LPSun NFS (Network File System) requests and replies are printed as:.RS.nf.sp .5\fIsrc.xid > dst.nfs: len op args\fP\fIsrc.nfs > dst.xid: reply stat len op results\fP.sp .5\f(CW

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -