{"id":423415,"date":"2021-04-03T12:54:33","date_gmt":"2021-04-03T04:54:33","guid":{"rendered":"http:\/\/4563.org\/?p=423415"},"modified":"2021-04-03T12:54:33","modified_gmt":"2021-04-03T04:54:33","slug":"ngx_waf-%e5%ae%8c%e6%95%b4%e3%80%81%e7%ae%80%e5%8d%95%e3%80%81%e9%ab%98%e6%80%a7%e8%83%bd%e7%9a%84-nginx-%e9%98%b2%e7%81%ab%e5%a2%99%e6%a8%a1%e5%9d%97","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=423415","title":{"rendered":"ngx_waf&#8211;\u5b8c\u6574\u3001\u7b80\u5355\u3001\u9ad8\u6027\u80fd\u7684 nginx \u9632\u706b\u5899\u6a21\u5757"},"content":{"rendered":"<div>\n<div>\n<div>\n<h1>                  ngx_waf&#8211;\u5b8c\u6574\u3001\u7b80\u5355\u3001\u9ad8\u6027\u80fd\u7684 nginx \u9632\u706b\u5899\u6a21\u5757               <\/h1>\n<p> <\/p>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : c137rick <\/span>  <span><i><\/i> 0<\/span> <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<\/p><\/div>\n<div isfirst=\"1\"> <\/p>\n<p>ngx_waf \u662f\u4e00\u4e2a\u7528 C \u8bed\u8a00\u5f00\u53d1\u7684 nginx \u9632\u706b\u5899\u6a21\u5757\u3002<\/p>\n<h2>\u76f8\u5173\u94fe\u63a5<\/h2>\n<p>Github\uff1a https:\/\/github.com\/ADD-SP\/ngx_waf<\/p>\n<p>\u6587\u6863\u4e5f\u53ef\u4ee5\u5728 Github \u4e0a\u627e\u5230\uff0c\u6587\u6863\u81ea\u8ba4\u4e3a\u5f88\u8be6\u7ec6\u3002<\/p>\n<h2>\u529f\u80fd\u5b8c\u6574<\/h2>\n<ul>\n<li>IP \u9ed1\u767d\u540d\u5355\uff0c\u652f\u6301 IPV4 \u548c IPV6\uff0c\u652f\u6301\u5730\u5740\u5757\u7684\u8868\u793a\u3002<\/li>\n<li>CC \u9632\u62a4\uff0c\u81ea\u52a8\u62c9\u9ed1\u6076\u610f IP \u4e00\u6bb5\u65f6\u95f4\u3002<\/li>\n<li>URL \u548c Referer \u9ed1\u767d\u540d\u5355\uff0c\u4f7f\u7528\u6b63\u5219\u5199\u89c4\u5219\u3002<\/li>\n<li>POST \u3001User-Agent \u3001Query String \u548c Cookie \u9ed1\u540d\u5355\uff0c\u4f7f\u7528\u6b63\u5219\u5199\u89c4\u5219\u3002<\/li>\n<\/ul>\n<h2>\u4f7f\u7528\u7b80\u5355<\/h2>\n<p>\u914d\u7f6e\u7b80\u5355\uff0c\u914d\u7f6e\u53ea\u9700\u8981\u4e94\u884c\u3002\u63d0\u4f9b\u9ed8\u8ba4\u89c4\u5219\uff0c\u5f00\u7bb1\u5373\u7528\u3002<\/p>\n<pre><code># on \u8868\u793a\u542f\u7528\uff0coff \u8868\u793a\u5173\u95ed\u3002 waf on;  # \u89c4\u5219\u6587\u4ef6\u6240\u5728\u76ee\u5f55\u7684\u7edd\u5bf9\u8def\u5f84\uff0c\u5fc5\u987b\u4ee5 \/ \u7ed3\u5c3e\u3002 waf_rule_path \/path\/to\/rules\/;  # \u9632\u706b\u5899\u5de5\u4f5c\u6a21\u5f0f\uff0cSTD \u8868\u793a\u6807\u51c6\u6a21\u5f0f\u3002 waf_mode STD;  # CC \u9632\u5fa1\u53c2\u6570\uff0c1000 \u6bcf\u5206\u949f\u8bf7\u6c42\u6b21\u6570\u4e0a\u9650\uff0c60 \u8868\u793a\u8d85\u51fa\u4e0a\u9650\u540e\u5c01\u7981\u5bf9\u5e94 ip 60 \u5206\u949f\u3002 waf_cc_deny_limit 1000 60;  # \u7528\u4e8e\u7f13\u5b58\u68c0\u67e5\u7ed3\u679c\u7684\u5185\u5b58\u7a7a\u95f4\u7684\u5927\u5c0f\uff0c\u8bbe\u7f6e\u4e3a 10 MB \u3002\u76ee\u524d\u4ec5\u5f00\u53d1\u7248\u53ef\u7528\u3002 waf_cache_size 10m; <\/code><\/pre>\n<h2>\u9ad8\u6027\u80fd<\/h2>\n<p>IP \u9ed1\u767d\u540d\u5355\u7684\u68c0\u67e5\u82b1\u8d39\u5e38\u6570\u65f6\u95f4\uff0c\u5373\u82b1\u8d39\u7684\u65f6\u95f4\u4e0e IP \u9ed1\u767d\u540d\u5355\u7684\u89c4\u6a21\u65e0\u5173\u3002<\/p>\n<p>\u5176\u4f59\u7684\u68c0\u67e5\u4f1a\u6328\u4e2a\u5339\u914d\u6b63\u5219\uff0c\u76f4\u5230\u5339\u914d\u5230\u4e3a\u6b62\u3002\u5339\u914d\u7ed3\u679c\u4f1a\u88ab\u7f13\u5b58\u8d77\u6765\uff0c\u4e0b\u6b21\u68c0\u67e5\u65f6\u5c31\u53ef\u4ee5\u76f4\u63a5\u8bfb\u53d6\u7f13\u5b58\u7684\u7ed3\u679c\u3002<strong>\u76ee\u524d\u4ec5\u5f00\u53d1\u7248\u542f\u7528\u4e86\u7f13\u5b58\uff0c\u7ecf\u8fc7\u6d4b\u8bd5\u5df2\u7ecf\u57fa\u672c\u7a33\u5b9a\u3002<\/strong><\/p>\n<p><em>POST \u68c0\u67e5\u7684\u7ed3\u679c\u4e0d\u4f1a\u7f13\u5b58\uff0c\u56e0\u4e3a\u592a\u5360\u5185\u5b58\u3002<\/em><\/p>\n<p>\u5982\u679c\u4f60\u613f\u610f\u7684\u8bdd\u4e5f\u53ef\u4ee5\u6d4b\u8bd5\u6027\u80fd\u54e6\uff0c\u6709\u95ee\u9898\u7684\u8bdd\u6b22\u8fce\u6307\u6559\u3002<\/p>\n<h2>\u5176\u5b83<\/h2>\n<p>\u4e4b\u524d\u7684\u5e16\u5b50\uff1a\u4e00\u4e2a nginx \u9632\u706b\u5899\u6a21\u5757: ngx_waf<\/p>\n<p>\u4e4b\u524d\u5728 V2EX \u5ba3\u4f20\u8fc7\u8fd9\u4e2a\u9879\u76ee\uff0c\u73b0\u5728\u518d\u53d1\u4e00\u6b21\u7684\u7406\u7531\u662f\u4f18\u5316\u4e86\u6027\u80fd\uff0c\u539f\u672c\u90fd\u662f\u66b4\u529b\u5faa\u73af\u7684\uff0c\u73b0\u5728\u90fd\u5df2\u7ecf\u4f18\u5316\u4e86\u3002<\/p>\n<p>\u518d\u53d1\u4e00\u6b21\u7684\u76ee\u7684\u81ea\u7136\u662f\u60f3\u591a\u6da8\u70b9 star\uff0c\u6240\u4ee5\u5982\u679c\u89c9\u5f97\u597d\u7528\u7684\u8bdd\u8bb0\u5f97\u70b9\u4e2a star ~<\/p>\n<\/p><\/div>\n<div> <b>\u5927\u4f6c\u6709\u8a71\u8aaa<\/b> (<span>3<\/span>)        <\/div>\n<div> <\/div>\n<\/p><\/div>\n<\/p><\/div>\n<ul>\n<li data-pid=\"5624960\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u8cc7\u6df1\u5927\u4f6c : no1xsyzy <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             \u8bdd\u8bf4\u6b63\u5219\u5f15\u64ce\u8fd9\u4e1c\u897f\u80fd\u591f\u88ab\u6070\u5f53\u5730\u4f18\u5316\u6765\u907f\u514d\u5b83\u9020\u6210\u635f\u4f24\u5417\uff1f<br \/>\u6700\u8fd1\u770b\u5230 https:\/\/blog.doyensec.com\/ \u8fd9\u4e2a\u601d\u8def\u975e\u5e38\u795e\u5947<br \/>\uff08\u4e5f\u4e0d\u59a8\u5728\u8be5\u9879\u76ee\u76f8\u5173\u6587\u6863\u4e2d\u63a8\u8350\u4e00\u4e0b\u5982\u4f55\u201c\u907f\u514d\u88ab ReDoS\u201d\uff09<br \/>\uff08\u8bdd\u8bf4 benchmark(,,,,,) \u8fd9\u79cd\u6076\u610f\u8d1f\u8f7d\u8be5\u6761\u89c4\u5219\u7684\u5339\u914d\u65f6\u95f4\u4f1a\u662f\u968f\u9017\u53f7\u6570\u91cf\u7684\u5e73\u65b9\u65f6\u95f4\u5427\uff09                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5624961\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : c137rick <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy #1 \u8fd9\u4e2a\u95ee\u9898\u4e4b\u524d\u6709\u8003\u8651\u8fc7\uff0c\u4e0d\u8fc7\u8c8c\u4f3c\u4e0d\u9700\u8981\u505a\u4f18\u5316\u3002\u56e0\u4e3a\u672c\u6a21\u5757\u4f7f\u7528 pcre \u5e93\uff0c\u800c pcre \u5df2\u7ecf\u63d0\u4f9b\u4e86\u4e24\u79cd\u65b9\u5f0f\u53ef\u4ee5\u5728\u4e00\u5b9a\u7a0b\u5ea6\u4e0a\u9650\u5236\u4e86\u56de\u6eaf\u7684\u6b21\u6570\u3002<\/p>\n<p>\u7b2c\u4e00\u79cd\u65b9\u5f0f\u5c31\u662f\u5728\u7f16\u8bd1\u65f6\u901a\u8fc7\u6307\u5b9a `&#8211;with-match-limit=n` \u53c2\u6570\u6765\u9650\u5236\u4e3b\u5faa\u73af\u8ba1\u6570\u5668\u7684\u4e0a\u9650\uff0c\u8d85\u51fa\u4e0a\u9650\u81ea\u52a8\u7ed3\u675f\u3002<\/p>\n<p>\u7b2c\u4e8c\u79cd\u65b9\u5f0f\u5c31\u662f\u5728\u8fd0\u884c\u65f6\u4fee\u6539\u8ba1\u6570\u5668\u7684\u4e0a\u9650\uff0c\u6709\u76f8\u5e94\u7684\u51fd\u6570\u3002<\/p>\n<p>\u518d\u52a0\u4e0a\u5f00\u53d1\u7248\u4e2d\u5df2\u7ecf\u5f00\u59cb\u7f13\u5b58\u6b63\u5219\u7684\u5339\u914d\u7ed3\u679c\uff0c\u6545\u672c\u6a21\u5757\u6709\u4e00\u5b9a\u7684\u6297 ReDos \u80fd\u529b\u3002<\/p>\n<p>\u6211\u5728\u9879\u76ee\u6587\u6863\u91cc\u63d0\u4e00\u4e0b\u8fd9\u4e2a\u95ee\u9898\u5427\uff0c\u4e0d\u8fc7\u4f3c\u4e4e\u5e76\u4e0d\u90a3\u4e48\u4e25\u91cd\u3002<\/p>\n<p>\u5982\u679c\u6211\u8bf4\u7684\u6709\u4ec0\u4e48\u95ee\u9898\u6b22\u8fce\u6307\u6559\u3002                                                            <\/p><\/div>\n<\/p><\/div>\n<\/li>\n<li data-pid=\"5624962\" data-uid=\"2\">\n<div>\n<div>\n<div> <span>\u4e3b<\/span> <span>\u8cc7\u6df1\u5927\u4f6c : c137rick <\/span>  <\/div>\n<div> <i title=\"\u5f15\u7528\"><\/i>  <span>          <\/span> <\/div>\n<\/p><\/div>\n<div>                                                             @no1xsyzy #1 \u5982\u679c\u4e0d\u8c08\u672c\u6a21\u5757\uff0c\u60f3\u8981\u901a\u8fc7\u4f18\u5316\u6b63\u5219\u5f15\u64ce\u6765\u907f\u514d ReDoS \u7684\u8bdd\u6211\u6682\u65f6\u6211\u6ca1\u60f3\u5230\u4ec0\u4e48\u597d\u7684\u529e\u6cd5\u3002\u6211\u60f3\u8981\u4e0d\u7136\u9650\u5236\u56de\u6eaf\u6b21\u6570\uff0c\u8981\u4e0d\u7136\u7528\u4e0d\u4f1a\u56de\u6eaf\u7684\u6b63\u5219\u5f15\u64ce\u3002                                                            <\/div>\n<\/p><\/div>\n<\/li>\n<li>\n","protected":false},"excerpt":{"rendered":"<p>ngx_waf&#8211;\u5b8c\u6574\u3001&hellip;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":[],"categories":[],"tags":[],"_links":{"self":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/423415"}],"collection":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=423415"}],"version-history":[{"count":0,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/423415\/revisions"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=423415"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=423415"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=423415"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}