日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

nginx配合modsecurity实现WAF功能

發(fā)布時間:2025/6/15 编程问答 22 豆豆
生活随笔 收集整理的這篇文章主要介紹了 nginx配合modsecurity实现WAF功能 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

2019獨角獸企業(yè)重金招聘Python工程師標(biāo)準(zhǔn)>>>

一.準(zhǔn)備工作

系統(tǒng):centos 6.5 64位、 ngx_openresty-1.7.10.1, modsecurity 2.9.0

  • openresty:??????http://openresty.org/download/ngx_openresty-1.7.10.1.tar.gz??

  • modsecurity for Nginx:? ??https://www.modsecurity.org/tarball/2.9.0/modsecurity-2.9.0.tar.gz

  • OWASP規(guī)則集:?https://github.com/SpiderLabs/owasp-modsecurity-crs

  • 依賴關(guān)系:

    ????modsecurty依賴的包:pcre httpd-devel libxml2 apr

    ???? yum?install?httpd-devel?apr?apr-util-devel?apr-devel??pcre?pcre-devel??libxml2?libxml2-devel

    ????openresty依賴的包:pcre 、zlib、 openssl

    yum?install?zlib?zlib-devel?openssl?openssl-devel??pcre?pcre-devel

    二.啟用standalone模塊并編譯

    下載modsecurity for nginx 解壓,進(jìn)入解壓后目錄執(zhí)行:

    ./autogen.sh ./configure?--enable-standalone-module?--disable-mlogc make

    三.openresty添加modsecurity模塊

    在編譯standalone后,openresty編譯時可以通過"--add-module"添加modsecurity模塊:

    ./configure?--prefix=/opt/openresty??--with-pcre-jit??--with-ipv6?--without-http_redis2_module?--with-http_iconv_module???-j2?--add-module=../modsecurity-2.9.0/nginx/modsecurity/ make?&&?make?install

    四.添加規(guī)則

    modsecurity傾向于過濾和阻止web危險,之所以強大就在于規(guī)則,OWASP提供的規(guī)則是于社區(qū)志愿者維護的,被稱為核心規(guī)則CRS(corerules),規(guī)則可靠強大,當(dāng)然也可以自定義規(guī)則來滿足各種需求。

    1.下載OWASP規(guī)則:

    git?clone?https://github.com/SpiderLabs/owasp-modsecurity-crsmv??owasp-modsecurity-crs?/opt/openresty/nginx/conf/cd?/opt/openresty/nginx/conf/owasp-modsecurity-crs/?&&?mv?modsecurity_crs_10_setup.conf.example?modsecurity_crs_10_setup.conf


    2.啟用OWASP規(guī)則:

    復(fù)制modsecurity源碼目錄下的modsecurity.conf-recommended和unicode.mapping到nginx的conf目錄下,并將modsecurity.conf-recommended重新命名為modsecurity.conf。

    mv?modsecurity.conf-recommended?/opt/openresty/nginx/conf/modsecurity.conf cp?unicode.mapping?/opt/openresty/nginx/conf/

    編輯modsecurity.conf 文件,將SecRuleEngine設(shè)置為 on

    sed?-i?'s/^SecRuleEngine.*/SecRuleEngine?On/'?/opt/openresty/nginx/conf/modsecurity.conf

    owasp-modsecurity-crs下有很多存放規(guī)則的文件夾,例如base_rules、experimental_rules、optional_rules、slr_rules,里面的規(guī)則按需要啟用。

    需要啟用的規(guī)則使用Include到modsecurity.conf即可。

    Include?owasp-modsecurity-crs/modsecurity_crs_10_setup.conf? Include?owasp-modsecurity-crs/base_rules/modsecurity_crs_41_sql_injection_attacks.conf? Include?owasp-modsecurity-crs/base_rules/modsecurity_crs_41_xss_attacks.conf? Include?owasp-modsecurity-crs/base_rules/modsecurity_crs_40_generic_attacks.conf? Include?owasp-modsecurity-crs/experimental_rules/modsecurity_crs_11_dos_protection.conf? Include?owasp-modsecurity-crs/experimental_rules/modsecurity_crs_11_brute_force.conf? Include?owasp-modsecurity-crs/optional_rules/modsecurity_crs_16_session_hijacking.conf


    五.配置nginx

    在需要啟用modsecurity的主機的location下面加入下面兩行即可:

    ModSecurityEnabled?on;?? ModSecurityConfig?modsecurity.conf;


    下面是幾個示例配置,php虛擬主機:

    server?{listen??????80;server_name?test.net?www.test.net; location?~?\.php$?{ModSecurityEnabled?on;??ModSecurityConfig?modsecurity.conf;root?/web/wordpress;index?index.php?index.html?index.htm;fastcgi_pass???127.0.0.1:9000;fastcgi_index??index.php;fastcgi_param??SCRIPT_FILENAME??$Document_root$fastcgi_script_name;include????????fastcgi_params;}}


    upstream負(fù)載均衡:

    upstream?online?{server?192.168.1.100:8080;server?192.168.1.101:8080?backup; }server?{ listen?80; server_name?test.net?www.test.net;location?/?{ModSecurityEnabled?on;??ModSecurityConfig?modsecurity.conf;??proxy_pass?http://online;proxy_redirect?????????off;proxy_set_header?Host?$host;proxy_set_header?X-Real-IP?$remote_addr;proxy_set_header??X-Forwarded-For?$proxy_add_x_forwarded_for;} }

    泛域名解析,反向代理方式:

    upstream?real_webserver?{server?192.168.0.12;server?192.168.0.13; } server?{listen???????80;server_name??_?;location?{ModSecurityEnabled?on;ModSecurityConfig?modsecurity.conf;proxy_set_header???Host????$host;proxy_set_header???X-Real-IP???$remote_addr;proxy_set_header???X-Forwarded-For?$proxy_add_x_forwarded_for;proxy_pass?http://real_webserver;}}

    六.測試

    我們啟用了xss和sql注入的過濾,不正常的請求會直接返回403。以php環(huán)境為例,新建一個phpinfo.php內(nèi)容為:

    <?php????phpinfo();??????>


    在瀏覽器中訪問:

    http://www.52os.net/phpinfo.php?id=1?正常顯示。? http://www.52os.net/phpinfo.php?id=1?and?1=1??返回403。? http://www.52os.net/phpinfo.php?search=<scritp>alert('xss');</script>??返回403。


    說明sql注入和xss已經(jīng)被過濾了



    轉(zhuǎn)載于:https://my.oschina.net/monkeyzhu/blog/393505

    總結(jié)

    以上是生活随笔為你收集整理的nginx配合modsecurity实现WAF功能的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。

    主站蜘蛛池模板: 欧洲熟妇精品视频 | 午夜男人网 | 蜜桃av导航 | 中文在线a√在线 | 青青草娱乐视频 | bangbros性欧美18 | 屁股夹体温计调教play | 五号特工组之偷天换月 | 波多野结衣视频在线观看 | 日本xxxxwww | 国产小视频在线免费观看 | 久久影院午夜理论片无码 | 九九视频在线播放 | 四季av国产一区二区三区 | 国产男女猛烈无遮挡免费观看网站 | 综合亚洲网 | 国产主播第一页 | 黄色国产一区 | 成人夜夜| 天天狠天天透 | 精品成人av一区二区在线播放 | 一本色道久久综合亚洲 | 日韩精品导航 | 免费在线看黄视频 | 午夜av网址 | 九一亚色| 少妇野外性xx老女人野外性xx | 国产噜噜噜 | 羞羞涩涩网站 | 国产精品一级无码 | 一区二区免费视频 | 国产专区在线播放 | 怡红院精品视频 | 91欧美激情一区二区三区成人 | 亚洲a视频在线观看 | 欧美一区二区免费电影 | 亚洲精品视频一区 | 国产又黄又粗又猛又爽的视频 | www亚洲国产 | 在线观看亚洲专区 | 又黄又色的网站 | 在线免费观看亚洲 | 一级中文片 | 中文字幕乱码在线 | 在线播放免费av | 欧美激情片一区二区 | 精品人妻一区二区三区香蕉 | 久久色中文字幕 | 男人天堂av电影 | 夜夜草网 | 午夜操操| 超碰caoporen| 3d毛片| 国产一区日本 | 亚欧美精品 | 亚洲一区 在线播放 | 欧美永久精品 | 99ri视频 | 中文字幕激情小说 | 狠狠搞av | 综合精品在线 | 这里只有精品免费视频 | 视频一区二区视频 | 97国产在线播放 | 国产a网 | 久久噜噜 | 主播福利在线 | 欧美日韩国产在线一区 | 无码h黄肉3d动漫在线观看 | 久久久久久中文字幕 | 久久久青青 | 亚洲一区二区欧美 | 高级毛片 | 三及毛片 | 国产精品久久影视 | 欧美午夜在线视频 | 青青草视频 | 免费观看黄一级视频 | 中文字幕3 | 天天射综合网站 | 久久亚洲熟女cc98cm | 亚洲一区二区黄片 | 午夜影院免费视频 | 色网站入口| 99热这里只有精品4 精品国产黄色 | 久久精品国产亚洲AV无码麻豆 | 操欧美女 | 国产做受高潮动漫 | 成人午夜精品一区二区三区 | 欧洲美女与动交zozzo | 久热青草| 韩国三级bd高清中字2021 | 后进极品美女圆润翘臀 | 日本性高潮视频 | 日b免费视频 | 禁漫天堂免费网站 | 公车乳尖揉捏酥软呻吟 | 中文字幕国产在线 | 四虎影像 |