簡介:利用OpenResty+unixhot自建WAF系統
目錄
- 介紹
- 安裝Openresty
- 修改nginx.conf
- 部署WAF
- 測驗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
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/51324.html
標籤:其他
上一篇:Shiro RememberMe 1.2.4 反序列化漏洞復現
下一篇:TCP/IP網路協議初識
