Top Related Projects
ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
High-performance WAF built on the OpenResty stack
Quick Overview
The unixhot/waf repository is a Web Application Firewall (WAF) implementation based on OpenResty and Nginx. It aims to provide protection against common web application attacks and can be used to secure various web applications and services.
Pros
- Easy to deploy and integrate with existing Nginx setups
- Offers protection against common web attacks like SQL injection, XSS, and more
- Customizable rules and configurations to suit specific security needs
- Built on top of OpenResty, which provides high performance and scalability
Cons
- Limited documentation, which may make it challenging for new users to set up and configure
- Requires knowledge of Nginx and Lua for advanced customization
- May introduce some performance overhead, especially with complex rule sets
- Not as feature-rich as some commercial WAF solutions
Getting Started
To get started with unixhot/waf:
-
Clone the repository:
git clone https://github.com/unixhot/waf.git
-
Install OpenResty and its dependencies:
sudo apt-get install openresty
-
Copy the WAF files to your OpenResty installation:
sudo cp -R waf/ /usr/local/openresty/
-
Configure your Nginx configuration file to include the WAF:
http { lua_package_path "/usr/local/openresty/waf/?.lua;;"; init_by_lua_file "/usr/local/openresty/waf/init.lua"; access_by_lua_file "/usr/local/openresty/waf/access.lua"; }
-
Restart OpenResty:
sudo systemctl restart openresty
Note: This is a basic setup. You may need to adjust paths and configurations based on your specific environment and requirements.
Competitor Comparisons
ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
Pros of ModSecurity
- More mature and widely adopted, with extensive documentation and community support
- Offers a comprehensive set of rules (OWASP Core Rule Set) for protecting against various web application attacks
- Highly configurable and can be integrated with multiple web servers (Apache, Nginx, IIS)
Cons of ModSecurity
- Can be complex to set up and configure, especially for beginners
- May introduce performance overhead, particularly with extensive rule sets
- Requires regular updates and maintenance to keep up with new threats
Code Comparison
ModSecurity:
SecRule REQUEST_HEADERS:User-Agent "nikto" \
"id:1000,phase:1,deny,log,msg:'Nikto Scan Detected'"
WAF:
location / {
waf_main on;
waf_rule_path /etc/nginx/waf/rules;
}
ModSecurity uses a more detailed and flexible rule syntax, allowing for complex conditions and actions. WAF, on the other hand, focuses on simplicity and ease of use within Nginx configurations.
ModSecurity is a comprehensive, battle-tested solution with a steeper learning curve, while WAF aims to provide a more straightforward approach to web application security, specifically tailored for Nginx environments.
NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
Pros of naxsi
- More mature and actively maintained project with a larger community
- Designed specifically for NGINX, offering tight integration
- Extensive rule set for common web application attacks
Cons of naxsi
- Steeper learning curve due to its complex configuration
- May require more fine-tuning to reduce false positives
- Limited documentation compared to some other WAF solutions
Code Comparison
naxsi configuration example:
location / {
SecRulesEnabled;
DeniedUrl "/RequestDenied";
CheckRule "$SQL >= 8" BLOCK;
CheckRule "$RFI >= 8" BLOCK;
CheckRule "$TRAVERSAL >= 4" BLOCK;
CheckRule "$EVADE >= 4" BLOCK;
root /var/www/html;
}
waf configuration example:
location / {
waf_mode ACTIVE;
waf_rule_path /etc/nginx/waf/rules;
waf_global_rule_path /etc/nginx/waf/global;
waf_req_body_parse on;
waf_req_body_size 8M;
waf_res_body_parse off;
}
Both projects aim to provide web application firewall functionality for NGINX, but naxsi offers a more comprehensive and established solution with its own rule language. waf, on the other hand, appears to have a simpler configuration syntax but may lack some of the advanced features and extensive rule sets found in naxsi.
High-performance WAF built on the OpenResty stack
Pros of lua-resty-waf
- Built specifically for OpenResty, leveraging its performance benefits
- More extensive rule set and customization options
- Active development and community support
Cons of lua-resty-waf
- Steeper learning curve due to more complex configuration
- Potentially higher resource usage for advanced features
Code Comparison
lua-resty-waf:
local waf = require "resty.waf"
local waf_instance = waf:new()
waf_instance:set_option("debug", true)
waf_instance:exec()
waf:
location / {
access_by_lua_file /path/to/waf/waf.lua;
content_by_lua_file /path/to/app.lua;
}
Summary
lua-resty-waf is a more feature-rich and actively maintained WAF solution specifically designed for OpenResty environments. It offers greater flexibility and customization options but may require more setup time and resources. waf, on the other hand, provides a simpler implementation that might be easier to integrate for basic use cases but lacks some of the advanced features and ongoing development of lua-resty-waf.
Both projects aim to enhance web application security, but lua-resty-waf is better suited for users looking for a comprehensive, OpenResty-optimized solution, while waf might be preferable for those seeking a straightforward, lightweight option.
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual CopilotREADME
WAF
- 使ç¨Nginx+Luaå®ç°èªå®ä¹WAFï¼Web application firewallï¼
- æè¿åç°ä½¿ç¨ç人è¶æ¥è¶å¤äºï¼è®¡åå¼å§ç»´æ¤åå¢å æ°åè½ 2020.7.29 èµµçé¿
项ç®èæ¯ä»ç»
éæ±äº§ç
ç±äºåçæçNginxçä¸äºå®å ¨é²æ¤åè½æéï¼å°±ç 究è½ä¸è½èªå·±ç¼åä¸ä¸ªWAFï¼åèKindle大ç¥çngx_lua_wafï¼èªå·±å°è¯åä¸ä¸ªäºï¼ä½¿ç¨ä¸¤å¤©æ¶é´ï¼è¾¹å¦Luaï¼è¾¹åãä¸è¿ä¸æ¯å®å ¨ä¸ä¸ï¼åªå®ç°äºä¸äºæ¯è¾ç®åçåè½ï¼
åè½å表ï¼
- æ¯æIPç½åååé»åååè½ï¼ç´æ¥å°é»ååçIP访é®æç»ã
- æ¯æURLç½ååï¼å°ä¸éè¦è¿æ»¤çURLè¿è¡å®ä¹ã
- æ¯æUser-Agentçè¿æ»¤ï¼å¹é èªå®ä¹è§åä¸çæ¡ç®ï¼ç¶åè¿è¡å¤çï¼è¿å403ï¼ã
- æ¯æCCæ»å»é²æ¤ï¼å个URLæå®æ¶é´ç访é®æ¬¡æ°ï¼è¶ è¿è®¾å®å¼ï¼ç´æ¥è¿å403ã
- æ¯æCookieè¿æ»¤ï¼å¹é èªå®ä¹è§åä¸çæ¡ç®ï¼ç¶åè¿è¡å¤çï¼è¿å403ï¼ã
- æ¯æURLè¿æ»¤ï¼å¹é èªå®ä¹è§åä¸çæ¡ç®ï¼å¦æç¨æ·è¯·æ±çURLå å«è¿äºï¼è¿å403ã
- æ¯æURLåæ°è¿æ»¤ï¼åçåä¸ã
- æ¯ææ¥å¿è®°å½ï¼å°æææç»çæä½ï¼è®°å½å°æ¥å¿ä¸å»ã
- æ¥å¿è®°å½ä¸ºJSONæ ¼å¼ï¼ä¾¿äºæ¥å¿åæï¼ä¾å¦ä½¿ç¨ELKè¿è¡æ»å»æ¥å¿æ¶éãåå¨ãæç´¢åå±ç¤ºã
WAFå®ç°
WAFä¸å¥è¯æè¿°ï¼å°±æ¯è§£æHTTP请æ±ï¼å议解æ模åï¼ï¼è§åæ£æµï¼è§å模åï¼ï¼åä¸åçé²å¾¡å¨ä½ï¼å¨ä½æ¨¡åï¼ï¼å¹¶å°é²å¾¡è¿ç¨ï¼æ¥å¿æ¨¡åï¼è®°å½ä¸æ¥ãæ以æ¬æä¸çWAFçå®ç°ç±äºä¸ªæ¨¡å(é 置模åãå议解æ模åãè§å模åãå¨ä½æ¨¡åãé误å¤ç模åï¼ç»æã
å®è£ é¨ç½²
以ä¸æ¹æ¡éæ©å ¶ä¸ä¹ä¸å³å¯ï¼
- éæ©1: å¯ä»¥éæ©ä½¿ç¨åççNginxï¼å¢å Lua模åå®ç°é¨ç½²ã
- éæ©2: ç´æ¥ä½¿ç¨OpenResty
OpenRestyå®è£
1 Yumå®è£ OpenRestyï¼æ¨èï¼
æºç å®è£ åYumå®è£ éæ©å ¶ä¸å³å¯ï¼é»è®¤åå®è£ å¨/usr/local/openrestyç®å½ä¸ã
[root@opsany ~]# wget https://openresty.org/package/centos/openresty.repo
[root@opsany ~]# sudo mv openresty.repo /etc/yum.repos.d/
[root@opsany ~]# sudo yum install -y openresty
- æµè¯OpenRestyåè¿è¡Lua
[root@opsany ~]# vim /usr/local/openresty/nginx/conf/nginx.conf
#å¨é»è®¤çserveré
ç½®ä¸å¢å
location /hello {
default_type text/html;
content_by_lua_block {
ngx.say("<p>hello, world</p>")
}
}
[root@opsany ~]# /usr/local/openresty/nginx/sbin/nginx -t
nginx: the configuration file /usr/local/openresty-1.17.8.2/nginx/conf/nginx.conf syntax is ok
nginx: configuration file /usr/local/openresty-1.17.8.2/nginx/conf/nginx.conf test is successful
[root@opsany ~]# /usr/local/openresty/nginx/sbin/nginx
- æµè¯è®¿é®
[root@opsany ~]# curl http://127.0.0.1/hello
<p>hello, world</p>
WAFé¨ç½²
[root@opsany ~]# git clone https://github.com/unixhot/waf.git
[root@opsany ~]# cp -r ./waf/waf /usr/local/openresty/nginx/conf/
[root@opsany ~]# vim /usr/local/openresty/nginx/conf/nginx.conf
#å¨http{}ä¸å¢å ï¼æ³¨æè·¯å¾ï¼åæ¶WAFæ¥å¿é»è®¤åæ¾å¨/tmp/æ¥æ_waf.log
#WAF
lua_shared_dict limit 50m;
lua_package_path "/usr/local/openresty/nginx/conf/waf/?.lua";
init_by_lua_file "/usr/local/openresty/nginx/conf/waf/init.lua";
access_by_lua_file "/usr/local/openresty/nginx/conf/waf/access.lua";
[root@opsany ~]# ln -s /usr/local/openresty/lualib/resty/ /usr/local/openresty/nginx/conf/waf/resty
[root@opsany ~]# /usr/local/openresty/nginx/sbin/nginx -t
[root@opsany ~]# /usr/local/openresty/nginx/sbin/nginx -s reload
éå½
Nginx + Luaæºç ç¼è¯é¨ç½²(ä¸æ¨è)
- Nginxå®è£ å¿ å¤çNginxåPCRE软件å ã
[root@nginx-lua ~]# cd /usr/local/src
[root@nginx-lua src]# wget http://nginx.org/download/nginx-1.12.1.tar.gz
[root@nginx-lua src]# wget https://nchc.dl.sourceforge.net/project/pcre/pcre/8.41/pcre-8.41.tar.gz
#å
¶æ¬¡ï¼ä¸è½½å½åææ°çluajitångx_devel_kit (NDK)ï¼ä»¥åæ¥å¥ï¼ç« ï¼ç¼åçlua-nginx-module
[root@nginx-lua src]# wget http://luajit.org/download/LuaJIT-2.0.5.tar.gz
[root@nginx-lua src]# wget https://github.com/simpl/ngx_devel_kit/archive/v0.3.0.tar.gz
[root@nginx-lua src]# wget wget https://github.com/chaoslawful/lua-nginx-module/archive/v0.10.10.zip
- æåï¼å建Nginxè¿è¡çæ®éç¨æ·
[root@nginx-lua src]# useradd -s /sbin/nologin -M www
- 解åNDKålua-nginx-module
[root@openstack-compute-node5 src]# tar zxvf v0.3.0.tar.gz
[root@openstack-compute-node5 src]# unzip -q v0.10.10.zip
- å®è£ LuaJIT Luajitæ¯Luaå³æ¶ç¼è¯å¨ã
[root@webs-ebt src]# tar zxvf LuaJIT-2.0.5.tar.gz
[root@webs-ebt src]# cd LuaJIT-2.0.5
[root@webs-ebt LuaJIT-2.0.5]# make && make install
- å®è£ Nginx并å 载模å
[root@webs-ebt src]# tar zxf nginx-1.12.1.tar.gz
[root@webs-ebt src]# tar zxvf pcre-8.41.tar.gz
[root@webs-ebt src]# cd nginx-1.12.1
[root@webs-ebt nginx-1.12.1]# export LUAJIT_LIB=/usr/local/lib
[root@webs-ebt nginx-1.12.1]# export LUAJIT_INC=/usr/local/include/luajit-2.0
[root@webs-ebt nginx-1.12.1]#./configure --user=www --group=www --prefix=/usr/local/nginx-1.12.1/ --with-pcre=/usr/local/src/pcre-8.41 --with-http_stub_status_module --with-http_sub_module --with-http_gzip_static_module --without-mail_pop3_module --without-mail_imap_module --without-mail_smtp_module --add-module=../ngx_devel_kit-0.3.0/ --add-module=../lua-nginx-module-0.10.10/
[root@webs-ebt nginx-1.12.1]# make -j2 && make install
[root@webs-ebt nginx-1.12.1]# ln -s /usr/local/nginx-1.12.1 /usr/local/nginx
[root@webs-ebt nginx-1.12.1]# ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
å¦æä¸å建符å·é¾æ¥ï¼å¯è½åºç°ä»¥ä¸å¼å¸¸ï¼
error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
- æµè¯å®è£
å®è£ å®æ¯åï¼ä¸é¢å¯ä»¥æµè¯å®è£ äºï¼ä¿®æ¹nginx.conf å¢å 第ä¸ä¸ªé ç½®ã
location /hello {
default_type 'text/plain';
content_by_lua 'ngx.say("hello,lua")';
}
[root@webs-ebt src]# /usr/local/nginx/sbin/nginx -t
[root@webs-ebt src]# /usr/local/nginx/sbin/nginx -t
ç¶å访é®http://xxx.xxx.xxx.xxx/hello å¦æåºç°hello,luaã表示å®è£ å®æ,ç¶åå°±å¯ä»¥ã
OpenRestyæºç ç¼è¯é¨ç½²ï¼ä¸æ¨èï¼
- å®è£ ä¾èµè½¯ä»¶å
[root@opsany ~]# yum install -y readline-devel pcre-devel openssl-devel
- å®è£ OpenResty
2.1 ä¸è½½å¹¶ç¼è¯å®è£ OpenResty
[root@opsany ~]# cd /usr/local/src
[root@opsany src]# wget https://openresty.org/download/openresty-1.17.8.2.tar.gz
[root@opsany src]# tar zxf openresty-1.17.8.2.tar.gz
[root@opsany src]# cd openresty-1.17.8.2
[root@opsany openresty-1.17.8.2]# ./configure --prefix=/usr/local/openresty-1.17.8.2 \
--with-luajit --with-http_stub_status_module \
--with-pcre --with-pcre-jit \
--with-file-aio --with-threads
[root@opsany openresty-1.17.8.2]# gmake && gmake install
[root@opsany openresty-1.17.8.2]# cd
[root@opsany ~]# ln -s /usr/local/openresty-1.17.8.2/ /usr/local/openresty
Top Related Projects
ModSecurity is an open source, cross platform web application firewall (WAF) engine for Apache, IIS and Nginx. It has a robust event-based programming language which provides protection from a range of attacks against web applications and allows for HTTP traffic monitoring, logging and real-time analysis.
NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
High-performance WAF built on the OpenResty stack
Convert designs to code with AI
Introducing Visual Copilot: A new AI model to turn Figma designs to high quality code using your components.
Try Visual Copilot