{"id":111,"date":"2025-03-20T12:02:36","date_gmt":"2025-03-20T12:02:36","guid":{"rendered":"https:\/\/www.24x7serverguard.com\/blog\/?p=111"},"modified":"2025-03-20T12:02:36","modified_gmt":"2025-03-20T12:02:36","slug":"a-syn-attack-is-a-widely-used-denial-of-service-dos-technique-that-exploits-the-tcp-connection-request-process","status":"publish","type":"post","link":"https:\/\/www.24x7serverguard.com\/blog\/ddos\/a-syn-attack-is-a-widely-used-denial-of-service-dos-technique-that-exploits-the-tcp-connection-request-process\/","title":{"rendered":"A SYN attack is a widely used Denial-of-Service (DoS) technique that exploits the TCP connection request process."},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">A <strong>SYN flood<\/strong> is a type of DoS attack where an attacker overwhelms a target system by continuously sending <strong>SYN requests<\/strong> without completing the connection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">During a typical <strong>TCP handshake<\/strong>, the following steps occur:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">1\ufe0f\u20e3 The <strong>client initiates<\/strong> a connection by sending a <strong>SYN (synchronize)<\/strong> request to the server.<br>2\ufe0f\u20e3 The <strong>server responds<\/strong> with a <strong>SYN-ACK (synchronize-acknowledge)<\/strong> to confirm the request.<br>3\ufe0f\u20e3 The <strong>client replies<\/strong> with an <strong>ACK (acknowledge)<\/strong>, successfully establishing the connection.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><strong>How to Detect a SYN Attack on a Server<br><\/strong>To quickly check if your server is under a <strong>DDoS (Denial-of-Service) attack<\/strong>, use the following command:<\/p>\n\n\n\n<p class=\"has-medium-font-size wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">netstat -anp | grep &#8216;tcp|udp&#8217; | awk &#8216;{print $5}&#8217; | cut -d: -f1 | sort | uniq -c | sort -n<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This will display a list of IP addresses making the highest number of connections to your server. However, it&#8217;s important to note that modern <strong>DDoS attacks<\/strong> have become more sophisticated, often using multiple attacking IPs with fewer connections per IP. This means that even if the connection count appears low, your server may still be under attack.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Another crucial aspect to monitor is the <strong>number of active connections<\/strong> your server is currently handling:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">netstat -n | grep :80 | wc -l<br>netstat -n | grep :80 | grep SYN | wc -l<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>first command<\/strong> shows the total number of active connections to your server. While the exact number varies, exceeding <strong>500 connections<\/strong> is often a sign of trouble. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The <strong>second command<\/strong> filters for <strong>SYN requests<\/strong>, indicating potential SYN flood attacks. If this number exceeds <strong>100<\/strong>, it suggests that your server is experiencing a <strong>SYN flood attack<\/strong>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Sol.: <\/strong>To protect your server from a <strong>SYN flood attack<\/strong>, follow these steps:<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u2705 1. Enable TCP SYN Cookies<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">This prevents the server from allocating resources for half-open connections. Run the following command:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">echo 1 > \/proc\/sys\/net\/ipv4\/tcp_syncookies<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\">This enables SYN cookies, helping to mitigate <strong>SYN flood attacks<\/strong>.<\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u2705 2. Apply IPTables Rules to Block Malicious Packets<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">The following <strong>IPTables<\/strong> rules will drop packets with suspicious TCP flags, helping prevent <strong>various types of attacks<\/strong>:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">iptables -A INPUT -p tcp &#8211;tcp-flags ALL NONE -j DROP # Block NULL packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags SYN,FIN SYN,FIN -j DROP # Block SYN-FIN packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags SYN,RST SYN,RST -j DROP # Block SYN-RST packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags FIN,RST FIN,RST -j DROP # Block FIN-RST packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags ACK,FIN FIN -j DROP # Block XMAS packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags ACK,PSH PSH -j DROP # Block ACK-PSH packets<br>iptables -A INPUT -p tcp &#8211;tcp-flags ACK,URG URG -j DROP # Block ACK-URG packets<\/mark><\/p>\n\n\n\n<h4 class=\"wp-block-heading\"><strong>\u2705 3. Save and Restart IPTables<\/strong><\/h4>\n\n\n\n<p class=\"wp-block-paragraph\">After applying the rules, save and restart <strong>IPTables<\/strong> to ensure they take effect:<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><mark style=\"background-color:rgba(0, 0, 0, 0)\" class=\"has-inline-color has-vivid-red-color\">service iptables save<br>service iptables restart<\/mark><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><\/p>\n","protected":false},"excerpt":{"rendered":"<p>A SYN flood is a type of DoS attack where an attacker overwhelms a target system by continuously sending SYN requests without completing the connection. During a typical TCP handshake, the following steps occur: 1\ufe0f\u20e3 The client initiates a connection by sending a SYN (synchronize) request to the server.2\ufe0f\u20e3 The server responds with a SYN-ACK [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":112,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[8],"tags":[59,58,55,57,54,56],"class_list":["post-111","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-ddos","tag-attack","tag-ddos","tag-syn","tag-synattack","tag-synflood","tag-tcp"],"_links":{"self":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/111","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/comments?post=111"}],"version-history":[{"count":1,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions"}],"predecessor-version":[{"id":113,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/posts\/111\/revisions\/113"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media\/112"}],"wp:attachment":[{"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/media?parent=111"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/categories?post=111"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.24x7serverguard.com\/blog\/wp-json\/wp\/v2\/tags?post=111"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}