{"id":136,"date":"2025-06-18T01:35:13","date_gmt":"2025-06-18T01:35:13","guid":{"rendered":"https:\/\/epbrtcybersecurityportfolio.xyz\/?p=136"},"modified":"2025-06-18T01:35:13","modified_gmt":"2025-06-18T01:35:13","slug":"writing-tcpdump-filters","status":"publish","type":"post","link":"https:\/\/epbrtcybersecurityportfolio.xyz\/?p=136","title":{"rendered":"Writing tcpdump filters"},"content":{"rendered":"\n<p>This lab focused on building familiarity with <strong>tcpdump filters<\/strong>, particularly for identifying specific traffic based on TCP flags. The lab also introduced the use of <strong>TCP flags<\/strong>, which play a key role in identifying different types of TCP traffic (e.g., SYN, ACK, FIN).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exercise 1 \u2013 Identifying TCP Connection Attempts with tcpdump<\/h3>\n\n\n\n<p><strong>Objective:<\/strong><br>Use <code>tcpdump<\/code> to examine records from the file <code>int-server.pcap<\/code> and identify <strong>initial TCP connection attempts<\/strong> from clients to servers. The goal is to isolate packets where only the <strong>SYN<\/strong> bit is set\u2014this indicates the start of a TCP handshake.<\/p>\n\n\n\n<p><strong>Steps Taken:<\/strong><\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li><strong>Command Setup:<\/strong><br>To simplify the output, I used the <code>-n<\/code> (no DNS resolution) and <code>-t<\/code> (no timestamp) flags<\/li>\n\n\n\n<li><strong>Filtering on TCP Flags:<\/strong><\/li>\n\n\n\n<li>TCP control flags are located at <strong>byte offset 13<\/strong> in the TCP header (<code>tcp[13]<\/code>). For SYN-only packets (i.e., no ACK or other bits set), we need to match exactly the binary value <strong>00000010<\/strong>, which is <strong>0x02<\/strong> in hex.<\/li>\n\n\n\n<li><strong>tcpdump Filter Expression:<\/strong><\/li>\n\n\n\n<li>The appropriate filter to match only SYN packets is:<\/li>\n<\/ol>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"540\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-46-1024x540.png\" alt=\"\" class=\"wp-image-139\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-46-1024x540.png 1024w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-46-300x158.png 300w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-46-768x405.png 768w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-46.png 1026w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We see attempted connections from the clients to ports 25(SMTP), 445(SMB), 4444(default port used by Metasploit), 999, 80(HTTP) and 53(DNS).<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exercise 2 \u2013 Filtering for TCP SYN-ACK Responses<\/h3>\n\n\n\n<p><strong>Objective:<\/strong><br>Use <code>tcpdump<\/code> to identify packets from the <code>int-server.pcap<\/code> file where a server responds to a connection request\u2014i.e., where both the <strong>SYN<\/strong> and <strong>ACK<\/strong> flags are set. This indicates the server is listening and willing to establish a connection.<\/p>\n\n\n\n<p><strong>Understanding TCP Flags:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>The TCP <strong>flags byte<\/strong> is at <strong>offset 13<\/strong> (<code>tcp[13]<\/code>)<\/li>\n\n\n\n<li><strong>ACK<\/strong> = 0x10<\/li>\n\n\n\n<li><strong>SYN<\/strong> = 0x02<\/li>\n\n\n\n<li>Therefore, <strong>SYN-ACK<\/strong> = <code>0x12<\/code> (00010010 in binary)<\/li>\n<\/ul>\n\n\n\n<p><strong>tcpdump Filter Used:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"235\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-47-1024x235.png\" alt=\"\" class=\"wp-image-142\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-47-1024x235.png 1024w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-47-300x69.png 300w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-47-768x176.png 768w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-47.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>The server ports that responded are 25, 445 and 4444.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exercise 3 \u2013 Filtering for TCP Session Termination (RST or FIN)<\/h3>\n\n\n\n<p><strong>Objective:<\/strong><br>Use <code>tcpdump<\/code> to identify packets from the <code>int-server.pcap<\/code> file that contain <strong>termination flags<\/strong>, specifically the <strong>RST<\/strong> or <strong>FIN<\/strong> flags. These flags signal that a TCP session is being closed\u2014either gracefully (FIN) or abruptly (RST).<\/p>\n\n\n\n<p><strong>Flag Values:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>FIN<\/strong> = <code>0x01<\/code><\/li>\n\n\n\n<li><strong>RST<\/strong> = <code>0x04<\/code><\/li>\n<\/ul>\n\n\n\n<p>Unlike previous filters that matched exact values, this task required detecting <strong>whether either of the two termination flags is present<\/strong>, regardless of other flags that might also be set.<\/p>\n\n\n\n<p><strong>Using a Mask Byte:<\/strong><\/p>\n\n\n\n<p>The correct approach is to apply a <strong>mask byte<\/strong> that preserves only the <strong>FIN<\/strong> and <strong>RST<\/strong> bits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Binary: <code>00000101<\/code><\/li>\n\n\n\n<li>Hex: <code>0x05<\/code><\/li>\n<\/ul>\n\n\n\n<p>The filter will check if <strong>either<\/strong> of these bits is present using a bitwise AND mask.<\/p>\n\n\n\n<p><strong>tcpdump Filter Used:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"291\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-48-1024x291.png\" alt=\"\" class=\"wp-image-144\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-48-1024x291.png 1024w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-48-300x85.png 300w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-48-768x218.png 768w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-48.png 1028w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n\n\n\n<p>We see 7 records with either or both the FIN and RESET flags set. <\/p>\n\n\n\n<h3 class=\"wp-block-heading\">Exercise 4 \u2013 Filtering for TCP Packets with Both PSH and ACK Flags on Port 143 (IMAP)<\/h3>\n\n\n\n<p><strong>Objective:<\/strong><br>Use <code>tcpdump<\/code> to extract the <strong>first five packets<\/strong> from <code>int-server.pcap<\/code> that meet all the following criteria:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Destination port is <strong>TCP 143<\/strong> (IMAP)<\/li>\n\n\n\n<li>Both the <strong>PUSH<\/strong> and <strong>ACK<\/strong> flags are set<\/li>\n\n\n\n<li>Other flags may be present as well<\/li>\n<\/ul>\n\n\n\n<p><strong>TCP Flags Reference:<\/strong><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>ACK<\/strong> = <code>0x10<\/code> (bit 4)<\/li>\n\n\n\n<li><strong>PSH<\/strong> = <code>0x08<\/code> (bit 3)<br>Combined, they yield a value of <code>0x18<\/code> (00011000 in binary)<\/li>\n<\/ul>\n\n\n\n<p>To isolate packets where both these bits are set (regardless of other flags), I used a <strong>bitmask<\/strong> to mask all other bits:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Mask: <code>0x18<\/code><\/li>\n\n\n\n<li>Value: <code>0x18<\/code><\/li>\n<\/ul>\n\n\n\n<p><strong>tcpdump Filter Used:<\/strong><\/p>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"1024\" height=\"193\" src=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-49-1024x193.png\" alt=\"\" class=\"wp-image-147\" srcset=\"https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-49-1024x193.png 1024w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-49-300x57.png 300w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-49-768x145.png 768w, https:\/\/epbrtcybersecurityportfolio.xyz\/wp-content\/uploads\/2025\/06\/image-49.png 1027w\" sizes=\"auto, (max-width: 1024px) 100vw, 1024px\" \/><\/figure>\n","protected":false},"excerpt":{"rendered":"<p>This lab focused on building familiarity with tcpdump filters, particularly for identifying specific traffic based on TCP flags. The lab also introduced the use of TCP flags, which play a key role in identifying different types of TCP traffic (e.g., SYN, ACK, FIN). Exercise 1 \u2013 Identifying TCP Connection Attempts with tcpdump Objective:Use tcpdump to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-136","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/136","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=136"}],"version-history":[{"count":5,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions"}],"predecessor-version":[{"id":148,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=\/wp\/v2\/posts\/136\/revisions\/148"}],"wp:attachment":[{"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=136"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=136"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/epbrtcybersecurityportfolio.xyz\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=136"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}