{"id":608,"date":"2014-07-17T00:56:29","date_gmt":"2014-07-17T00:56:29","guid":{"rendered":"http:\/\/ixyzero.com\/blog\/?p=608"},"modified":"2014-07-17T00:56:29","modified_gmt":"2014-07-17T00:56:29","slug":"%e7%ae%80%e5%8d%95%e5%ae%9e%e7%8e%b0%e8%87%aa%e5%8a%a8%e8%bf%87%e6%bb%a4%e5%b1%8f%e8%94%bdweb%e6%94%bb%e5%87%bb%e6%ba%90ip","status":"publish","type":"post","link":"https:\/\/ixyzero.com\/blog\/archives\/608.html","title":{"rendered":"\u7b80\u5355\u5b9e\u73b0\u81ea\u52a8\u8fc7\u6ee4\/\u5c4f\u853dWEB\u653b\u51fb\u6e90IP"},"content":{"rendered":"<p>\u4e4b\u524d\u5176\u5b9e\u5f04\u8fc7\u4e00\u4e2a\u81ea\u52a8\u5c4f\u853d\u6076\u610f\u653b\u51fb\u8005\u7684IP\u7684\u811a\u672c{\u8fd8\u5199\u4e86\u7bc7\u6587\u7ae0\uff1a<a title=\"\u81ea\u52a8\u5c4f\u853d\u4e00\u4e9b\u6076\u610fIP\" href=\"http:\/\/ixyzero.com\/blog\/archives\/411.html\" target=\"_blank\">\u81ea\u52a8\u5c4f\u853d\u4e00\u4e9b\u6076\u610fIP<\/a>}\uff08\u4f46\u5176\u5b9e\u6211\u4e00\u76f4\u6ca1\u6709\u5b9e\u9645\u90e8\u7f72\u4e0a\u53bb\uff0c\u56e0\u4e3a\u770b\u4e86\u770b\u65e5\u5fd7\u6587\u4ef6\u53d1\u73b0\u672c\u6765\u8bbf\u95ee\u6d41\u91cf\u5c31\u4e0d\u5927\uff0c\u867d\u7136\u5176\u4e2d\u4e5f\u6709\u4e00\u4e9b\u662f\u626b\u63cf\u5668\u7684\u884c\u4e3a\uff0c\u4f46\u662f\u5bf9\u73b0\u5728\u7684blog\u8bbf\u95ee\u8fd8\u6ca1\u4ea7\u751f\u4ec0\u4e48\u5b9e\u9645\u5f71\u54cd\uff0c\u6240\u4ee5\u5c31\u6682\u65f6\u6401\u7f6e\u4e86\uff09\uff0c\u4f46\u662f\u6628\u5929\u5728\u6d4f\u89c8\u522b\u4eba\u7684blog\u65f6\u53d1\u73b0\u4e86\u7bc7\u6587\u7ae0\uff1a<a title=\"\u7b80\u5355\u5b9e\u73b0\u81ea\u52a8\u8fc7\u6ee4WEB\u653b\u51fb\u6e90IP\" href=\"http:\/\/heylinux.com\/archives\/3123.html\" target=\"_blank\">\u7b80\u5355\u5b9e\u73b0\u81ea\u52a8\u8fc7\u6ee4WEB\u653b\u51fb\u6e90IP<\/a>\uff0c\u89e3\u51b3\u4e86\u4e4b\u524d\u6211\u4e00\u76f4\u6ca1\u6709\u60f3\u5230\u8be5\u5982\u4f55\u5904\u7406\u7684\u51e0\u4e2a\u95ee\u9898\uff081.\u5982\u4f55\u907f\u514d\u5c4f\u853d\u81ea\u5df1\u7684IP\uff0c\u56e0\u4e3a\u73b0\u5728\u4f7f\u7528\u7684\u662fPPPoE\u7684\u62e8\u53f7\u5f0f\u7f51\u7edc\uff0c\u6ca1\u6709\u4e00\u4e2a\u56fa\u5b9a\u7684IP\uff0c\u800c\u81ea\u5df1\u53c8\u4f1a\u7ecf\u5e38\u4e0a\u81ea\u5df1\u7684blog\u770b\u770b\uff0c\u6709\u65f6\u662f\u4ee5\u7ba1\u7406\u5458\u8eab\u4efd\uff0c\u6709\u65f6\u5c31\u662f\u4ee5\u8bbf\u5ba2\u7684\u8eab\u4efd\uff0c\u5f53\u65f6\u6ca1\u6709\u60f3\u5230\u8be5\u5982\u4f55\u907f\u514d\u5c4f\u853d\u81ea\u5df1\u7684IP\u6240\u4ee5\u5c31\u6ca1\u6dfb\u52a0\u8fd9\u4e2a\u767d\u540d\u5355\u7684\u529f\u80fd&#8211;\u5176\u5b9e\u4e5f\u548c\u6211\u79df\u7684\u7b2c\u4e00\u53f0VPS\u65e0\u6cd5\u6267\u884clast\u547d\u4ee4\u6709\u5173\uff1b2.\u5b9a\u671f\u6e05\u9664\u8bb0\u5f55\uff1b3.\u5904\u7406\u5173\u4e8e\u8bc4\u8bba\u548c\u540e\u53f0\u767b\u9646\u9875\u9762\u7684\u8bbf\u95ee\uff09\uff0c\u6240\u4ee5\uff0c\u5c31\u53c8\u5173\u6ce8\u8d77\u4e86\u8fd9\u4e2a\u4e8b\u60c5\u3002\u56e0\u4e3a\u4ee3\u7801\u7684\u529f\u80fd\u5df2\u7ecf\u57fa\u672c\u4e0a\u6ee1\u8db3\u4e00\u822c\u8981\u6c42\uff08\u4f60\u53ef\u4ee5\u81ea\u5df1\u5728\u811a\u672c\u4e2d\u6dfb\u52a0\u51fd\u6570\u5b9e\u73b0\u7279\u5b9a\u529f\u80fd\uff0c\u5982\uff1a\u8bb0\u5f55\/\u5c4f\u853d\u8bbf\u95ee\u7279\u5b9aURL\u7684IP\uff09\u4e86\uff0c\u6240\u4ee5\u8fd9\u6b21\u4ee5\u5b66\u4e60\u4e3a\u4e3b\uff08\u800c\u4e14\u5404\u4eba\u78b0\u5230\u7684\u60c5\u51b5\u4e5f\u4e0d\u4e00\u6837\uff0c\u9700\u8981\u9002\u5f53\u505a\u51fa\u4fee\u6539\u4ee5\u7b26\u5408\u81ea\u5df1\u7684\u60c5\u51b5\uff0c\u811a\u672c\u4e2d\u7684\u60c5\u51b5\u5c31\u662f\uff1a<span style=\"color: rgb(255, 0, 0);\">\u6839\u636e\u5f53\u524d\u670d\u52a1\u5668\u7684\u8bbf\u95ee\u65e5\u5fd7\u6765\u770b\uff0c\u5982\u679c\u572810000\u4e2a\u8bf7\u6c42\u4e2d\uff0c\u67091000\u4e2a\u8bf7\u6c42\u6765\u81ea\u4e8e\u540c\u4e00\u4e2aIP\u7684\u8bdd\uff0c\u90a3\u4e48\u5176\u653b\u51fb\u7279\u5f81\u5c31\u975e\u5e38\u660e\u663e\u4e86\uff1b\u53e6\u5916\uff0c\u9488\u5bf9\u540e\u53f0\u767b\u9646\u9875\u9762\u548c\u8bc4\u8bba\u9875\u9762\uff0c\u5355\u72ec\u5236\u5b9a\u4e86\u66f4\u52a0\u4e25\u683c\u7684\u89c4\u5219\uff0c\u90a3\u5c31\u662f\u572810000\u6b21POST\u8bf7\u6c42\u4e2d\uff0c\u5982\u679c\u6709100\u6b21\u5c1d\u8bd5\uff0c\u5c31Block\u6389<\/span>\uff09\uff1a<\/p>\n<p>\u5c06\u4e0b\u9762\u7684shell\u811a\u672c\u4fdd\u5b58\u4e3a\/home\/rainbow\/sbin\/block_attack_ips.sh<\/p>\n<pre class=\"lang:sh decode:true\">#!\/bin\/bash\n\nlogfiles=(\n\/webserver\/blog\/logs\/rainbow_access.log\n\/webserver\/blog\/logs\/eric_access.log\n)\n\nwhitelist=$(last | grep -Ev '^$|mosh|reboot|wtmp' | awk '{print $3}' | sort | uniq | xargs)\n\nfunction check_root(){\n\tif [ $EUID -ne 0 ]; then\n\t\techo \"This script must be run as root\"\n\t\texit 1\n\tfi\n}\n\nfunction block_ips(){\n\tblacklist=$@\n\tif [ ! -z \"${blacklist}\" ]; then\n\t\tfor ip in ${blacklist}\n\t\tdo\n\t\t\tif ! $(echo ${whitelist} | grep -wq ${ip}); then\n\t\t\t\tif ! $(\/sbin\/iptables-save | grep -wq ${ip}); then\n\t\t\t\t\techo \"Blocked ${ip}\"\n\t\t\t\t\t\/sbin\/iptables -I INPUT -s ${ip}\/32 -p tcp -m tcp --dport 80 -j DROP\n\t\t\t\tfi\n\t\t\tfi\n\t\tdone\n\tfi\n}\n\nfunction check_post(){\n\tpage=$1\t# the URL's path info\n\ttailnum=$2\n\tretry=$3\t# specify the retry times\n\n\tcommand=\"grep -w POST ${logfile} |tail -n ${tailnum} |grep -w ${page} |awk '{print $1}' |sort |uniq -c |awk '($1 &gt; ${retry}){print $2}'\"\n\tblacklist=$(eval ${command})\n\tblock_ips ${blacklist}\n}\n\nfunction check_all(){\n\ttailnum=$1\n\tretry=$2\n\n\tcommand=\"tail -n ${tailnum} ${logfile} |awk '{print $1}' |sort |uniq -c |awk '($1 &gt; ${retry}){print $2}'\"\n\tblacklist=$(eval ${command})\n\tblock_ips ${blacklist}\n}\n\ncheck_root\nfor logfile in ${logfiles[@]}\ndo\n\tcheck_post wp-login.php 10000 100\n\tcheck_post wp-comments-post.php 10000 100\n\tcheck_all 10000 1000\ndone<\/pre>\n<p>\u6dfb\u52a0\u53ef\u6267\u884c\u6743\u9650\uff1a<\/p>\n<pre class=\"lang:default decode:true \"># chmod +x \/home\/rainbow\/sbin\/block_attack_ips.sh<\/pre>\n<p>\u914d\u7f6ecrontab\u8ba1\u5212\u4efb\u52a1\uff0c\u6bcf5\u5206\u949f\u6267\u884c\u4e00\u6b21\uff0c\u6bcf\u5929\u5b9a\u65f6\u91cd\u542fiptables\u670d\u52a1\u4ee5\u6e05\u9664\u65e7\u7684\u8bb0\u5f55\uff1a<\/p>\n<pre class=\"lang:default decode:true \"># sudo crontab -e\n# *\/5 * * * * \/home\/rainbow\/sbin\/block_attack_ips.sh\n# 00 01 * * * \/etc\/init.d\/iptables restart\n# 00 01 * * * \/sbin\/iptables -F\n#\u56e0\u4e3a\u5728Ubuntu12.04\u4e0a\u9762\u6ca1\u6709\"\/etc\/init.d\/iptables\"\u6216\u662f\"service iptables restart\"\u8fd9\u6837\u7684\u547d\u4ee4\uff0c\u6240\u4ee5\uff0c\u53ef\u4ee5\u4f7f\u7528\u547d\u4ee4\"\/sbin\/iptables -F\"\u6765\u8fbe\u5230\u6e05\u9664\u8bb0\u5f55\u7684\u76ee\u7684<\/pre>\n<p>\u53c2\u8003\u6587\u7ae0\uff1a<\/p>\n<p><a href=\"http:\/\/heylinux.com\/archives\/3123.html\" target=\"_blank\">\u7b80\u5355\u5b9e\u73b0\u81ea\u52a8\u8fc7\u6ee4WEB\u653b\u51fb\u6e90IP \u00ab Hey! Linux.<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u4e4b\u524d\u5176\u5b9e\u5f04\u8fc7\u4e00\u4e2a\u81ea\u52a8\u5c4f\u853d\u6076\u610f\u653b\u51fb\u8005\u7684IP\u7684\u811a\u672c{\u8fd8\u5199\u4e86\u7bc7\u6587\u7ae0\uff1a\u81ea\u52a8\u5c4f\u853d\u4e00\u4e9b\u6076\u610fIP}\uff08\u4f46\u5176\u5b9e\u6211\u4e00\u76f4\u6ca1\u6709\u5b9e\u9645\u90e8\u7f72 [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,7,25,12],"tags":[29,65],"class_list":["post-608","post","type-post","status-publish","format-standard","hentry","category-linux","category-programing","category-security","category-tools","tag-iptables","tag-shell"],"views":3749,"_links":{"self":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/608","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/comments?post=608"}],"version-history":[{"count":0,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/posts\/608\/revisions"}],"wp:attachment":[{"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/media?parent=608"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/categories?post=608"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/ixyzero.com\/blog\/wp-json\/wp\/v2\/tags?post=608"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}