Skip to content

Commit 3fb113a

Browse files
add tcp_flag cheatsheet
1 parent a80f7a7 commit 3fb113a

File tree

1 file changed

+122
-0
lines changed

1 file changed

+122
-0
lines changed

sockets/TCP/tcp_flags.txt

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
##TCP FLAGS##
2+
3+
Unskilled Attackers Pester Real Security Folks
4+
==============================================
5+
TCPDUMP FLAGS
6+
Unskilled = URG = (Not Displayed in Flag Field, Displayed elsewhere)
7+
Attackers = ACK = (Not Displayed in Flag Field, Displayed elsewhere)
8+
Pester = PSH = [P] (Push Data)
9+
Real = RST = [R] (Reset Connection)
10+
Security = SYN = [S] (Start Connection)
11+
Folks = FIN = [F] (Finish Connection)
12+
SYN-ACK = [S.] (SynAcK Packet)
13+
[.] (No Flag Set)
14+
15+
##USAGE##
16+
Basic communication // see the basics without many options
17+
# tcpdump -nS
18+
19+
Basic communication (very verbose) // see a good amount of traffic, with verbosity and no name help
20+
# tcpdump -nnvvS
21+
22+
A deeper look at the traffic // adds -X for payload but doesn’t grab any more of the packet
23+
# tcpdump -nnvvXS
24+
25+
Heavy packet viewing // the final “s” increases the snaplength, grabbing the whole packet
26+
# tcpdump -nnvvXSs 1514
27+
28+
host // look for traffic based on IP address (also works with hostname if you’re not using -n)
29+
# tcpdump host 1.2.3.4
30+
31+
src, dst // find traffic from only a source or destination (eliminates one side of a host conversation)
32+
# tcpdump src 2.3.4.5
33+
# tcpdump dst 3.4.5.6
34+
35+
net // capture an entire network using CIDR notation
36+
# tcpdump net 1.2.3.0/24
37+
38+
proto // works for tcp, udp, and icmp. Note that you don’t have to type proto
39+
# tcpdump icmp
40+
41+
port // see only traffic to or from a certain port
42+
# tcpdump port 3389
43+
44+
src, dst port // filter based on the source or destination port
45+
# tcpdump src port 1025 # tcpdump dst port 389
46+
47+
src/dst, port, protocol // combine all three
48+
# tcpdump src port 1025 and tcp
49+
# tcpdump udp and src port 53
50+
51+
You also have the option to filter by a range of ports instead of declaring them individually, and to only see packets that are above or below a certain size.
52+
53+
Port Ranges // see traffic to any port in a range
54+
tcpdump portrange 21-23
55+
56+
Packet Size Filter // only see packets below or above a certain size (in bytes)
57+
tcpdump less 32
58+
tcpdump greater 128
59+
[ You can use the symbols for less than, greater than, and less than or equal / greater than or equal signs as well. ]
60+
61+
// filtering for size using symbols
62+
tcpdump > 32
63+
tcpdump <= 128
64+
65+
[ Note: Only the PSH, RST, SYN, and FIN flags are displayed in tcpdump‘s flag field output. URGs and ACKs are displayed, but they are shown elsewhere in the output rather than in the flags field ]
66+
67+
Keep in mind the reasons these filters work. The filters above find these various packets because tcp[13] looks at offset 13 in the TCP header, the number represents the location within the byte, and the !=0 means that the flag in question is set to 1, i.e. it’s on.
68+
69+
Show all URG packets:
70+
# tcpdump 'tcp[13] & 32 != 0'
71+
72+
Show all ACK packets:
73+
# tcpdump 'tcp[13] & 16 != 0'
74+
75+
Show all PSH packets:
76+
# tcpdump 'tcp[13] & 8 != 0'
77+
78+
Show all RST packets:
79+
# tcpdump 'tcp[13] & 4 != 0'
80+
81+
Show all SYN packets:
82+
# tcpdump 'tcp[13] & 2 != 0'
83+
84+
Show all FIN packets:
85+
# tcpdump 'tcp[13] & 1 != 0'
86+
87+
Show all SYN-ACK packets:
88+
# tcpdump 'tcp[13] = 18'
89+
90+
Show icmp echo request and reply
91+
#tcpdump -n icmp and 'icmp[0] != 8 and icmp[0] != 0'
92+
93+
Show all IP packets with a non-zero TOS field (one byte TOS field is at offset 1 in IP header):
94+
# tcpdump -v -n ip and ip[1]!=0
95+
96+
Show all IP packets with TTL less than some value (on byte TTL field is at offset 8 in IP header):
97+
# tcpdump -v ip and 'ip[8]<2'
98+
99+
Show TCP SYN packets:
100+
# tcpdump -n tcp and port 80 and 'tcp[tcpflags] & tcp-syn == tcp-syn'
101+
# tcpdump tcp and port 80 and 'tcp[tcpflags] == tcp-syn'
102+
# tcpdump -i <interface> "tcp[tcpflags] & (tcp-syn) != 0"
103+
104+
Show TCP ACK packets:
105+
# tcpdump -i <interface> "tcp[tcpflags] & (tcp-ack) != 0"
106+
107+
Show TCP SYN/ACK packets (typically, responses from servers):
108+
# tcpdump -n tcp and 'tcp[tcpflags] & (tcp-syn|tcp-ack) == (tcp-syn|tcp-ack)'
109+
# tcpdump -n tcp and 'tcp[tcpflags] & tcp-syn == tcp-syn' and 'tcp[tcpflags] & tcp-ack == tcp-ack'
110+
# tcpdump -i <interface> "tcp[tcpflags] & (tcp-syn|tcp-ack) != 0"
111+
112+
Show TCP FIN packets:
113+
# tcpdump -i <interface> "tcp[tcpflags] & (tcp-fin) != 0"
114+
115+
Show ARP Packets with MAC address
116+
# tcpdump -vv -e -nn ether proto 0x0806
117+
118+
Show packets of a specified length (IP packet length (16 bits) is located at offset 2 in IP header):
119+
# tcpdump -l icmp and '(ip[2:2]>50)' -w - |tcpdump -r - -v ip and '(ip[2:2]<60)'
120+
121+
More Details:
122+
http://danielmiessler.com/study/tcpdump/

0 commit comments

Comments
 (0)