1、WAF 関連概念:
(1)WAF はじめに:
WAF:ウェブAppalicationファイアウォール、ウェブアプリケーションファイアウォールは、のために、アプリケーション層の一連の作品であるHTTP / HTTPS のセキュリティポリシーとして、Webが安全な保護アプリケーションを提供しています。
(2)WAFは、以下の機能を達成することができます。
A、予防のSQL 、あふれ、地元あって、注入をファジングの上でテスト、XSS などのウェブ攻撃。
B、予防するためにSVN / バックアップファイルなどの漏れを。
C、防止Apacheのベンチのようなプレス計測ツールを攻撃。
D、共通シールドハッカースキャンツールを。
E、シールド異常なネットワーク要求。
Fは、画像添付クラスディレクトリシールドPHPが実行権限を。
グラムは、予防ウェブシェルのアップロードを。
2、インストール依存パッケージ:
#yumを-yインストールのgccはgcc-C ++のzlibはzlib-develのopensslのopensslの-develのPCRE PCRE-develのperlの-develのperlの-のExtUtils-埋め込み作るGD-develのlibxml2ののlibxml2-develのlibxsltはlibxsltは-develののGeoIPのGeoIP-develのGeoIPのデータのgitのhttpd -tools
3、インストールLuaJIT 2.1 :
LuaJITは使用することですのC によって調製言語をLuaの、コードインタプリタhttp://luajit.org/download.html 安定版のLuaJIT-2.0.5 このデモを使用し、お勧めしません、バージョンが低すぎる、あるLuaJIT-2.1ベータ3-0.0 。
#gitのクローンhttps://github.com/openresty/luajit2.git
#カドミウムluajit2
#メイク&& makeがPREFIX =は/ usr / local /のluajit2をインストール
#Lnを-swは/ usr / lokl / luajit2 / libに/ libluajit-5klksok2 / lib64に/ libluajit-5klksok2
4、テストのLua 環境:
#vimの/tmp/hello.lua - >印刷( "こんにちはLuaの")
#連絡先/tmp/hello.lua
#連絡先
5、ダウンロードコーデックngx_devel_kit モジュール:
NDK :nginxの開発キットは、拡大されnginxのモジュールサーバーのコア機能、https://github.com/vision5/ngx_devel_kit 。
#タール-xf ngx_devel_kit-0.3.1.tar.gz
図6に示すように、キャリア抽出LUA-nginxのモジュールのモジュール。
Module1の-nginxの-のLua :Luaの強力な機能組み込みnginxののサーバー、https://github.com/openresty/lua-nginx-module 。
#タール-xfのlua-nginxのモジュール-0.10.15.tar.gz
互換性のnginxののバージョン(最新の安定と互換性がありません1.16.1 バージョン):
7、コンパイルnginxのの安定したバージョン1.14.2を:
#useraddの-s / sbinに/ nologinに-M nginxの
#タール-xfのnginx-1.14.2.tar.gz -Cは/ usr / src
#CDの/usr/src/nginx-1.14.2/
輸出LUAJIT_LIB =は/ usr / local / luajit2 / libに
輸出LUAJIT_INC =は/ usr / local / luajit2 /含める/ luajit-2.1
#は./configure --prefix =は/ usr / local / nginxの--user = nginxの--group = nginxの--with-スレッド--with-FILE-AIO --with-http_ssl_module --with-http_v2_module --with- http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_geoip_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_mp4_module --with-http_gunzip_module --with- http_gzip_static_module --with-http_auth_request_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_slice_module --with-http_stub_status_module --with-http_perl_module --with-メール--with-mail_ssl_module --with- --with-stream_ssl_module --with-stream_realip_module --with-stream_geoip_module --with-stream_ssl_preread_module --with-compatの--with-PCRE流れ--add-モジュール= /ソフトウェア/ ngx_devel_kit-0.3.1 --add-モジュール= /ソフトウェア/ LUA-nginxのモジュール-0.10.15 --with-LD-OPT = " - W1を、-rpath、は/ usr /ローカル/ luajit2 / libに」
#メイク-j2 && make installを
備考:
(1)は、Module1標準--add 持つディレクトリにモジュールをコンフィグファイルを
(2)そこのMakefileのファイルを実行する必要がメイクをしてインストールします
8、のconfigure nginxのは、環境変数、および起動nginxの:
#vimの/etc/profile.d/nginx.sh
輸出PATH =は/ usr / local / nginxの/ sbinに:$ PATHに
#。/etc/profile.d/nginx.sh
#nginxの-v
#nginxの
#のSS -tunlp | grepの-w:80
9、テストnginxのLuaのモジュール。
#CDは/ usr / local / nginxの/ confに
#CPのnginx.conf {。} BAK
#vimのnginx.conf
でHTTP 新しい構成コードセグメント:lua_load_resty_core OFF。
在server配置段中新增如下location:
location /lua {
default_type 'text/plain';
content_by_lua 'ngx.say("Hello Lua")';
}
# nginx -t
# nginx -s reload
备注:在http配置段中新增lua_load_resty_core off;代码,启动Nginx时就不会提示上述错误信息。
10、创建保存日志的目录:
# mkdir -pv /usr/local/nginx/logs/hack
11、下载解压ngx_lua_waf模块:
ngx_lua_waf:基于lua-nginx-module的Web应用防火墙,https://github.com/loveshell/ngx_lua_waf。
# tar -xf ngx_lua_waf-0.7.2.tar.gz -C /usr/local/nginx/conf
# cd /usr/local/nginx/conf
# mv ngx_lua_waf-0.7.2 waf
# chown -R nginx.nginx /usr/local/nginx
备注:waf目录主要结构
(1)config.lua:配置文件;
(2)init.lua:规则函数;
(3)waf.lua:定义WAF检测顺序;
(4)wafconf:保存过滤规则的目录,每条规则需换行或用|分割;
(5)wafconf/args:按照GET参数过滤(默认已开启);
(6)wafconf/cookie:按照Cookie过滤;
(7)wafconf/post:按照POST请求过滤(默认已开启);
(8)wafconf/url:按照GET请求URL过滤;
(9)wafconf/user-agent:按照User Agent过滤;
(10)wafconf/whiteurl:按照白名单中的URL做匹配,匹配到则不做过滤。
12、确认config.lua配置文件中waf规则目录的路径是否正确:
# vim /usr/local/nginx/conf/waf/config.lua --> RulePath="/usr/local/nginx/conf/waf/wafconf/"
备注:config.lua配置文件
指令 |
含义 |
RulePath="/usr/local/nginx/conf/waf/wafconf/" |
规则存放目录 |
attacklog="on" |
开启日志 |
logdir="/usr/local/nginx/logs/hack/" |
Log日志目录 |
UrlDeny="on" |
拦截URL访问 |
Redirect="on" |
拦截后重定向 |
CookieMatch="on" |
拦截Cookie Attack |
postMatch="on" |
拦截Post Attack |
whiteModule="on" |
开启URL白名单 |
black_fileExt={"php","jsp"} |
不允许上传的文件后缀类型 |
ipWhitelist={"127.0.0.1"} |
IP白名单,多个IP之间使用逗号分隔 |
ipBlocklist={"1.0.0.1"} |
IP黑名单,多个IP之间使用逗号分隔 |
CCDeny="on" |
开启拦截CC Attack(需要在nginx.conf的http配置段中新增代码lua_shared_dict limit 10m;) |
CCrate="100/60" |
设置CC Attack频率,单位为秒 默认1分钟同一个IP只能请求同一个地址100次 |
13、修改nginx.conf配置文件:
# vim /usr/local/nginx/conf/nginx.conf,在http配置段中新增如下代码:
lua_package_path "/usr/local/nginx/conf/waf/?.lua";
lua_shared_dict limit 10m;
init_by_lua_file "/usr/local/nginx/conf/waf/init.lua";
access_by_lua_file "/usr/local/nginx/conf/waf/waf.lua";
# nginx -t
# nginx -s reload
14、测试WAF应用防火墙:
(1)模拟URL参数检测:http://192.168.0.120/lua?id=../etc/passwd
(2)使用ab命令模拟CC Attack:# ab -n 20000 -c 100 http://192.168.0.120/lua
备注:ab命令选项
-n requests:需要执行的请求总数,默认为1
-c concurrency:同时并发执行的请求数,默认为1
(3)查看日志:# tail /usr/local/nginx/logs/hack/localhost_2020-02-17_sec.log
192.168.0.120 [2020年2月17日午後12時四十七分17秒] "UAのローカルホスト/ LUA" " - " "ApacheBench / 2.3"「(HTTrack |収穫|監査| dirbuster |センザンコウ| nmapの| SQLN | -scan |ヒドラ|パーサ|のlibwww | BBBike | SQLMAP | w3af | OWASP | Niktoの| fimap | havij | PycURL |ズメウ| BabyKrokodil | netsparker | httperf |ベンチ| SF /)」