{"id":4054,"date":"2014-01-08T17:22:36","date_gmt":"2014-01-08T15:22:36","guid":{"rendered":"http:\/\/skeletor.org.ua\/?p=4054"},"modified":"2016-06-07T16:39:24","modified_gmt":"2016-06-07T13:39:24","slug":"%d0%b7%d0%b0%d1%89%d0%b8%d1%82%d0%b0-%d0%be%d1%82-syn-flooda","status":"publish","type":"post","link":"https:\/\/skeletor.org.ua\/?p=4054","title":{"rendered":"\u0417\u0430\u0449\u0438\u0442\u0430 \u043e\u0442 Syn Flood&#8217;a"},"content":{"rendered":"<p><em><strong><span style=\"color: #008000;\">\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u043d\u0434:<\/span><\/strong><\/em> <strong>Centos 6.2 (kernel 2.6.32-220.4.2.el6.x86_64), apache+php+mysql<\/strong><\/p>\n<p>\u0418\u043c\u0435\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c\u00a0<strong>SYN_RECV (syn flood)<\/strong>:<\/p>\n<p><code>$netstat -ntu<br \/>\n...<br \/>\ntcp 0 0 XX.XX.XX.XX:80 202.51.102.34:40700 SYN_RECV<br \/>\ntcp 0 0 XX.XX.XX.XX:80 190.225.143.29:40123 SYN_RECV<br \/>\ntcp 0 0 XX.XX.XX.XX:80 101.255.71.7:38725 SYN_RECV<br \/>\ntcp 0 0 XX.XX.XX.XX:80 122.226.122.201:48952 SYN_RECV<br \/>\ntcp 0 0 XX.XX.XX.XX:80 186.91.63.97:44343 SYN_RECV<br \/>\ntcp 0 0 XX.XX.XX.XX:80 109.230.156.97:56149 SYN_RECV<br \/>\n...<\/code><\/p>\n<p>\u041a\u0430\u043a \u0441 \u043d\u0438\u043c\u0438 \u0431\u043e\u0440\u043e\u0442\u044c\u0441\u044f?<\/p>\n<p><!--more--><br \/>\n\u0412 \u043f\u0435\u0440\u0432\u0443\u044e \u043e\u0447\u0435\u0440\u0435\u0434\u044c \u043f\u043e\u0434\u0442\u044e\u043d\u0438\u0442\u044c <strong>sysctl<\/strong>, \u043a\u0430\u043a \u044d\u0442\u043e \u043f\u043e\u043a\u0430\u0437\u0430\u043d\u043e <a href=\"\/?p=1742\" target=\"_blank\">\u0437\u0434\u0435\u0441\u044c<\/a>\u00a0\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0441\u043a\u0440\u0438\u043f\u0442 \u0434\u043b\u044f \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043d\u0435\u043d\u0443\u0436\u043d\u044b\u0445 <strong>IP<\/strong> \u0447\u0435\u0440\u0435\u0437 <strong>ipset<\/strong>. \u0422\u0443\u043f\u043e <strong>iptables<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u043d\u0435\u043b\u044c\u0437\u044f, \u0442\u0430\u043a \u043a\u0430\u043a \u043f\u0440\u0438 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0431\u043e\u043b\u044c\u0448\u0435 <strong>100<\/strong> IP \u043d\u0430\u0447\u0438\u043d\u0430\u044e\u0442\u0441\u044f \u0436\u0443\u0442\u043a\u0438\u0435 \u0442\u043e\u0440\u043c\u043e\u0437\u0430. \u0418 \u0442\u0430\u043a, \u0441\u0442\u0430\u0432\u0438\u043c <strong>ipset<\/strong>:<\/p>\n<p><code>#yum install ipset.x86_64<\/code><\/p>\n<p>\u041f\u043e\u0441\u043b\u0435 \u0443\u0441\u0442\u0430\u043d\u043e\u0432\u043a\u0438 \u0434\u043e\u0431\u0430\u0432\u043b\u0435\u043c \u043f\u0440\u0430\u0432\u0438\u043b\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u0432 <strong>iptables<\/strong>:<\/p>\n<p><code>#iptables -I INPUT 1 -m set --match-set dos src -j DROP<\/code><\/p>\n<p>\u0433\u0434\u0435 <strong>dos<\/strong> \u044d\u0442\u043e \u043d\u0430\u0448\u0430 \u0442\u0430\u0431\u043b\u0438\u0446\u0430 \u0438\u0437 <strong>ipset<\/strong>.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0445\u0435\u0448\u044c <strong>dos<\/strong>:<\/p>\n<p><code>#ipset -N dos iphash<\/code><\/p>\n<p>\u0415\u0441\u043b\u0438 \u043d\u0443\u0436\u043d\u043e \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0435\u0442\u0438, \u0442\u043e\u0433\u0434\u0430 \u0432\u043c\u0435\u0441\u0442\u043e <strong>iphash<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c <strong>nethash<\/strong><\/p>\n<p>\u041e\u0431\u044f\u0437\u0430\u0442\u0435\u043b\u044c\u043d\u043e \u0441\u043e\u0445\u0440\u0430\u043d\u044f\u0435\u043c <strong>iptables<\/strong>:<\/p>\n<p><code>#\/sbin\/service iptables save<\/code><\/p>\n<p>\u0414\u043b\u044f \u0430\u0432\u0442\u043e\u043c\u0430\u0442\u0438\u0447\u0435\u0441\u043a\u043e\u0439 \u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u043a\u0438 \u043f\u0438\u0448\u0435\u043c \u0442\u0430\u043a\u043e\u0439 \u0441\u043a\u0440\u0438\u043f\u0442 \u0438 \u043f\u043e\u043c\u0435\u0449\u0430\u0435\u043c \u0435\u0433\u043e \u0432 \u043a\u0440\u043e\u043d \u043d\u0430 \u0432\u044b\u043f\u043e\u043b\u043d\u0435\u043d\u0438\u0435 \u0440\u0430\u0437 \u0432 \u043c\u0438\u043d\u0443\u0442\u0443:<\/p>\n<p><code>#!\/bin\/bash<br \/>\nIFCONFIG=\/sbin\/ifconfig<br \/>\nGREP=\/bin\/grep<br \/>\nAWK=\/bin\/awk<br \/>\nCUT=\/bin\/cut<br \/>\nNETSTAT=\/bin\/netstat<br \/>\nIPSET=\/usr\/sbin\/ipset<br \/>\nIPTABLES=\/sbin\/iptables<br \/>\nSORT=\/bin\/sort<br \/>\nUNIQ=\/usr\/bin\/uniq<br \/>\nsrvIP=`$IFCONFIG eth0 | $GREP 'inet addr' | $AWK '{print $2}' | $CUT -f2 -d \":\"`<br \/>\nfor i in `$NETSTAT -ntu | $GREP SYN_RECV | $AWK '{print $5}' | $CUT -f1 -d \":\" | $SORT | $UNIQ | $GREP -v ${srvIP}`<br \/>\ndo<br \/>\n$IPSET -A dos $i<br \/>\ndone<br \/>\n$IPSET -S &gt; \/etc\/sysconfig\/ipset<\/code><\/p>\n<p>\u0414\u043b\u044f \u043f\u0440\u043e\u0441\u043c\u043e\u0442\u0440\u0430 \u0437\u0430\u0431\u043b\u043e\u043a\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u044b\u0445 \u0430\u0434\u0440\u0435\u0441\u043e\u0432 \u0432\u044b\u043f\u043e\u043b\u043d\u044f\u0435\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443<\/p>\n<p><code># ipset -L | head<br \/>\nName: dos<br \/>\nType: hash:ip<br \/>\nHeader: family inet hashsize 1024 maxelem 65536<br \/>\nSize in memory: 20104<br \/>\nReferences: 1<br \/>\nMembers:<br \/>\n200.170.151.14<br \/>\n196.21.39.13<br \/>\n180.250.209.2<br \/>\n203.89.27.150<br \/>\n# ipset -L | wc -l<br \/>\n269<\/code><\/p>\n<p>\u041d\u0430\u0448\u0451\u043b \u043d\u0435\u0434\u0430\u0432\u043d\u043e \u041f\u041e (\u00a0http:\/\/synflood-defender.net\/docs ) \u0442\u0438\u043f\u0430 \u0434\u043b\u044f \u0437\u0430\u0449\u0438\u0442\u044b \u043e\u0442 \u0430\u0442\u0430\u043a, \u043d\u043e \u043d\u0435 \u0441\u0438\u043b\u044c\u043d\u043e \u0432\u0435\u0440\u044e, \u0447\u0442\u043e \u043e\u043d\u043e \u043f\u043e\u043c\u043e\u0436\u0435\u0442 ))<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u0422\u0435\u0441\u0442\u043e\u0432\u044b\u0439 \u0441\u0442\u0435\u043d\u0434: Centos 6.2 (kernel 2.6.32-220.4.2.el6.x86_64), apache+php+mysql \u0418\u043c\u0435\u0435\u043c \u043e\u0447\u0435\u043d\u044c \u043c\u043d\u043e\u0433\u043e \u0441\u043e\u0435\u0434\u0438\u043d\u0435\u043d\u0438\u0439 \u0441 \u0441\u043e\u0441\u0442\u043e\u044f\u043d\u0438\u0435\u043c\u00a0SYN_RECV (syn flood): $netstat -ntu &#8230; tcp 0 0 XX.XX.XX.XX:80 202.51.102.34:40700 SYN_RECV tcp 0 0 XX.XX.XX.XX:80 190.225.143.29:40123 SYN_RECV tcp 0 0 XX.XX.XX.XX:80 101.255.71.7:38725 SYN_RECV tcp 0 0 XX.XX.XX.XX:80 122.226.122.201:48952 SYN_RECV tcp 0 0 XX.XX.XX.XX:80 186.91.63.97:44343 SYN_RECV tcp 0 0 XX.XX.XX.XX:80 109.230.156.97:56149 SYN_RECV &#8230; [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[5,13],"tags":[],"class_list":["post-4054","post","type-post","status-publish","format-standard","hentry","category-linux","category-security"],"_links":{"self":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/4054","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=4054"}],"version-history":[{"count":5,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/4054\/revisions"}],"predecessor-version":[{"id":4958,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=\/wp\/v2\/posts\/4054\/revisions\/4958"}],"wp:attachment":[{"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=4054"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=4054"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/skeletor.org.ua\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=4054"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}