🚨 官方域名僅限: gebu8f.com / gebu8f.link / gebu8f.de
若見到其他相似網站,皆非本人所有,請勿相信。

httpguard安裝

63次閱讀
尚無留言

共计 4576 个字符,预计需要花费 12 分钟才能阅读完成。

前置作業(如果是使用我一鍵腳本可不執行)

PHP

備註:php版本可自訂,如果你已經安裝php的不需執行

你是debain/ubuntu系統

apt update
apt install -y software-properties-common ca-certificates lsb-release gnupg curl

這裡是屬於debain

curl -fsSL https://packages.sury.org/php/apt.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/ondrej_php.gpg
echo "deb https://packages.sury.org/php/ $(lsb_release -sc) main" > /etc/apt/sources.list.d/php.list

這裡是Ubuntu

add-apt-repository -y ppa:ondrej/php

繼續安裝….

apt update
apt install -y php8.3 php8.3-gd

centOS 9 stream/Redhot系列

yum update -y
yum install -y epel-release
yum install -y https://rpms.remirepo.net/enterprise/remi-release-9.rpm
yum update -y
yum module reset php -y
yum module enable php:remi-8.3-y
yum install -y php php-gd

alpine

echo "@edgecommunity http://dl-cdn.alpinelinux.org/alpine/edge/community" >> /etc/apk/repositories     
apk update
apk add php83 php83-gd

工具

openresy和nginx配置文件路徑

/usr/local/openresty/nginx/conf
/etc/nginx

首先,你需要先有配置lua環境的nginx/openresy

檢查:

nginx/openresy -V | grep -q lua

❓ 你的環境不支援 Lua 嗎?可以參考我的 ng.sh 腳本自動開啟 Lua 模組👉 https://www.gebu8f.com/site-new/

到這裡下載檔案,可放在nginx/openresy安裝位置:https://pan.gebu8f.link/s/d1sN

解壓之後你會看到

httpguard安裝

cd captcha目錄

然後輸入php getImg.php等待一下

再來輸入

cd ..
nano config.lua

上方的baseDir = ‘/usr/local/openresty/nginx/conf/HttpGuard/’替換成你實際安裝路徑

⚠️注意:下方的主動防禦區塊建議只開啟一個

再來是用nano編輯器打開nginx配置文件

Debain/RHEL

nano /usr/local/openresty/nginx/conf/nginx.conf

alpine

nano /etc/nginx/nginx.conf

插入以下代碼請一定要插入在http區塊

備註:/usr/local/openresty/nginx/conf/HttpGuard/替換成你存放httpguard的路徑ex /etc/nginx/Httpguard。

備註alpine請將上面的lua_package_path、lua_package_cpath替換成

lua_package_path "/usr/local/share/lua/5.1/?.lua;/etc/nginx/HttpGuard/?.lua;;";     
lua_package_cpath "/usr/local/lib/lua/5.1/?.so;;";
lua_package_path "/usr/local/openresty/lualib/?.lua;/usr/local/openresty/nginx/conf/HttpGuard/?.lua;;"; 
lua_package_cpath "/usr/local/openresty/lualib/?.so;;";
lua_shared_dict guard_dict 100m;
lua_shared_dict dict_captcha 128m;
init_by_lua_file /usr/local/openresty/nginx/conf/HttpGuard/init.lua;
access_by_lua_file /usr/local/openresty/nginx/conf/HttpGuard/runtime.lua;
lua_max_running_timers 1;

如果沒有lua模塊的話

⚠️請解除安裝你的web server software

備註:我這個只是教你怎麼安裝,沒有配置文件修改,現在這樣有一個alpine是無法使用的,所以還是使用我一鍵腳本比較好

Debain/Ubuntu

apt update
apt install -y curl gnupg2 ca-certificates lsb-release
curl -s https://openresty.org/package/pubkey.gpg | gpg --dearmor -o /etc/apt/trusted.gpg.d/openresty.gpg
# debain 
echo "deb http://openresty.org/package/debian $(lsb_release -sc) openresty" | tee /etc/apt/sources.list.d/openresty.list
# Ubuntu 
echo "deb http://openresty.org/package/ubuntu $(lsb_release -sc) openresty" | tee /etc/apt/sources.list.d/openresty.list
apt install openresty -y

centOS 9 stream/RHEL

yum update
yum install -y yum-utils
yum-config-manager --add-repo https://openresty.org/package/centos/openresty.repo
yum update
yum install -y openresty --nogpgcheck

alpine

apk update
apk add build-base pcre-dev zlib-dev openssl-dev git cmake linux-headers perl luajit-dev libtool automake autoconf
wget https://nginx.org/download/nginx-1.27.5.tar.gz
tar -xzvf nginx-1.27.5.tar.gz    
cd nginx-1.27.5
git clone --depth=1 -b OpenSSL_1_1_1u+quic https://github.com/quictls/openssl.git
git clone https://github.com/simpl/ngx_devel_kit.git
git clone https://github.com/openresty/lua-nginx-module.git
./configure \  
--prefix=/etc/nginx \  
--sbin-path=/usr/sbin/nginx \  
--conf-path=/etc/nginx/nginx.conf \  --with-http_v3_module \  
--with-http_ssl_module \  
--with-http_v2_module \  
--with-http_gzip_static_module \  
--with-http_realip_module \ 
--with-stream \  
--with-http_stub_status_module \  
--with-openssl=./openssl \  
--with-cc-opt="-I./openssl/include -I/usr/include/luajit-2.1" \  
--with-ld-opt="-L./openssl -lluajit-5.1" \  
--add-module=./ngx_devel_kit \  
--add-module=./lua-nginx-module
make
make install
rm -rf nginx-1.27.5 nginx-1.27.5.tar.gz

config.lua介紹

302跳轉模塊,利用cc控制端不支援解析響應頭的特點,來辨識是否為正常用戶,建議不要開啟,因為SEO有可能會出事

redirectModules = { state = "Off" ,verifyMaxFail = 5, keySecret = 'yK48J276hg', amongTime = 60 ,urlProtect = baseDir.."url-protect/302.txt"},

JS跳轉(大招),利用cc控制端無法解析js跳轉的特點,來辨識是否為正常用戶

JsJumpModules = { state = "Off" ,verifyMaxFail = 5, keySecret = 'QSjL6p38h9', amongTime = 60 , urlProtect = baseDir.."url-protect/js.txt"},

cookie(普通人最察覺不到),此模組會向訪客發送cookie,然後等待訪客返回正確的cookie,此模組利用cc控制端無法支援cookie的特點,來識別cc攻擊

cookieModules = { state = "Off" ,verifyMaxFail = 5, keySecret = 'bGMfY2D5t3', amongTime = 60 , urlProtect = baseDir.."url-protect/cookie.txt"},

自動開啟主動防禦模塊,原理是根據protectPort連接埠的已連線數超過maxConnection來決定

⚠️請確保ss指令有安裝

查看路徑

which ss

這是每個參數的解釋

參數名 含義 說明
protectPort 保護的服務端口 多半是 “80” 或 “443”,即 HTTP/HTTPS
interval 掃描間隔時間(秒) 每隔多少秒檢查一次是否需要觸發防禦
normalTimes 正常連線次數 指可接受的正常連線次數,超過才觸發防禦
exceedTimes 超過限制次數 達到這個次數就觸發主動防禦
maxConnection 單一 IP 允許的最大連線數 超過這個數值會被視為異常
ssCommand 使用的連線查詢指令路徑 上方使用which ss查到的路徑
enableModule 啟用的主動防禦模組名稱 我上方介紹的其中一個可填入
autoEnable = { state = "Off", protectPort = "443", interval = 5, normalTimes = 1,exceedTimes = 1,maxConnection = 15, ssCommand = "/usr/bin/ss" ,enableModule = "JsJumpModules"},
gebu8f

Author: gebu8f

正文完
 0
評論(尚無留言)