nbs-system / naxsi

NAXSI is an open-source, high performance, low rules maintenance WAF for NGINX
GNU General Public License v3.0
4.8k stars 606 forks source link

Problems with "MainRule" directive is not allowed here #501

Closed DiederikDeZee closed 1 year ago

DiederikDeZee commented 4 years ago

Hi Guys, im receiving some errors with a "MainRule" directive is not allowed here in /etc/nginx/naxsi_core.rules:19. Im running the latest stable version of naxsi.

NGINX Module compilation information (output from nginx -V): nginx version: nginx/1.18.0 built by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2) built with OpenSSL 1.1.1f 31 Mar 2020 TLS SNI support enabled configure arguments: --add-module=/root/naxsi-master/naxsi_src/ --sbin-path=/usr/sbin/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module

Error code from NGINX returned:

nginx: [emerg] "MainRule" directive is not allowed here in /etc/nginx/naxsi_core.rules:19
nginx: configuration file /etc/nginx/nginx.conf test failed

I'm running Ubuntu 20.04, kernel: 5.4.0-40-generic #44-Ubuntu SMP Tue Jun 23 00:01:04 UTC 2020 x86_64 x86_64 x86_64 GNU/Linux

Or could it be because naxsi/this nginx version can't be compiled against a 5.4 kernel?

Looking forward to your guys's response!

wargio commented 4 years ago

i think is your configuration. The core rules should not be included inside a location. Move the 'include "/etc/nginx/naxsi_core.rules";' outside the location and it will work.

DiederikDeZee commented 4 years ago

i think is your configuration. The core rules should not be included inside a location. Move the 'include "/etc/nginx/naxsi_core.rules";' outside the location and it will work.

It is placed directly in the /etc/nginx/nginx.conf above any opening tags /locations and/or server tags of some sort. Any other ideas?

wargio commented 4 years ago

can i see the config? Please try to doublecheck your configuration with this: https://github.com/nbs-system/naxsi/wiki/naxsi-compile#basic-setup

DiederikDeZee commented 4 years ago

Hi,

Currently it is:

user www-data;
worker_processes auto;
pid /run/nginx.pid;
include /etc/nginx/modules-enabled/*.conf;
include /etc/nginx/naxsi_core.rules;

events {
        worker_connections 768;
        # multi_accept on;
}

http {

        ##
        # Basic Settings
        ##

        sendfile on;
        tcp_nopush on;
        tcp_nodelay on;
        keepalive_timeout 65;
... etc, basic NGINX config...

The module should already be compiled within NGINX and active, so that's why the load_module isn't specified here:

root@web1:/etc/nginx# nginx -V
nginx version: nginx/1.18.0
built by gcc 9.3.0 (Ubuntu 9.3.0-10ubuntu2)
built with OpenSSL 1.1.1f  31 Mar 2020
TLS SNI support enabled
configure arguments: --add-module=/root/naxsi-master/naxsi_src/ --sbin-path=/usr/sbin/nginx --with-cc-opt='-g -O2 -fdebug-prefix-map=/build/nginx-5J5hor/nginx-1.18.0=. -fstack-protector-strong -Wformat -Werror=format-security -fPIC -Wdate-time -D_FORTIFY_SOURCE=2' --with-ld-opt='-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC' --prefix=/usr/share/nginx --conf-path=/etc/nginx/nginx.conf --http-log-path=/var/log/nginx/access.log --error-log-path=/var/log/nginx/error.log --lock-path=/var/lock/nginx.lock --pid-path=/run/nginx.pid --modules-path=/usr/lib/nginx/modules --http-client-body-temp-path=/var/lib/nginx/body --http-fastcgi-temp-path=/var/lib/nginx/fastcgi --http-proxy-temp-path=/var/lib/nginx/proxy --http-scgi-temp-path=/var/lib/nginx/scgi --http-uwsgi-temp-path=/var/lib/nginx/uwsgi --with-debug --with-compat --with-pcre-jit --with-http_ssl_module --with-http_stub_status_module --with-http_realip_module --with-http_auth_request_module --with-http_v2_module --with-http_dav_module --with-http_slice_module --with-threads --with-http_addition_module --with-http_gunzip_module --with-http_gzip_static_module --with-http_image_filter_module=dynamic --with-http_sub_module --with-http_xslt_module=dynamic --with-stream=dynamic --with-stream_ssl_module --with-mail=dynamic --with-mail_ssl_module
wargio commented 4 years ago

include /etc/nginx/naxsi_core.rules;

I can confirm that the include /etc/nginx/naxsi_core.rules; shall go inside the http {} block, not outside Sorry for the late reply.