• 利用开源软件自建WAF系统--OpenResty+unixhot


    简介:利用OpenResty+unixhot自建WAF系统

    介绍

      OpenResty是一个基于 Nginx 与 Lua 的高性能 Web 平台,其内部集成了大量精良的 Lua 库、第三方模块以及大多数的依赖项。用于方便地搭建能够处理超高并发、扩展性极高的动态 Web 应用、Web 服务和动态网关。
      OpenResty通过汇聚各种设计精良的 Nginx 模块(主要由 OpenResty 团队自主开发),从而将 Nginx 有效地变成一个强大的通用 Web 应用平台。这样,Web 开发人员和系统工程师可以使用 Lua 脚本语言调动 Nginx 支持的各种 C 以及 Lua 模块,快速构造出足以胜任 10K 乃至 1000K 以上单机并发连接的高性能 Web 应用系统。
      OpenResty的目标是让你的Web服务直接跑在 Nginx 服务内部,充分利用 Nginx 的非阻塞 I/O 模型,不仅仅对 HTTP 客户端请求,甚至于对远程后端诸如 MySQL、PostgreSQL、Memcached 以及 Redis 等都进行一致的高性能响应。

    安装Openresty

    以CentOS7.5为例
    1.安装命令如下

    yum install yum-utils -y
    yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
    yum install openresty-resty -y
    yum --disablerepo="*" --enablerepo="openresty" list available #列出所有 openresty 仓库里的软件包
    

    安装完成如下图所示

    2.查看openresty所在目录

    whereis openresty
    

    修改nginx.conf

    cd /usr/local/openresty/nginx/conf
    ls
    mv nginx.conf nginx.conf.$(date +%Y%m%d) #将nginx.conf移入nginx.conf.$(date +%Y%m%d)
    


    vim nginx.conf #此时为新建 nginx.conf
    将以下内容复制到nginx.conf中并保存

    worker_processes  1;
    error_log logs/error.log;
    events {
        worker_connections 1024;
    }
    http {
        server {
            listen 8080;
            location / {
                default_type text/html;
                content_by_lua '
                    ngx.say("<p>hello, world</p>")
                ';
            }
        }
    }
    

    添加环境变量

    echo "export PATH=$PATH:/usr/local/openresty/nginx/sbin" >> /etc/profile
    source /etc/profile
    

    启动Openresty

    nginx -c /usr/local/openresty/nginx/conf/nginx.conf
    

    查看服务

    ps -ef | grep  nginx
    

    访问web服务验证是否正常

    curl http://localhost:8080/
    

    重启web服务

    nginx -s reload
    

    部署WAF

    unixhot下载,如果没有git,先安装一下

    yum -y install git
    git clone https://github.com/unixhot/waf.git
    

    将WAF配置文件夹复制到nginx的配置下

    cp -a ~/waf/waf /usr/local/openresty/nginx/conf/
    

    修改nginx.conf配置,加入如下代码并保存

    #WAF
    lua_shared_dict limit 10m;
    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";
    

    到目前为止,修改过的nginx.conf文件如下图所示:

    测试配置

    /usr/local/openresty/nginx/sbin/nginx -t
    


    重新加载配置

    /usr/local/openresty/nginx/sbin/nginx -s reload
    

    测试WAF

    模拟SQL注入

    本文参考链接:
    https://www.cnblogs.com/sanduzxcvbnm/p/11322946.html

    作者:RitaWWang
    本文版权归作者和博客园共有,欢迎转载,但必须给出原文链接,并保留此段声明,否则保留追究法律责任的权利。
  • 相关阅读:
    常用网址
    设备像素比devicePixelRatio简单介绍
    VR虚拟红包的技术实现
    jQuery重置表单
    jQuery,遍历表格每个单元格数据。
    java 23种设计模式 链接集锦
    webstorm创建nodejs + express + jade 的web 项目
    类与类之间的几种关系
    JS 中的事件绑定、事件监听、事件委托是什么?
    简单的JavaScript图像延迟加载库Echo.js
  • 原文地址:https://www.cnblogs.com/RitaWWang/p/11949896.html
Copyright © 2020-2023  润新知