Under normal circumstances, the network analysis of non-HTTP protocol, in the server end with Tcpdump more, in the client with Wireshark more, two grab software syntax is the same.
first, the basic grammar 1.1, filter host crawl all through eth1, the purpose or source address is 192.168.1.1 network data
Tcpdump-i eth1 Host 192.168.1.1
Specify Source Address
Tcpdump-i eth1 SRC Host 192.168.1.1
Specify Destination Address
Tcpdump-i eth1 DST Host 192.168.1.1
1.2. Filter PortCrawl all network data through eth1, destination or source port is 25
Tcpdump-i eth1 Port 25
Specify Source port
Tcpdump-i eth1 SRC Port 25
Specify Destination port
Tcpdump-i eth1 DST Port 25
1.3, Network filtering
Tcpdump-i eth1 net 192.168
tcpdump-i eth1 src net 192.168 tcpdump-i eth1
DST net 192.168
1.4. Protocol Filtering
Tcpdump-i eth1 arp
tcpdump-i eth1 IP
tcpdump-i eth1 tcp
tcpdump-i eth1 UDP
tcpdump-i eth1 ICMP
1.5. Common Expressions
Non -:! or "not" (with double quotes removed)
and: &&
or "and" or: | | or "or"
Crawl all TCP data that passes through ETH1, the destination address is 192.168.1.254 or 192.168.1.200 port is 80
Tcpdump-i eth1 ' ((TCP) and (port) and (DST host 192.168.1.254) or (DST host 192.168.1.200)) '
Crawl all ICMP data that has passed through eth1, the target MAC address is 00:01:02:03:04:05
Tcpdump-i eth1 ' ((ICMP) and (Ether DST host 00:01:02:03:04:05)) '
Crawl all through eth1, the destination network is 192.168, but the destination host is not 192.168.1.200 TCP data
Tcpdump-i eth1 ' ((TCP) and ((DST 192.168) and (not DST host 192.168.1.200)) '
second, the Advanced Baotou filtration
First learn how to filter information from headers
PROTO[X:Y] : Filters the number of y bytes starting from x bytes. For example, Ip[2:2] filters out 3, 4 bytes (first byte from 0 start)
proto[x:y] & z = 0 : proto[x:y] and Z's with operation 0
proto[x:y] & z!=0 : Proto [X:y] and Z's and operations are not 0
proto[x:y] & z = z : proto[x:y] and Z with operations for z
proto[x:y] = Z : proto[x:y] equals Z
Operator: ",", >=, <=, =,!= 2.1, IP header
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | version| IHL | Type of service|
Total Length | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Identification | flags|
Fragment Offset | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Time to Live | Protocol |
Header Checksum | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Source Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Destination Address | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Options | Padding | <--Optional +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
DATA ... |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
This article is for IPV4 only. 2.2, the IP option set.
The "General" IP header is 20 bytes, but the IP header has option settings and cannot read data directly from the offset of 21 bytes. The IP header has a length field to know if the header length is greater than 20 bytes.
+-+-+-+-+-+-+-+-+
| version| IHL |
+-+-+-+-+-+-+-+-+
Usually the binary value of the first byte is: 01000101, divided into two parts:
0100 = 4 means that IP version 0101 = 5 represents the number of blocks for the IP header bit, 5 x bits = 160 bits or bytes
If the value of the second part of the first byte is greater than 5, then the header has an IP option.
Here are two types of filtering methods (the first one is a bit fucked and can be ignored):
A. Compares the value of the first byte to be greater than 01000101, which can be used to determine IPV4 data with IP options and IPV6 data.
10,001,010 is equal to 69, the calculation method is as follows (small tip: Use calculator more convenient)
0:0 \
1:2^6 = 64 \ First part (IP version)
0:0 /
0:0 /
-
0:0 \
1:2^2 = 4
\ Part II (head length)
0:0 /
1:2^0 = 1/
64 + 4 + 1 = 69
If the IP option is set, then the first one is 01000110 (decimal 70), the filter rule:
Tcpdump-i eth1 ' ip[0] > 69 '
The IPV6 data will also match, looking at the second method.
B. Bit operation
0100 0101: The first byte of the binary
0000 1111: With the operation
<=========
0000 0101: Results
The right way to filter
Tcpdump-i eth1 ' ip[0] & > 5 '
Or
Tcpdump-i eth1 ' ip[0] & 0x0f > 5 '
2.3. Fragment Mark
When the sender's MTU is larger than the destination path link to the MTU will be fragmented, this paragraph is a bit clumsy, authoritative please refer to "TCP/IP detailed." Alas, 32 borrowed my book has not yet, can only make up to write, we remember reading AH.
Fragmentation information in the seventh and eighth bytes of the IP header:
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| flags| Fragment Offset |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Bit 0: Reserved, must be 0
Bit 1: (DF) 0 = possibly fragmented, 1 = not fragmented
Bit 2: (MF) 0 = final fragment, 1 = also fragment
The Fragment offset field is only used when slicing.
To grab the not-fragmented package with the DF bit mark, the seventh byte value should be:
01000000 = 64
Tcpdump-i eth1 ' ip[6] = 64 '
2.4. Grab the Slice bagMatching MF, slicing package
Tcpdump-i eth1 ' ip[6] = 32 '
The first 3 bits of the last shard package are 0, but there are fragment offset fields. Matching fragmentation and final fragmentation
Tcpdump-i eth1 ' (Ip[6:2] > 0) and (not ip[6] = 64)) '
Test fragmentation can be made with the following command:
PING-M Want-s 3000 192.168.1.1
2.5, matching small TTL
The TTL field is in the Nineth byte and is exactly the full byte, the TTL maximum is 255, and the binary is 11111111.
You can use the following command to verify:
$ ping-m want-s 3000-t 256 192.168.1.200 ping:ttl out of
range
+-+-+-+-+-+-+-+-+
| Time to Live |
+-+-+-+-+-+-+-+-+
At the gateway you can use the following command to see who is using traceroute in the network
Tcpdump-i eth1 ' ip[8] < 5 '
2.6. Grab packets larger than x bytesGreater than 600 bytes
Tcpdump-i eth1 ' ip[2:2] > 600 '
2.7, more IP filtering
First or need to know the TCP basic structure, again recommended "TCP/IP detailed", Volume one is enough to see, to avoid the obsession. TCP Headers
0 1 2 3 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ | Source Port |
Destination Port | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Sequence number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Acknowledgment number | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Data | | c| e| u| a| p| r| s| F|
| | Offset| Res. | w| c| r| c| s| s| y| i|
Window | | | | r| e| G| k| h| T| n| n|
| +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
| Checksum |
Urgent pointer |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+| Options |
Padding | +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
|
Data |
+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
Grabbing TCP packets with a source port greater than 1024
Tcpdump-i eth1 ' tcp[0:2] > 1024 '
Special tags that match TCP packets
TCP tags are defined in the 14th byte of the TCP header
+-+-+-+-+-+-+-+-+
| c| e| u| a| p| r| s| F|
| w| c| r| c| s| s| y| i|
| r| e| G| k| h| T| n| n|
+-+-+-+-+-+-+-+-+
Repeat TCP three times handshake, two host is how to hook up: