<\/a><\/figure>\n\n\n\n\u53ef\u4ee5\u5229\u7528redis\u7684\u9ad8\u6027\u80fd\u4f18\u52bf\u53bb\u505a\u4e00\u4e9b\u6587\u7ae0\u3002<\/p>\n\n\n\n
\u539f\u7406\u5c31\u662f\u7528\u7f51\u7ad9\u7a0b\u5e8f\u53bb\u5224\u65ad\u7528\u6237\u7684\u8bf7\u6c42\uff0c\u5982\u679c\u5224\u65ad\u51fa\u662f\u6076\u610f\u7684\uff0c\u90a3\u4e48\u628a\u8be5\u8bbf\u95ee\u8005\u8bb0\u5f55\u4e0b\u6765\u5b58\u50a8\u5230redis\u4e2d\u53bb\u3002\u5982\u679c\u8be5\u8bbf\u95ee\u8005\u518d\u6765\u8bf7\u6c42\uff0c\u90a3\u4e48\u76f4\u63a5\u7ed9\u4ed6\u8fd4\u56de500\u3002\u6b63\u5e38\u60c5\u51b5\u6765\u8bb2\uff0c\u9ed1\u5ba2\u7684\u626b\u63cf\u5de5\u5177\u5f97\u77e5500\u76f8\u5e94\u7801\u540e\uff0c\u5e94\u8be5\u4f1a\u505c\u6b62\u626b\u63cf\u5427\u3002\u5c31\u7b97\u4e0d\u505c\u6b62\uff0c\u90a3\u4e48redis\u7684\u9ad8\u6027\u80fd\u4e5f\u53ef\u4ee5\u62b5\u6321\u8fd9\u4e9b\u975e\u6cd5\u626b\u63cf\u8bf7\u6c42\uff0c\u4ece\u800c\u8fbe\u5230\u4fdd\u62a4\u670d\u52a1\u5668\u7684\u76ee\u7684\u3002\u901a\u5e38\u53ef\u4ee5\u8bbe\u7f6e\u4e00\u4e2a\u5c0f\u65f6\u5185\u7981\u6b62\u8be5ip\u7684\u6b63\u5e38\u8bbf\u95ee\u3002\u65f6\u95f4\u53ef\u4ee5\u81ea\u5df1\u8bbe\u7f6e\u3002<\/p>\n\n\n\n
\u5982\u4f55\u5224\u65ad\u6076\u610f\u8bbf\u95ee\uff1a\u6bd4\u5982\u6211\u7684\u662fphp\u7a0b\u5e8f\uff0c\u5982\u679c\u7528\u6237\u7684\u8bf7\u6c42\u4e2d\u51fa\u73b0\u4e86 .asp\u6216\u8005.jsp\uff0c\u6216\u8005hack,hacker\u5b57\u6837\uff0c\u90a3\u4e48\u5c31\u5224\u65ad\u4f60\u5c0f\u5b50\u4e0d\u8001\u5b9e\uff0c\u5c31\u6253\u5165\u51b7\u5bab\u3002\u81f3\u4e8e\u52a0\u54ea\u4e9b\u5224\u65ad\u5b57\u7b26\u53ef\u4ee5\u6839\u636e\u81ea\u5df1\u7684\u9700\u6c42\u8fdb\u884c\u8bbe\u7f6e\u3002<\/p>\n\n\n\n
\u9700\u8981\u670d\u52a1\u5668\u5b89\u88c5redis\uff0c\u6211\u8fd9\u91cc\u662f\u7528\u7684php\u505a\u4e86\u4e00\u4e2a\u793a\u4f8b\uff0c\u6211\u7684php\u6587\u4ef6\u540d\u4e3a\u3010illegal_deny.php\u3011\uff0c\u7528\u6237\u53ef\u4ee5\u76f4\u63a5\u5728\u7ad9\u70b9\u5165\u53e3\u5305\u542b\u6b64\u6587\u4ef6\u5373\u53ef\u3002 <\/p>\n\n\n\n
require __DIR__.'\/..\/app\/diy\/illegal_deny.php';\n<\/code><\/pre>\n\n\n\n\u4e0b\u8fb9\u662f\u6587\u4ef6\u5185\u5bb9\u3002\u8bf7\u6839\u636e\u81ea\u5df1\u7684\u5b9e\u9645\u60c5\u51b5\u8fdb\u884c\u4fee\u6539\u3002<\/p>\n\n\n\n
<?php\n\/\/redis\u7684\u914d\u7f6e\n\/\/define('REDIS_SERVER_IP', '121.40.24.38');\ndefine('REDIS_SERVER_IP', '127.0.0.1');\ndefine('REDIS_SERVER_PORT', 6379);\n\/\/auth\u5c31\u662f\u5bc6\u7801\ndefine('REDIS_SERVER_AUTH', 'yourpassword');\n\n\/\/\u7981\u6b62\u8bbf\u95ee\u7684\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2 3600 = 1\u5c0f\u65f6\ndefine('DENY_TIME', 3600);\n\n\nfunction getRedis($db = 0){\n \n $redis = new \\Redis();\n $res = $redis->connect(REDIS_SERVER_IP,REDIS_SERVER_PORT);\n $redis->auth(REDIS_SERVER_AUTH);\n $redis->select($db);\n return $redis;\n}\n\n\/\/\u5982\u679c\u662f\u8bbf\u95ee\u4e00\u4e9b\u975e\u6cd5\u7f51\u5740\uff0c\u6bd4\u5982\u9ed1\u5ba2\uff0c\u5c31\u8fdb\u884c\u4e00\u6bb5\u65f6\u95f4\u7684\u8bbf\u95ee\u5c4f\u853d begin\n\/\/\u975e\u6cd5\u8bbf\u95ee\u6b21\u6570\n$illegal_attempt_count_key = 'ILLEGAL_ATTEMPT_COUNT';\n\n\/\/\u662f\u5426\u5df2\u7ecf\u88ab\u9650\u5236\u8bbf\u95ee\n$illegal_key = \"ILLEGAL_IP_\".$_SERVER['REMOTE_ADDR'];\n\/\/$illegal_key = \"ILLEGAL_IP_\".$_SERVER['HTTP_X_FORWARDED_FOR'];\n\n\n\n$uri = $_SERVER['REQUEST_URI'];\n\n\n$redis = getRedis();\n\/\/$redis->delete($illegal_key);\nif($redis->exists($illegal_key)){\n \n header('HTTP\/1.1 500 Internal Server Error');\n exit(0);\n}\n\n$limit_time = DENY_TIME;\/\/\u7981\u6b62\u65f6\u95f4\uff0c\u5355\u4f4d\u79d2\n\/\/\u5224\u65ad\u662f\u5426\u8981\u8fdb\u884c\u9650\u5236\n\n\/\/\u51e0\u4e2a\u7981\u6b62\u8bbf\u95ee\u7684\u76ee\u5f55\nif($uri == '\/admin'){\n \/\/\n $redis->setex($illegal_key,$limit_time,date(\"Y-m-d H:i:s\",time()));\n $redis->incr($illegal_attempt_count_key);\n header('HTTP\/1.1 500 Internal Server Error');\n exit(0);\n}\n\n\/\/\u9650\u5236\u8bbf\u95ee\u5730\u5740\u5305\u542b\u7684\u4e00\u4e9b\u5173\u952e\u8bcd\uff0c\u53ea\u8981\u5339\u914d\u5230\u5c31\u8fdb\u884c\u9650\u5236\n$illegal_urls = ['hack','hacker','.asp','.jsp'];\nforeach ($illegal_urls as $url){\n if(strpos($uri, $url)){\n \/\/\n $redis->setex($illegal_key,$limit_time,date(\"Y-m-d H:i:s\",time()));\n $redis->incr($illegal_attempt_count_key);\n \n header('HTTP\/1.1 500 Internal Server Error');\n exit(0);\n }\n}\n\/\/\u5982\u679c\u662f\u8bbf\u95ee\u4e00\u4e9b\u975e\u6cd5\u7f51\u5740\uff0c\u6bd4\u5982\u9ed1\u5ba2\uff0c\u5c31\u8fdb\u884c\u4e00\u6bb5\u65f6\u95f4\u7684\u8bbf\u95ee\u5c4f\u853d over\n<\/code><\/pre>\n\n\n\n\n
\n
\n
\n\n\n\n
\u9644\uff1a\u5bf9\u6211\u76841cpu2G\u5185\u5b58\u7684\u670d\u52a1\u5668\u52a0\u4e86\u8fd9\u4e2a\u3010\u62a4\u76fe\u3011\u540e\uff0c\u670d\u52a1\u5668\u5c31\u4e0d\u4f1a\u518d\u62a5\u8b66\u4e86\uff08\u4e4b\u524d\u662fcpu \u4e00\u65e6\u8fc790%\u4f7f\u7528\u7387\u5c31\u4f1a\u53d1\u90ae\u4ef6\uff0c\u77ed\u4fe1\uff0c\u597d\u70e6\uff09\u3002\u771f\u9999\uff01\u8c01\u7528\u8c01\u8bf4\u597d\u3002<\/p>\n<\/div><\/div>\n<\/div>\n<\/div>\n\n\n\n
<\/p>\n","protected":false},"excerpt":{"rendered":"
\u4e00\u4e9b\u5c0f\u9ed1\u5ba2\u4f1a\u8bd5\u56fe\u901a\u8fc7\u6b63\u5e38\u7684\u4f46\u9ad8\u9891\u7684\u3010\u6b63\u5e38\u8bbf\u95ee\u3011\u53bb\u67e5\u770b\u6211\u4eec\u7f51\u7ad9\u7684\u4e00\u4e9b\u9690\u85cf\u7684\u9875\u9762\uff0c\u6bd4\u5982\u7ba1\u7406\u5458\u767b\u5f55\u9875\u9762\u3002\u8fd8\u6709\u4e00\u79cd\u6bd4\u8f83\u5e38\u89c1\u7684\u662f\u53bb\u626b\u63cf\u4e00\u4e9b \u884c\u4e1a\u5185\u7684 \u73b0\u6210\u7684 \u6728\u9a6c\u6587\u4ef6\uff0c\u6765\u653b\u51fb\u6211\u4eec\u7684\u7f51\u7ad9\u3002\u56e0\u4e3a\u77ed\u65f6\u95f4\u5185\u4f1a\u6709\u5927\u91cf\u7684\u770b\u4f3c\u6b63\u5e38\u7684\u8bf7\u6c42\uff0c\u4f1a\u9020\u6210\u6027\u80fd\u4e0d\u9ad8\u7684\u670d\u52a1\u5668\u7684\u62a5\u8b66\uff0c\u5982\u5185\u5b58\u6216\u8005cpu\uff0c\u751a\u81f3\u5e26\u5bbd \u5403\u7d27\uff0c\u5f71\u54cd\u6b63\u5e38\u670d\u52a1\u3002 \u4e0b\u56fe\u4e3a\u975e\u6cd5\u8bf7\u6c42\u793a\u4f8b \u53ef\u4ee5\u5229\u7528redis\u7684\u9ad8\u6027\u80fd\u4f18\u52bf\u53bb\u505a\u4e00\u4e9b\u6587\u7ae0\u3002 \u539f\u7406\u5c31\u662f\u7528\u7f51\u7ad9\u7a0b\u5e8f\u53bb\u5224\u65ad\u7528\u6237\u7684\u8bf7\u6c42\uff0c\u5982\u679c\u5224\u65ad\u51fa\u662f\u6076\u610f\u7684\uff0c\u90a3\u4e48\u628a\u8be5\u8bbf\u95ee\u8005\u8bb0\u5f55\u4e0b\u6765\u5b58\u50a8\u5230redis\u4e2d\u53bb\u3002\u5982\u679c\u8be5\u8bbf\u95ee\u8005\u518d\u6765\u8bf7\u6c42\uff0c\u90a3\u4e48\u76f4\u63a5\u7ed9\u4ed6\u8fd4\u56de500\u3002\u6b63\u5e38\u60c5\u51b5\u6765\u8bb2\uff0c\u9ed1\u5ba2\u7684\u626b\u63cf\u5de5\u5177\u5f97\u77e5500\u76f8\u5e94\u7801\u540e\uff0c\u5e94\u8be5\u4f1a\u505c\u6b62\u626b\u63cf\u5427\u3002\u5c31\u7b97\u4e0d\u505c\u6b62\uff0c\u90a3\u4e48redis\u7684<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[1,224],"tags":[304,303,305],"_links":{"self":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1932"}],"collection":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/comments?post=1932"}],"version-history":[{"count":6,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1932\/revisions"}],"predecessor-version":[{"id":1944,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/posts\/1932\/revisions\/1944"}],"wp:attachment":[{"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/media?parent=1932"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/categories?post=1932"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.youthtribe.com\/wp-json\/wp\/v2\/tags?post=1932"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}