共计 6938 个字符,预计需要花费 18 分钟才能阅读完成。
Naxsi 简介:
Naxsi 是一个开放源代码、高效、低维护规则的 Nginx web 应用防火墙模块。Naxsi 的主要目标是帮助人们加固他们的 web 应用程序,以抵御 SQL 注入、跨站脚本、跨域伪造请求、本地和远程文件包含漏洞。
安装配置 naxsi 模块步骤如下:
一. 首先要搭建 lnmp 环境并添加 lua 模块:
添加 lua 模块步骤如下:
1. 下载并安装 lua 模块:
wget http://luajit.org/download/LuaJIT-2.0.1.tar.gz
tar zxvfLuaJIT-2.0.1.tar.gz
cd LuaJIT-2.0.1
make && make install
2. 下载 ngx_devel_kit 和 nginx_lua_module 并解压
tar zxvfngx_devel_kit-0.2.19.tar.gz
tar zxvflua-nginx-module-0.9.2.tar.gz
3. 进入 nginx 源码文件夹,编译安装 nginx
a. 导入环境变量
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
b. 查看 nginx 的先前的 configure 配置
/usr/local/webserver/nginx/sbin/nginx -V
nginxversion: nginx/1.2.9
configurearguments: –user=www –group=www –prefix=/usr/local/webserver/nginx –with- http_stub_status_module –with-http_ssl_module
c. 重新编译安装 nginx:
cd /tools/nginx-1.2.9
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/tools/ngx_devel_kit-0.2.19 –add-module=/tools/lua-nginx-module-0.9.2
make -j2
make install
此时检查 nginx 配置文件语法会出现错误:
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx:error while loading shared libraries:
libluajit-5.1.so.2: cannot open sharedobject file: No such file or directory
原因是找不到 libluajit-5.1.so.2
解决方法:
find / -name “libluajit-5.1.so.2”
/usr/local/lib/libluajit-5.1.so.2
echo “/usr/local/lib” >>/etc/ld.so.conf
ldconfig
/usr/local/webserver/nginx/sbin/nginx -t
nginx:the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/webserver/nginx/conf/nginx.conf test issuccessful
配置 OK。
二. 下载 naxsi 模块:
wget http://naxsi.googlecode.com/files/naxsi-core-0.50.tgz
tar zxvf naxsi-core-0.50.tgz
三. 关联 naxsi 模块:
先查看 nginx 的原有./configure 配置,然后复制后并添加 naxsi 模块的路径:
cd /tools/nginx-1.2.9
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/tools/ngx_devel_kit-0.2.19 –add-module=/tools/lua-nginx-module-0.9.2 –add-module=/tools/naxsi-core-0.50/naxsi_src/
make && make install
Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里
推荐阅读 :
Nginx 实现反向代理和负载均衡的配置及优化 http://www.linuxidc.com/Linux/2013-11/92909.htm
Nginx 做负载均衡报:nginx: [emerg] could not build the types_hash http://www.linuxidc.com/Linux/2013-10/92063.htm
Nginx 负载均衡模块 ngx_http_upstream_module 详述 http://www.linuxidc.com/Linux/2013-10/91907.htm
Nginx+Firebug 让浏览器告诉你负载均衡将请求分到了哪台服务器 http://www.linuxidc.com/Linux/2013-10/91824.htm
Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm
Nginx + Naxsi 搭建 Web 应用防火墙(Ubuntu 系统)http://www.linuxidc.com/Linux/2012-08/67511.htm
四. 配置 naxsi 模块:
官网说明见:
http://code.google.com/p/naxsi/wiki/Howto#Installing_nginx_+_naxsi
1. 将 naxsi_config 目录下核心配置 naxsi_core.rules 拷贝到 nginx/conf/ 目录下:
cp /tools/naxsi-core-0.50/naxsi_config/naxsi_core.rules /usr/local/webserver/nginx/conf/
2. 在 nginx/conf/ 目录下新建 naxsi_nbs.rules 文件,用以配置使用;
touch naxsi_nbs.rules
3. 配置 nginx.conf 文件:
user www;
worker_processes 1;
events {
worker_connections 1024;
}
http {
include mime.types;
include/usr/local/webserver/nginx/conf/naxsi_core.rules;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
location /xss {
include naxsi_nbs.rules;
include naxsi_BasicRule.conf;
default_type ‘test/plain’;
content_by_lua ‘
ngx.say(“({\’Test xss ,come inplease!!!\’})”);
‘;
root html;
}
location /RequestDenied {
return 403;
}
error_page 403 /403.html;
}
}
4. 配置规则文件 naxsi_nbs.rules
#LearningMode; #Enables learningmode
SecRulesEnabled;
#SecRulesDisabled;
DeniedUrl “/RequestDenied”;
## check rules
CheckRule “$SQL >= 8″BLOCK;
CheckRule “$RFI >= 8″BLOCK;
CheckRule “$TRAVERSAL >=4”
BLOCK; CheckRule “$EVADE >=4” BLOCK;
CheckRule “$XSS >= 8″BLOCK;
5. 配置白名单文件 naxsi_BasicRule.conf
12 BasicRule wl:0″mz:$ARGS_VAR:script”;
BasicRule wl:0″mz:$ARGS_VAR:id”;
这表示 xss 攻击正常是被拦截的,若被添加白名单,则不被拦截:此处是 Get 参数名若为 id 或者 script,则不被拦截;
BasicRule 的规则说明,具体参见:http://code.google.com/p/naxsi/wiki/BasicRule
五. 测试 naxsi 模块
1. 检查语法并重启 nginx 服务:
12 /usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx -s reload
2. 测试连接:
http://192.168.1.11/xss/xss/
http://192.168.1.11/xss/xss/?id=40/**/and/**/1=1
http://192.168.1.11/xss/xss/?name=40/**/and/**/1=1
http://192.168.1.11/xss/xss/?name=%28%29
http://192.168.1.11/xss/xss/?term=%3Cscript%3Ewindow.open%28%22
http://192.168.1.11/xss/xss/?title=meta%20http-equiv=%22refresh%22%20content=%220;%22
测试结果:
1 通过
2 通过,因为配置到白名单
3 不通过,含有条件注入
4 不通过,特殊字符
5 不通过,参数内容含脚本注入
6 不通过
Naxsi 简介:
Naxsi 是一个开放源代码、高效、低维护规则的 Nginx web 应用防火墙模块。Naxsi 的主要目标是帮助人们加固他们的 web 应用程序,以抵御 SQL 注入、跨站脚本、跨域伪造请求、本地和远程文件包含漏洞。
安装配置 naxsi 模块步骤如下:
一. 首先要搭建 lnmp 环境并添加 lua 模块:
添加 lua 模块步骤如下:
1. 下载并安装 lua 模块:
wget http://luajit.org/download/LuaJIT-2.0.1.tar.gz
tar zxvfLuaJIT-2.0.1.tar.gz
cd LuaJIT-2.0.1
make && make install
2. 下载 ngx_devel_kit 和 nginx_lua_module 并解压
tar zxvfngx_devel_kit-0.2.19.tar.gz
tar zxvflua-nginx-module-0.9.2.tar.gz
3. 进入 nginx 源码文件夹,编译安装 nginx
a. 导入环境变量
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
b. 查看 nginx 的先前的 configure 配置
/usr/local/webserver/nginx/sbin/nginx -V
nginxversion: nginx/1.2.9
configurearguments: –user=www –group=www –prefix=/usr/local/webserver/nginx –with- http_stub_status_module –with-http_ssl_module
c. 重新编译安装 nginx:
cd /tools/nginx-1.2.9
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/tools/ngx_devel_kit-0.2.19 –add-module=/tools/lua-nginx-module-0.9.2
make -j2
make install
此时检查 nginx 配置文件语法会出现错误:
/usr/local/webserver/nginx/sbin/nginx -t
/usr/local/webserver/nginx/sbin/nginx:error while loading shared libraries:
libluajit-5.1.so.2: cannot open sharedobject file: No such file or directory
原因是找不到 libluajit-5.1.so.2
解决方法:
find / -name “libluajit-5.1.so.2”
/usr/local/lib/libluajit-5.1.so.2
echo “/usr/local/lib” >>/etc/ld.so.conf
ldconfig
/usr/local/webserver/nginx/sbin/nginx -t
nginx:the configuration file /usr/local/webserver/nginx/conf/nginx.conf syntax is ok
nginx:configuration file /usr/local/webserver/nginx/conf/nginx.conf test issuccessful
配置 OK。
二. 下载 naxsi 模块:
wget http://naxsi.googlecode.com/files/naxsi-core-0.50.tgz
tar zxvf naxsi-core-0.50.tgz
三. 关联 naxsi 模块:
先查看 nginx 的原有./configure 配置,然后复制后并添加 naxsi 模块的路径:
cd /tools/nginx-1.2.9
./configure –user=www –group=www –prefix=/usr/local/webserver/nginx –with-http_stub_status_module –with-http_ssl_module –add-module=/tools/ngx_devel_kit-0.2.19 –add-module=/tools/lua-nginx-module-0.9.2 –add-module=/tools/naxsi-core-0.50/naxsi_src/
make && make install
Nginx 的详细介绍 :请点这里
Nginx 的下载地址 :请点这里
推荐阅读 :
Nginx 实现反向代理和负载均衡的配置及优化 http://www.linuxidc.com/Linux/2013-11/92909.htm
Nginx 做负载均衡报:nginx: [emerg] could not build the types_hash http://www.linuxidc.com/Linux/2013-10/92063.htm
Nginx 负载均衡模块 ngx_http_upstream_module 详述 http://www.linuxidc.com/Linux/2013-10/91907.htm
Nginx+Firebug 让浏览器告诉你负载均衡将请求分到了哪台服务器 http://www.linuxidc.com/Linux/2013-10/91824.htm
Ubuntu 安装 Nginx php5-fpm MySQL(LNMP 环境搭建) http://www.linuxidc.com/Linux/2012-10/72458.htm
Nginx + Naxsi 搭建 Web 应用防火墙(Ubuntu 系统)http://www.linuxidc.com/Linux/2012-08/67511.htm