{"id":9318,"date":"2019-02-18T20:27:44","date_gmt":"2019-02-18T12:27:44","guid":{"rendered":"http:\/\/4563.org\/?p=9318"},"modified":"2019-02-18T20:27:44","modified_gmt":"2019-02-18T12:27:44","slug":"lnmp%e4%b8%80%e9%94%ae%e5%ae%89%e8%a3%85%e5%8c%85-ngx_lua_waf-wafweb%e5%ba%94%e7%94%a8%e9%98%b2%e7%81%ab%e5%a2%99-%e5%ae%89%e8%a3%85%e8%ae%be%e7%bd%ae%e6%95%99%e7%a8%8b","status":"publish","type":"post","link":"http:\/\/4563.org\/?p=9318","title":{"rendered":"LNMP\u4e00\u952e\u5b89\u88c5\u5305 ngx_lua_waf waf(web\u5e94\u7528\u9632\u706b\u5899) \u5b89\u88c5\u8bbe\u7f6e\u6559\u7a0b"},"content":{"rendered":"<h2><img decoding=\"async\" loading=\"lazy\" class=\"alignnone size-full wp-image-9319\" src=\"http:\/\/4563.org\/wp-content\/uploads\/2019\/02\/20190218_122708.png\" alt=\"\" width=\"367\" height=\"116\" \/><\/h2>\n<h2>WAF\u662f\u5565\uff1f<\/h2>\n<p>WAF\u4e2d\u6587\u540d\u662fWeb\u5e94\u7528\u9632\u706b\u5899\uff0cWAF\u80fd\u591f\u6839\u636e\u89c4\u5219\u62e6\u622aSQL\u6ce8\u5165\u3001\u6076\u610f\u8bf7\u6c42\u3001\u9ed1\u5ba2\u626b\u63cf\u7b49HTTP\u8bf7\u6c42\u4ece\u800c\u4fdd\u62a4WEB\u5e94\u7528\u7684\u5b89\u5168\u3002<\/p>\n<p>\u4eca\u5929\u6211\u4eec\u8981\u8bf4\u7684\u662f\u4e00\u4e2a\u6bd4\u8f83\u7b80\u5355\u597d\u7528\u7684\u57fa\u4e8elua\u7684waf\uff1angx_lua_waf\u3002<\/p>\n<p>ngx_lua_waf\u662f\u4e00\u4e2a\u57fa\u4e8elua-nginx-module(openresty)\u7684web\u5e94\u7528\u9632\u706b\u5899\uff0c<a href=\"https:\/\/github.com\/loveshell\/ngx_lua_waf\" target=\"_blank\" rel=\"noopener\">https:\/\/github.com\/loveshell\/ngx_lua_waf<\/a>\u3002<span id=\"more-6880\"><\/span><\/p>\n<p><strong>\u7528\u9014\uff1a<\/strong><\/p>\n<blockquote><p>\u9632\u6b62sql\u6ce8\u5165\uff0c\u672c\u5730\u5305\u542b\uff0c\u90e8\u5206\u6ea2\u51fa\uff0cfuzzing\u6d4b\u8bd5\uff0cxss\uff0cSSRF\u7b49web\u653b\u51fb<br \/>\n\u9632\u6b62svn\/\u5907\u4efd\u4e4b\u7c7b\u6587\u4ef6\u6cc4\u6f0f<br \/>\n\u9632\u6b62ApacheBench\u4e4b\u7c7b\u538b\u529b\u6d4b\u8bd5\u5de5\u5177\u7684\u653b\u51fb<br \/>\n\u5c4f\u853d\u5e38\u89c1\u7684\u626b\u63cf\u9ed1\u5ba2\u5de5\u5177\uff0c\u626b\u63cf\u5668<br \/>\n\u5c4f\u853d\u5f02\u5e38\u7684\u7f51\u7edc\u8bf7\u6c42<br \/>\n\u5c4f\u853d\u56fe\u7247\u9644\u4ef6\u7c7b\u76ee\u5f55php\u6267\u884c\u6743\u9650<br \/>\n\u9632\u6b62webshell\u4e0a\u4f20<\/p><\/blockquote>\n<h2>ngx_lua_waf\u5b89\u88c5<\/h2>\n<h3>lua\u652f\u6301\u5b89\u88c5<\/h3>\n<p>LNMP\u4e00\u952e\u5b89\u88c5\u5305\u4ece1.5\u5f00\u59cb\u589e\u52a0\u4e86lua\u652f\u6301\u7684\u9009\u9879\uff0c\u53ef\u4ee5\u901a\u8fc7\u4fee\u6539lnmp.conf\u4e2dEnable_Nginx_Lua\u540e\u7684\u53c2\u6570\u4e3a y \u6765\u542f\u7528lua\uff0c\u5982\u679c\u6ca1\u5b89\u88c5lnmp\uff0c\u4fee\u6539lnmp.conf\u540e\u4fdd\u5b58\uff0c\u5b89\u88c5\u5b8clnmp\u5c31\u662f\u652f\u6301lua\u7684\uff0c\u5982\u679c\u5df2\u7ecf\u5b89\u88c5\u597dlnmp\uff0c\u4e5f\u662f\u6309\u524d\u9762\u4fee\u6539lnmp.conf\uff0c\u7136\u540elnmp\u5b89\u88c5\u5305\u76ee\u5f55\u4e0b <strong>.\/upgrade.sh nginx<\/strong> \u5347\u7ea7nginx\uff0c\u8f93\u5165\u5f53\u524dnginx\u7248\u672c\u53f7\u6216\u66f4\u65b0\u7684nginx\u7248\u672c\u53f7\uff0c\u5347\u7ea7\u5b8c\u6210\u5c31\u662f\u652f\u6301lua\u7684\u4e86\u3002<\/p>\n<h3>\u5b89\u88c5ngx_lua_waf<\/h3>\n<p><strong>\u4e0b\u8f7d\u5b89\u88c5ngx_lua_waf\uff1a<\/strong><\/p>\n<blockquote><p><strong>wget https:\/\/github.com\/loveshell\/ngx_lua_waf\/archive\/master.zip -O ngx_lua_waf.zip<br \/>\nunzip\u00a0ngx_lua_waf.zip<br \/>\nmv ngx_lua_waf-master \/usr\/local\/nginx\/conf\/waf<\/strong><\/p><\/blockquote>\n<p><strong>nginx\u4e0a\u8bbe\u7f6e\u5e76\u542f\u7528ngx_lua_waf<\/strong><\/p>\n<p>\u7f16\u8f91 \/usr\/local\/nginx\/conf\/nginx.conf \u5728 server_tokens off; \u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<br \/>\nlua_package_path &#8220;\/usr\/local\/nginx\/conf\/waf\/?.lua&#8221;;<br \/>\nlua_shared_dict limit 10m;<br \/>\ninit_by_lua_file \/usr\/local\/nginx\/conf\/waf\/init.lua;<br \/>\n\u4fee\u6539\u5b8c\u6210\u4fdd\u5b58<\/p>\n<p>\u5982\u679c\u8981\u60f3\u5728\u67d0\u4e2a\u865a\u62df\u4e3b\u673a\u542f\u7528ngx_lua_waf\u53ef\u4ee5\u4fee\u6539\u5bf9\u5e94\u865a\u62df\u4e3b\u673a\u7684server\u6bb5\uff0c\u5728\u8be5server\u6bb5\u4e2d root \u7f51\u7ad9\u76ee\u5f55\u884c\u4e0b\u9762\u6dfb\u52a0\u5982\u4e0b\u4ee3\u7801\uff1a<br \/>\naccess_by_lua_file \/usr\/local\/nginx\/conf\/waf\/waf.lua;<br \/>\n\u4fee\u6539\u5b8c\u6210\u4fdd\u5b58<\/p>\n<p>\u6d4b\u8bd5nginx\u914d\u7f6e\u6587\u4ef6\uff1a<strong>\/usr\/local\/nginx\/sbin\/nginx -t<\/strong><br \/>\n\u91cd\u8f7dnginx\u914d\u7f6e\u751f\u6548\uff1a<strong>\/usr\/local\/nginx\/sbin\/nginx -s reload<\/strong><\/p>\n<p>\u5982\u679c\u6d4b\u8bd5\u548c\u91cd\u8f7d\u90fd\u6ca1\u62a5\u9519\u5c31\u5df2\u7ecf\u751f\u6548\u3002<\/p>\n<p>\u53ef\u4ee5\u901a\u8fc7\u8bbf\u95ee http:\/\/\u57df\u540d\/test.php?id=..\/etc\/passwd \u6765\u6d4b\u8bd5<\/p>\n<p>\u63d0\u793a\uff1a\u60a8\u7684\u8bf7\u6c42\u5e26\u6709&gt;\u4e0d\u5408\u6cd5\u53c2\u6570\uff0c\u5df2\u88ab\u7f51\u7ad9\u7ba1\u7406\u5458\u8bbe\u7f6e\u62e6\u622a\uff01\u8bf4\u660e\u5df2\u7ecf\u6b63\u786e\u8bbe\u7f6e<\/p>\n<p>ngx_lua_waf\u914d\u7f6e\u6587\u4ef6\u4f4d\u7f6e\uff1a\/usr\/local\/nginx\/conf\/waf\/config.lua<br \/>\nngx_lua_waf\u914d\u7f6e\u6587\u4ef6\u53c2\u6570\u8bf4\u660e\uff1a<\/p>\n<blockquote><p>RulePath = &#8220;\/usr\/local\/nginx\/conf\/waf\/wafconf\/&#8221;<br \/>\n&#8211;\u89c4\u5219\u5b58\u653e\u76ee\u5f55<br \/>\nattacklog = &#8220;off&#8221;<br \/>\n&#8211;\u662f\u5426\u5f00\u542f\u653b\u51fb\u4fe1\u606f\u8bb0\u5f55\uff0c\u9700\u8981\u914d\u7f6elogdir<br \/>\nlogdir = &#8220;\/usr\/local\/nginx\/logs\/hack\/&#8221;<br \/>\n&#8211;log\u5b58\u50a8\u76ee\u5f55\uff0c\u8be5\u76ee\u5f55\u9700\u8981\u7528\u6237\u81ea\u5df1\u65b0\u5efa\uff0c\u5207\u9700\u8981nginx\u7528\u6237\u7684\u53ef\u5199\u6743\u9650<br \/>\nUrlDeny=&#8221;on&#8221;<br \/>\n&#8211;\u662f\u5426\u62e6\u622aurl\u8bbf\u95ee<br \/>\nRedirect=&#8221;on&#8221;<br \/>\n&#8211;\u662f\u5426\u62e6\u622a\u540e\u91cd\u5b9a\u5411<br \/>\nCookieMatch = &#8220;on&#8221;<br \/>\n&#8211;\u662f\u5426\u62e6\u622acookie\u653b\u51fb<br \/>\npostMatch = &#8220;on&#8221;<br \/>\n&#8211;\u662f\u5426\u62e6\u622apost\u653b\u51fb<br \/>\nwhiteModule = &#8220;on&#8221;<br \/>\n&#8211;\u662f\u5426\u5f00\u542fURL\u767d\u540d\u5355<br \/>\nblack_fileExt={&#8220;php&#8221;,&#8221;jsp&#8221;}<br \/>\n&#8211;\u586b\u5199\u4e0d\u5141\u8bb8\u4e0a\u4f20\u6587\u4ef6\u540e\u7f00\u7c7b\u578b<br \/>\nipWhitelist={&#8220;127.0.0.1&#8221;}<br \/>\n&#8211;ip\u767d\u540d\u5355\uff0c\u591a\u4e2aip\u7528\u9017\u53f7\u5206\u9694<br \/>\nipBlocklist={&#8220;1.0.0.1&#8243;}<br \/>\n&#8211;ip\u9ed1\u540d\u5355\uff0c\u591a\u4e2aip\u7528\u9017\u53f7\u5206\u9694<br \/>\nCCDeny=&#8221;on&#8221;<br \/>\n&#8211;\u662f\u5426\u5f00\u542f\u62e6\u622acc\u653b\u51fb(\u9700\u8981nginx.conf\u7684http\u6bb5\u589e\u52a0lua_shared_dict limit 10m;)<br \/>\nCCrate = &#8220;100\/60&#8221;<br \/>\n&#8211;\u8bbe\u7f6ecc\u653b\u51fb\u9891\u7387\uff0c\u5355\u4f4d\u4e3a\u79d2.<br \/>\n&#8211;\u9ed8\u8ba41\u5206\u949f\u540c\u4e00\u4e2aIP\u53ea\u80fd\u8bf7\u6c42\u540c\u4e00\u4e2a\u5730\u5740100\u6b21<br \/>\nhtml=[[Please go away~~]] &#8211;\u8b66\u544a\u5185\u5bb9,\u53ef\u5728\u4e2d\u62ec\u53f7\u5185\u81ea\u5b9a\u4e49<br \/>\n\u5907\u6ce8:\u4e0d\u8981\u4e71\u52a8\u53cc\u5f15\u53f7\uff0c\u533a\u5206\u5927\u5c0f\u5199<\/p><\/blockquote>\n<p>ngx_lua_waf\u5b89\u88c5\u6559\u7a0b\u5230\u6b64\u7ed3\u675f<\/p>\n<p>\u4f86\u6e90:https:\/\/www.vpser.net\/build\/lnmp-nginx-lua-waf-install.html<\/p>\n","protected":false},"excerpt":{"rendered":"<p>WAF\u662f\u5565\uff1f WAF\u4e2d\u6587\u540d\u662fWeb&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\/9318"}],"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=9318"}],"version-history":[{"count":1,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/9318\/revisions"}],"predecessor-version":[{"id":9320,"href":"http:\/\/4563.org\/index.php?rest_route=\/wp\/v2\/posts\/9318\/revisions\/9320"}],"wp:attachment":[{"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=9318"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=9318"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/4563.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=9318"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}