{"id":36313,"date":"2024-10-01T06:36:31","date_gmt":"2024-09-30T22:36:31","guid":{"rendered":"https:\/\/server.hk\/cnblog\/36313\/"},"modified":"2024-10-01T06:36:31","modified_gmt":"2024-09-30T22:36:31","slug":"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8modsecurity-core-rule-set-crs","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/36313\/","title":{"rendered":"Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528ModSecurity Core Rule Set (CRS)"},"content":{"rendered":"<h1 id=\"apache%e5%ae%89%e5%85%a8%e7%ad%96%e7%95%a5%ef%bc%9a%e4%bd%bf%e7%94%a8modsecurity-core-rule-set-crs-nLZEbWUvCq\">Apache\u5b89\u5168\u7b56\u7565\uff1a\u4f7f\u7528ModSecurity Core Rule Set (CRS)<\/h1>\n<p>\u5728\u7576\u4eca\u7684\u7db2\u7d61\u74b0\u5883\u4e2d\uff0c\u7db2\u7ad9\u5b89\u5168\u6027\u8b8a\u5f97\u8d8a\u4f86\u8d8a\u91cd\u8981\u3002Apache\u4f5c\u70ba\u6700\u6d41\u884c\u7684\u7db2\u9801\u4f3a\u670d\u5668\u4e4b\u4e00\uff0c\u63d0\u4f9b\u4e86\u591a\u7a2e\u5b89\u5168\u63aa\u65bd\u4f86\u4fdd\u8b77\u7db2\u7ad9\u514d\u53d7\u5404\u7a2e\u653b\u64ca\u3002\u5176\u4e2d\uff0cModSecurity\u662f\u4e00\u500b\u5f37\u5927\u7684Web\u61c9\u7528\u9632\u706b\u7246\uff08WAF\uff09\uff0c\u800cCore Rule Set (CRS)\u5247\u662f\u5176\u4e00\u500b\u91cd\u8981\u7684\u7d44\u4ef6\uff0c\u80fd\u5920\u6709\u6548\u5730\u589e\u5f37Apache\u7684\u5b89\u5168\u6027\u3002<\/p>\n<h2 id=\"%e4%bb%80%e9%ba%bc%e6%98%afmodsecurity%ef%bc%9f-nLZEbWUvCq\">\u4ec0\u9ebc\u662fModSecurity\uff1f<\/h2>\n<p>ModSecurity\u662f\u4e00\u500b\u958b\u6e90\u7684Web\u61c9\u7528\u9632\u706b\u7246\uff0c\u65e8\u5728\u63d0\u4f9b\u5c0dWeb\u61c9\u7528\u7684\u4fdd\u8b77\u3002\u5b83\u53ef\u4ee5\u6aa2\u6e2c\u548c\u963b\u6b62\u5404\u7a2e\u653b\u64ca\uff0c\u5305\u62ecSQL\u6ce8\u5165\u3001\u8de8\u7ad9\u8173\u672c\uff08XSS\uff09\u548c\u5176\u4ed6\u5e38\u898b\u7684Web\u653b\u64ca\u3002ModSecurity\u7684\u9748\u6d3b\u6027\u4f7f\u5176\u80fd\u5920\u6839\u64da\u7279\u5b9a\u9700\u6c42\u9032\u884c\u914d\u7f6e\uff0c\u4e26\u4e14\u53ef\u4ee5\u8207\u591a\u7a2eWeb\u4f3a\u670d\u5668\uff08\u5982Apache\u3001Nginx\u548cIIS\uff09\u4e00\u8d77\u4f7f\u7528\u3002<\/p>\n<h2 id=\"core-rule-set-crs%e7%9a%84%e4%bb%8b%e7%b4%b9-nLZEbWUvCq\">Core Rule Set (CRS)\u7684\u4ecb\u7d39<\/h2>\n<p>Core Rule Set (CRS)\u662f\u4e00\u7d44\u9810\u5b9a\u7fa9\u7684\u898f\u5247\uff0c\u65e8\u5728\u4fdd\u8b77Web\u61c9\u7528\u514d\u53d7\u5e38\u898b\u653b\u64ca\u3002\u9019\u4e9b\u898f\u5247\u6db5\u84cb\u4e86\u591a\u7a2e\u653b\u64ca\u5411\u91cf\uff0c\u4e26\u4e14\u53ef\u4ee5\u6839\u64da\u5be6\u969b\u9700\u6c42\u9032\u884c\u8abf\u6574\u3002CRS\u7684\u4e3b\u8981\u7279\u9ede\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u5373\u6642\u4fdd\u8b77\uff1a<\/strong>CRS\u80fd\u5920\u5373\u6642\u6aa2\u6e2c\u548c\u963b\u6b62\u653b\u64ca\uff0c\u5f9e\u800c\u6e1b\u5c11\u6f5b\u5728\u7684\u640d\u5931\u3002<\/li>\n<li><strong>\u6613\u65bc\u914d\u7f6e\uff1a<\/strong>CRS\u7684\u5b89\u88dd\u548c\u914d\u7f6e\u76f8\u5c0d\u7c21\u55ae\uff0c\u9069\u5408\u5404\u7a2e\u6280\u8853\u6c34\u5e73\u7684\u7528\u6236\u3002<\/li>\n<li><strong>\u6301\u7e8c\u66f4\u65b0\uff1a<\/strong>CRS\u793e\u5340\u4e0d\u65b7\u66f4\u65b0\u898f\u5247\uff0c\u4ee5\u61c9\u5c0d\u65b0\u51fa\u73fe\u7684\u5a01\u8105\u3002<\/li>\n<\/ul>\n<h2 id=\"%e5%a6%82%e4%bd%95%e5%ae%89%e8%a3%9d%e5%92%8c%e9%85%8d%e7%bd%aemodsecurity%e8%88%87crs-nLZEbWUvCq\">\u5982\u4f55\u5b89\u88dd\u548c\u914d\u7f6eModSecurity\u8207CRS<\/h2>\n<p>\u4ee5\u4e0b\u662f\u5b89\u88dd\u548c\u914d\u7f6eModSecurity\u53caCRS\u7684\u57fa\u672c\u6b65\u9a5f\uff1a<\/p>\n<h3 id=\"1-%e5%ae%89%e8%a3%9dmodsecurity-nLZEbWUvCq\">1. \u5b89\u88ddModSecurity<\/h3>\n<pre><code>sudo apt-get install libapache2-mod-security2<\/code><\/pre>\n<p>\u5b89\u88dd\u5b8c\u6210\u5f8c\uff0c\u555f\u7528ModSecurity\u6a21\u7d44\uff1a<\/p>\n<pre><code>sudo a2enmod security2<\/code><\/pre>\n<h3 id=\"2-%e4%b8%8b%e8%bc%89%e5%92%8c%e5%ae%89%e8%a3%9dcore-rule-set-nLZEbWUvCq\">2. \u4e0b\u8f09\u548c\u5b89\u88ddCore Rule Set<\/h3>\n<p>\u53ef\u4ee5\u5f9eCRS\u7684\u5b98\u65b9GitHub\u9801\u9762\u4e0b\u8f09\u6700\u65b0\u7248\u672c\uff1a<\/p>\n<pre><code>git clone https:\/\/github.com\/coreruleset\/coreruleset.git<\/code><\/pre>\n<p>\u5c07\u4e0b\u8f09\u7684\u6587\u4ef6\u79fb\u52d5\u5230Apache\u7684\u914d\u7f6e\u76ee\u9304\u4e2d\uff1a<\/p>\n<pre><code>sudo mv coreruleset \/etc\/modsecurity\/<\/code><\/pre>\n<h3 id=\"3-%e9%85%8d%e7%bd%aemodsecurity%e4%bd%bf%e7%94%a8crs-nLZEbWUvCq\">3. \u914d\u7f6eModSecurity\u4f7f\u7528CRS<\/h3>\n<p>\u7de8\u8f2fModSecurity\u7684\u914d\u7f6e\u6587\u4ef6\uff0c\u555f\u7528CRS\uff1a<\/p>\n<pre><code>sudo nano \/etc\/modsecurity\/modsecurity.conf<\/code><\/pre>\n<p>\u5c07\u4ee5\u4e0b\u884c\u53d6\u6d88\u8a3b\u89e3\uff1a<\/p>\n<pre><code>SecRuleEngine On<\/code><\/pre>\n<p>\u7136\u5f8c\u5728Apache\u7684\u914d\u7f6e\u6587\u4ef6\u4e2d\u6dfb\u52a0CRS\u7684\u8def\u5f91\uff1a<\/p>\n<pre><code>Include \/etc\/modsecurity\/coreruleset\/crs-setup.conf<\/code><\/pre>\n<pre><code>Include \/etc\/modsecurity\/coreruleset\/rules\/*.conf<\/code><\/pre>\n<h3 id=\"4-%e9%87%8d%e5%95%9fapache%e4%bc%ba%e6%9c%8d%e5%99%a8-nLZEbWUvCq\">4. \u91cd\u555fApache\u4f3a\u670d\u5668<\/h3>\n<pre><code>sudo systemctl restart apache2<\/code><\/pre>\n<h2 id=\"modsecurity-crs%e7%9a%84%e5%84%aa%e5%8b%a2-nLZEbWUvCq\">ModSecurity CRS\u7684\u512a\u52e2<\/h2>\n<p>\u4f7f\u7528ModSecurity CRS\u7684\u4e3b\u8981\u512a\u52e2\u5305\u62ec\uff1a<\/p>\n<ul>\n<li><strong>\u81ea\u52d5\u5316\u9632\u8b77\uff1a<\/strong>CRS\u80fd\u5920\u81ea\u52d5\u6aa2\u6e2c\u4e26\u963b\u6b62\u591a\u7a2e\u653b\u64ca\uff0c\u6e1b\u5c11\u4e86\u624b\u52d5\u5e72\u9810\u7684\u9700\u6c42\u3002<\/li>\n<li><strong>\u9748\u6d3b\u6027\uff1a<\/strong>\u7528\u6236\u53ef\u4ee5\u6839\u64da\u5177\u9ad4\u9700\u6c42\u8abf\u6574\u898f\u5247\uff0c\u589e\u5f37\u9632\u8b77\u6548\u679c\u3002<\/li>\n<li><strong>\u793e\u5340\u652f\u6301\uff1a<\/strong>CRS\u64c1\u6709\u6d3b\u8e8d\u7684\u793e\u5340\uff0c\u63d0\u4f9b\u6301\u7e8c\u7684\u66f4\u65b0\u548c\u652f\u6301\u3002<\/li>\n<\/ul>\n<h2 id=\"%e7%b5%90%e8%ab%96-nLZEbWUvCq\">\u7d50\u8ad6<\/h2>\n<p>\u5728\u7576\u524d\u7684\u7db2\u7d61\u5b89\u5168\u74b0\u5883\u4e2d\uff0c\u4f7f\u7528ModSecurity\u548cCore Rule Set (CRS)\u662f\u4fdd\u8b77Apache\u4f3a\u670d\u5668\u7684\u91cd\u8981\u63aa\u65bd\u3002\u901a\u904e\u6b63\u78ba\u7684\u5b89\u88dd\u548c\u914d\u7f6e\uff0c\u7db2\u7ad9\u7ba1\u7406\u54e1\u53ef\u4ee5\u6709\u6548\u5730\u9632\u6b62\u5404\u7a2e\u653b\u64ca\uff0c\u4fdd\u8b77\u7528\u6236\u6578\u64da\u548c\u7db2\u7ad9\u7684\u5b8c\u6574\u6027\u3002\u5c0d\u65bc\u5c0b\u6c42\u5b89\u5168\u89e3\u6c7a\u65b9\u6848\u7684\u7528\u6236\uff0c\u9078\u64c7\u5408\u9069\u7684VPS\u6216\u4f3a\u670d\u5668\u662f\u81f3\u95dc\u91cd\u8981\u7684\u3002\u4e86\u89e3\u66f4\u591a\u95dc\u65bc<a href=\"https:\/\/server.hk\">\u9999\u6e2fVPS<\/a>\u548c<a href=\"https:\/\/server.hk\">\u4f3a\u670d\u5668<\/a>\u7684\u8cc7\u8a0a\uff0c\u53ef\u4ee5\u5e6b\u52a9\u60a8\u505a\u51fa\u660e\u667a\u7684\u9078\u64c7\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Learn how to enhance Apache security with ModSecurity Core Rule Set (CRS) to protect your web applications from various threats effectively.<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4924],"tags":[],"class_list":["post-36313","post","type-post","status-publish","format-standard","hentry","category-setup-tutorials"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36313","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=36313"}],"version-history":[{"count":1,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36313\/revisions"}],"predecessor-version":[{"id":36314,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/36313\/revisions\/36314"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=36313"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=36313"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=36313"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}