Created
July 28, 2020 14:03
-
-
Save ShellCode33/8366f015e5f33aeb9376e8cb4bf86017 to your computer and use it in GitHub Desktop.
ModSecurity automatic upgrade
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
exec_or_die() { | |
$@ &>> modsecurity_upgrade_logs || (echo "Error while executing \"$@\", read log file"; exit 1) | |
} | |
echo "[+] Upgrading ModSecurity" | |
cd /root | |
echo " - Git clone..." | |
exec_or_die git clone https://github.com/SpiderLabs/ModSecurity.git | |
cd ModSecurity | |
echo " - Configuring..." | |
exec_or_die ./build.sh | |
exec_or_die ./configure | |
echo " - Compiling..." | |
exec_or_die make | |
echo " - Installing..." | |
exec_or_die make install | |
echo "[+] Upgrading NGINX Connector for MS" | |
NGINX_VERSION=$(nginx -v 2>&1 | cut -d'/' -f 2) | |
echo " - Downloading..." | |
exec_or_die wget http://nginx.org/download/nginx-${NGINX_VERSION}.tar.gz | |
echo " - Extracting...." | |
exec_or_die tar zxf nginx-${NGINX_VERSION}.tar.gz | |
echo " - Configuring..." | |
cd nginx-${NGINX_VERSION} | |
exec_or_die ./configure --with-compat --add-dynamic-module=../ModSecurity-nginx | |
echo " - Compiling..." | |
exec_or_die make modules | |
cp objs/ngx_http_modsecurity_module.so /etc/nginx/modules | |
echo "[+] Upgrading recommended MS configuration" | |
wget https://raw.githubusercontent.com/SpiderLabs/ModSecurity/v3/master/modsecurity.conf-recommended -O /etc/nginx/modsec/modsecurity.conf | |
echo "[+] Upgrade complete ! Restarting Nginx..." | |
service nginx restart | |
echo "[+] Saving space by removing cloned repository..." | |
rm -rf /root/ModSecurity |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment