安装nginx+ngx_lua支持WAF防护功能
nginx lua模块淘宝开发的nginx第三方模块,它能将lua语言嵌入到nginx配置中,从而使用lua就极大增强了nginx的能力.nginx以高并发而知名,lua脚本轻便,两者的搭配堪称完美.
用途:防止sql注入,本地包含,部分溢出,fuzzing测试,xss,SSRF等web攻击
防止svn/备份之类文件泄漏
防止ApacheBench之类压力测试工具的攻击
屏蔽常见的扫描黑客工具,扫描器
屏蔽异常的网络请求
屏蔽图片附件类目录php执行权限
防止webshell上传
系统:centos 6.4_x64
需要的软件:LuaJIT-2.0.3.tar.gz
tengine-2.1.0.tar.gz (nginx)
ngx_devel_kit-master.zip (ngx_devel_kit)
lua-nginx-module-master.zip (nginx_lua模块)
ngx_lua_waf-master.zip (waf策略 web应用防火墙)
yum -y install gcc gcc-c++ ncurses-devel libxml2-devel openssl-devel curl-devel libjpeg-devel libpng-devel autoconf pcre-devel libtool-libs freetype-devel gd zlib-devel zip unzip wget crontabs iptables file bison cmake patch mlocate flex diffutils automake make readline-devel glibc-devel glibc-static glib2-devel bzip2-devel gettext-devel libcap-devel logrotate ntp libmcrypt-devel GeoIP*
安装LuaJIT 2.0
tar zxf LuaJIT-2.0.0.tar.gz
cd LuaJIT-2.0.0
make && make install
注:lib和include是直接放在/usr/local/lib和usr/local/include
再来设置环境变量(这是给后面nginx编译的时候使用的):
vi /etc/profile
export LUAJIT_LIB=/usr/local/lib
export LUAJIT_INC=/usr/local/include/luajit-2.0
export LD_LIBRARY_PATH=/usr/local/lib/:$LD_LIBRARY_PATH
source /etc/profile
安装nginx
tar zxvf tengine-2.1.0.tar.gz
cd tengine-2.1.0
./configure --user=www --group=www --prefix=/usr/local/webserver/nginx --with-http_stub_status_module --with-pcre=/root/lnmp/pcre-8.20 --with-google_perftools_module --with-http_realip_module --with-poll_module --with-select_module --with-http_realip_module --with-http_addition_module --with-http_xslt_module --with-http_image_filter_module --with-http_sub_module --with-http_dav_module --with-http_flv_module --with-http_slice_module --with-http_mp4_module --with-http_gzip_static_module --with-http_concat_module --with-http_random_index_module --with-http_secure_link_module --with-http_degradation_module --with-http_sysguard_module --with-http_browser_module=shared --with-http_user_agent_module=shared --with-http_upstream_ip_hash_module=shared --with-http_upstream_least_conn_module=shared --with-http_upstream_session_sticky_module=shared --with-http_addition_module=shared --with-http_xslt_module=shared --with-http_image_filter_module=shared --with-http_sub_module=shared --with-http_flv_module=shared --with-http_slice_module=shared --with-http_mp4_module=shared --with-http_concat_module=shared --with-http_random_index_module=shared --with-http_secure_link_module=shared --with-http_sysguard_module=shared --with-http_charset_filter_module=shared --with-http_userid_filter_module=shared --with-http_footer_filter_module=shared --with-http_trim_filter_module=shared --with-http_access_module=shared --with-http_autoindex_module=shared --with-http_map_module=shared --with-http_split_clients_module=shared --with-http_referer_module=shared --with-http_uwsgi_module=shared --with-http_scgi_module=shared --with-http_memcached_module=shared --with-http_limit_conn_module=shared --with-http_limit_req_module=shared --with-http_empty_gif_module=shared
make && make install
报错误请执行error while loading shared libraries: libluajit-5.1.so.2: cannot open shared object file: No such file or directory
ln -s /usr/local/lib/libluajit-5.1.so.2 /lib64/libluajit-5.1.so.2
然后创建下面文件夹
mkdir -p /data/logs/{client_body,hack}
chown -R www:www /data
chmod -R 755 /data
解压ngxluawaf-master.zip
unzip ngx_lua_waf-master.zip
mv ngx_lua_waf-master/* /usr/local/webserver/nginx/conf/
vi /usr/local/webserver/nginx/conf/config.lua
RulePath = waf的路径--规则存放目录
logdir = 日志记录地址--log存储目录,该目录需要用户自己新建,切需要nginx用户的可写权限
attacklog = "off" --是否开启攻击信息记录,需要配置logdir
UrlDeny="on" --是否拦截url访问
Redirect="on" --是否拦截后重定向
CookieMatch = "on" --是否拦截cookie攻击
postMatch = "on" --是否拦截post攻击
whiteModule = "on" --是否开启URL白名单
ipWhitelist={"127.0.0.1"} --ip白名单,多个ip用逗号分隔
ipBlocklist={"1.0.0.1"} --ip黑名单,多个ip用逗号分隔
CCDeny="on" --是否开启拦截cc攻击(需要nginx.conf的http段增加luashareddict limit 10m;)
CCrate = "100/60" --设置cc攻击频率,单位为秒. --默认1分钟同一个IP只能请求同一个地址100次
html=[[Please go away~~]] --警告内容,可在中括号内自定义
备注:不要乱动双引号,区分大小写
修改nginx配置,在HTTP里面加入 记得改自己的路径
lua_need_request_body on;
lua_package_path "/usr/local/webserver/nginx/conf /?.lua";
lua_shared_dict limit 10m;
init_by_lua_file /usr/local/webserver/nginx/conf/init.lua;
access_by_lua_file /usr/local/webserver/nginx/conf/waf.lua;
limit_req_zone $binary_remote_addr $uri zone=two:3m rate=1r/s;
limit_req_zone $binary_remote_addr $request_uri zone=thre:3m rate=1r/s;
然后启动nginx.
测试创建个test.php文件,内容为test,使用curl来访问,当然前提是nginx做好了虚拟主机,这里就不介绍怎么做虚拟主机了.
curl http://localhost/test.php?id=../etc/passwd
返回的内容:test
因为127.0.0.1允许的所以能看见页面的内容,因为域名地址是不允许的所以能看不见页面的内容,说明生效了
curl http://blog.slogra.com/test.php?id=../etc/passwd
返回的内容:
转载于:https://www.cnblogs.com/xull0651/p/7473060.html
安装nginx+ngx_lua支持WAF防护功能相关推荐
- 让 Nginx 支持 WAF 防护功能web防火墙 - 沧海一粟 - Web系统架构与服务器运维,php开发...
让 Nginx 支持 WAF 防护功能web防火墙 - 沧海一粟 - Web系统架构与服务器运维,php开发
- centos7安装 Nginx+ModSecurity实现WAF
目录 Nginx+ModSecurity 安装 1.相关依赖 2. 安装Modsecurity 3.ModSecurity-nginx 安装 4.安装nginx 5.nginx + ModSecuri ...
- ubuntu 安装nginx 并开启目录浏览功能
首先 如果安装apache 应该卸载 sudo apt-get --purge remove apache2 sudo apt-get --purge remove apache2.2-common ...
- centos yum方式安装nginx 并支持https
https://www.jianshu.com/p/f5376bba4a60 转载于:https://www.cnblogs.com/falcon-fei/p/11159741.html
- linux上安装nginx及实现反向代理
nginx是高性能的http和反向代理的服务器.占用内存少,并发能力强. 主要作用有:反向代理.负载均衡.动静结合. 接下来我将描述一下如何安装nginx,同时实现反向代理功能. 1.安装nginx ...
- (46.1)【WAF绕过】知己知彼:safedog、aliyun-os、BT的防护功能理解
目录 测试环境: 一.safedog(安全狗) 1.1.下载安装教程: 1.2.核心功能: 二.aliyun-os(阿里云盾) 2.1.基础功能: 三.BT(宝塔) 3.1.下载(官网): 3.2.核 ...
- CentOS 6.3安装Nginx开启目录浏览、下载功能
本次实验实现目的: 安装Nginx,Nginx开启目录浏览.下载功能,开机默认启动:咐件自带开机启动脚本.重启脚本: 1.关闭SELINUX 查看获取SELinux的状态: [root@localho ...
- 源码包安装Nginx(1.19.1),并配置Nginx,比如:用户认证,防盗链,虚拟主机,SSL等功能
基础配置 #关闭防火墙 [root@node2 ~]# systemctl stop firewalld [root@node2 ~]# systemctl disable firewalld #清空 ...
- 编译安装nginx并实现反向代理负载均衡和缓存功能
一.编译安装nginx 1.下载 [root@ns1 ~]# wget http://nginx.org/download/nginx-1.10.0.tar.gz 2.解压 [root@ns1 ~]# ...
最新文章
- python 终止、结束、退出 代码
- JavaWeb 入门篇(7) 初次总结
- Sleepy Kaguya
- 使用Microsoft.AspNetCore.TestHost进行完整的功能测试
- html2canvas改成同步,html2canvas转为图片异步转同步问题(记录)
- 强化顶层设计 巩固网络安全
- Android 仿美团网,大众点评购买框悬浮效果之修改版
- Storyboard全解析-第二部分
- 数据仓库3级范式(3NF)基础
- Money Pro for Mac如何导入账单?
- cron每小时执行一次_crontab每小时运行一次
- 通过命令完成 虚拟机 ubuntu 中的文件拷贝到主机
- 互联网大佬扎堆出书 不为赚钱只为粉丝
- 2021年12月四六级考试成绩批量查询Java
- Tcache Attack
- 可能是史上最详细攻略的广州人才引进入户
- 互联网日报 | 5月31日 星期一 | 天猫618取消PK玩法;有赞独立新零售业务品牌;钉钉发布国内首个低代码应用广场“钉钉搭”...
- 部署N9e-v3运维监控平台
- 为何国外的人都爱用电子邮箱?注册电子邮箱有哪些好处呢?
- Python图片下载器(单线程PK多线程)_一蓑烟雨任平生