From owner-freebsd-stable@freebsd.org Wed Jan 23 00:59:13 2019 Return-Path: Delivered-To: freebsd-stable@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 71ACA14B5796 for ; Wed, 23 Jan 2019 00:59:13 +0000 (UTC) (envelope-from matt.garber@gmail.com) Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (Client CN "smtp.gmail.com", Issuer "Google Internet Authority G3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 8D4B582307 for ; Wed, 23 Jan 2019 00:59:12 +0000 (UTC) (envelope-from matt.garber@gmail.com) Received: by mail-qt1-x829.google.com with SMTP id t33so584503qtt.4 for ; Tue, 22 Jan 2019 16:59:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=+oExpbMqpOCRVYOg5UnXMpHAHZ+lKyRUZDbFqaivuU8=; b=tEXvLgUVzSsgJPqp+SYxIZxzU0HrbZvenKihU6+KDRlCTu7NB7uprSiYZPIaPjNrqy BEXp0qTT3ZqtBOFAe5HLbPzC3CYwAXmlusOsrMhD53eQZl+h0XvnKX2Ikc+BMG8U6VDL rQ1wKYlw2fdkQ8HAkZihcIPq7ZikWsRnHY03fAxKRQMYy7v742G7ZEDMlslb0ENOVzTF foTufWzAm3nr6DdFybSh3XMQGt5lHSq9CnhZkpjS7qCX1c2nkHgpngV+2VWZUNMQdIxa UJBHjUUluXyLhN3vaDcG8+va+bLJW5QA/JtHI+auO3Hry+QdoWwvBChHEF+MMtmH+dGH N9WA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:subject:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to; bh=+oExpbMqpOCRVYOg5UnXMpHAHZ+lKyRUZDbFqaivuU8=; b=Si2zGB0L4fgWptHAXlbcpnHjURk5CukkAbz8ZpljmGftHOTGK/0eXpO3Zt/tMxxsK9 3jtqesuaCbTpCztRlVniGS3J2EawOzi5qwZhd9H1V71RuvVD4Fw5v08f7EXQE/hFy01N H1QIUQND8NwjIPF8YRXNkpBPkaTsr/JmXK/c9fOuR0RwUmjmSO4bIDZ0FcwNMQQd0Set en+IcJ2Ur/Wqlh3un1qE8sf4UHQ9KGiC03SKCR1SsuCVV9OXo7vrYQ7w1lpD/myubquA EA+cSbW2WAHTeZl4fnHV/RS/ldip1IWiqp/vbfxzCDrKlYqmKFOJb11KTgbS/VY1OmQB 2icA== X-Gm-Message-State: AJcUukfjzYU4Ph2eiow+Ywu8HeQ5JvT9LPaGqJ6SM5uhhErvAZE+VY+q xLjHmwP0CUAkQYwf0MtvcAA= X-Google-Smtp-Source: ALg8bN4IR/P+46gzwhrkItNICcOGOB5/PPJsB/q4ab95a589eC+bxw8iLashnGjv3RyD1SCFaj5oEg== X-Received: by 2002:aed:2ee5:: with SMTP id k92mr167124qtd.304.1548205152047; Tue, 22 Jan 2019 16:59:12 -0800 (PST) Received: from [10.137.64.34] ([216.151.191.252]) by smtp.gmail.com with ESMTPSA id n67sm50836292qkd.95.2019.01.22.16.59.11 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 22 Jan 2019 16:59:11 -0800 (PST) Content-Type: text/plain; charset=utf-8 Mime-Version: 1.0 (Mac OS X Mail 12.2 \(3445.102.3\)) Subject: Re: Issue with mod_security3 From: Matt Garber X-Priority: 3 In-Reply-To: <5c47b2c0.1c69fb81.ba7c2.95f3@mx.google.com> Date: Tue, 22 Jan 2019 19:59:09 -0500 Cc: "freebsd-stable@freebsd.org" Content-Transfer-Encoding: quoted-printable Message-Id: References: <5c4744cd.1c69fb81.7b84f.5450@mx.google.com> <20190122185438.GC85865@v1.leiden.byshenk.net> <5c476baa.1c69fb81.58970.0af8@mx.google.com> <5c47b2c0.1c69fb81.ba7c2.95f3@mx.google.com> To: SoftwareInforJam X-Mailer: Apple Mail (2.3445.102.3) X-Rspamd-Queue-Id: 8D4B582307 X-Spamd-Bar: ------ Authentication-Results: mx1.freebsd.org; dkim=pass header.d=gmail.com header.s=20161025 header.b=tEXvLgUV; dmarc=pass (policy=none) header.from=gmail.com; spf=pass (mx1.freebsd.org: domain of mattgarber@gmail.com designates 2607:f8b0:4864:20::829 as permitted sender) smtp.mailfrom=mattgarber@gmail.com X-Spamd-Result: default: False [-6.12 / 15.00]; TO_DN_EQ_ADDR_SOME(0.00)[]; RCVD_VIA_SMTP_AUTH(0.00)[]; TO_DN_SOME(0.00)[]; R_SPF_ALLOW(-0.20)[+ip6:2607:f8b0:4000::/36]; MV_CASE(0.50)[]; FREEMAIL_FROM(0.00)[gmail.com]; RCVD_COUNT_THREE(0.00)[3]; DKIM_TRACE(0.00)[gmail.com:+]; RCPT_COUNT_TWO(0.00)[2]; HAS_X_PRIO_THREE(0.00)[3]; MX_GOOD(-0.01)[cached: alt3.gmail-smtp-in.l.google.com]; DMARC_POLICY_ALLOW(-0.50)[gmail.com,none]; FREEMAIL_TO(0.00)[gmail.com]; FROM_EQ_ENVFROM(0.00)[]; MIME_TRACE(0.00)[0:+]; FREEMAIL_ENVFROM(0.00)[gmail.com]; ASN(0.00)[asn:15169, ipnet:2607:f8b0::/32, country:US]; TAGGED_FROM(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; DWL_DNSWL_NONE(0.00)[gmail.com.dwl.dnswl.org : 127.0.5.0]; ARC_NA(0.00)[]; NEURAL_HAM_MEDIUM(-1.00)[-1.000,0]; R_DKIM_ALLOW(-0.20)[gmail.com:s=20161025]; FROM_HAS_DN(0.00)[]; NEURAL_HAM_SHORT(-0.94)[-0.944,0]; NEURAL_HAM_LONG(-1.00)[-1.000,0]; MIME_GOOD(-0.10)[text/plain]; PREVIOUSLY_DELIVERED(0.00)[freebsd-stable@freebsd.org]; TO_MATCH_ENVRCPT_SOME(0.00)[]; RCVD_IN_DNSWL_NONE(0.00)[9.2.8.0.0.0.0.0.0.0.0.0.0.0.0.0.0.2.0.0.4.6.8.4.0.b.8.f.7.0.6.2.list.dnswl.org : 127.0.5.0]; RCVD_TLS_LAST(0.00)[]; IP_SCORE(-2.67)[ip: (-8.90), ipnet: 2607:f8b0::/32(-2.46), asn: 15169(-1.89), country: US(-0.08)] X-BeenThere: freebsd-stable@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Production branch of FreeBSD source code List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 23 Jan 2019 00:59:13 -0000 > On Jan 22, 2019, at 7:18 PM, SoftwareInforJam = wrote: >=20 > Well I am making some progress I guess. Now modsecurity is installed = and not orphaned. My challenge now is that I have been reading several = documents and all of them say I need to add the following to nginx.conf >=20 > load_module modules/ngx_http_modsecurity.so; >=20 > My challenge now is I can=E2=80=99t seem to find this module anywhere. = I am not sure what to do now. Isn=E2=80=99t this module needed for this = to work? >=20 > root@proxy:/usr/local/etc/nginx # find / -name "ngx_http_modsecurity*" > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _body_filter.o > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _rewrite.o > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _log.o > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _pre_access.o > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _header_filter.o > = /usr/ports/www/nginx/work/nginx-1.14.2/objs/addon/src/ngx_http_modsecurity= _module.o > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_body_filter.c > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_common.h > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_header_filter.c > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_log.c > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_module.c > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_pre_access.c > = /usr/ports/www/nginx/work/ModSecurity-nginx-71ede63/src/ngx_http_modsecuri= ty_rewrite.c Here are the steps I just followed successfully in a test jail =E2=80=93 = a mix of packages (modsecurity3) and the source for nginx and the = ModSecurity3-nginx connector; the =E2=80=98modsecurity3=E2=80=99 package = installs the shared library (e.g., = /usr/local/lib/libmodsecurity.so.3.0.3), but doesn=E2=80=99t install the = nginx connector. If the nginx port doesn=E2=80=99t have a make option = for the connector, you might have to either hack the port or just = compile from source like I did: ----- Very simplified, single jail ----- 1. Install the modsecurity3 library package and git for cloning the = ModSecurity-nginx repo: # pkg install modsecurity3 git 2. Grab the latest nginx source and ModSecurity-nginx repo: $ fetch 'http://nginx.org/download/nginx-1.14.2.tar.gz' $ tar -zxvf nginx-1.14.2.tar.gz $ git clone --depth 1 = https://github.com/SpiderLabs/ModSecurity-nginx.git $ cd nginx-1.14.2 3. Compile nginx, adding support for the ModSecurity3-nginx connector as = a dynamic module. I=E2=80=99ve also added a variety of other = FreeBSD-specific configuration directives and/or compilation/linking = hardening used by nginx upstream in their Linux repositories: $ ./configure --with-compat --add-dynamic-module=3D../ModSecurity-nginx = --prefix=3D/usr/local/etc/nginx --with-cc-opt=3D'-g -O2 = -fstack-protector-strong -Wformat -Werror=3Dformat-security -fPIC = -Wdate-time -D_FORTIFY_SOURCE=3D2 -I /usr/local/include' = --with-ld-opt=3D'-Wl,-Bsymbolic-functions -Wl,-z,relro -Wl,-z,now -fPIC = -L /usr/local/lib' --conf-path=3D/usr/local/etc/nginx/nginx.conf = --sbin-path=3D/usr/local/sbin/nginx --pid-path=3D/var/run/nginx.pid = --error-log-path=3D/var/log/nginx/error.log --user=3Dwww --group=3Dwww = --modules-path=3D/usr/local/libexec/nginx --with-file-aio --with-threads = --without-mail_imap_module --without-mail_pop3_module = --without-mail_smtp_module --with-mail_ssl_module = --http-client-body-temp-path=3D/var/tmp/nginx/client_body_temp = --http-fastcgi-temp-path=3D/var/tmp/nginx/fastcgi_temp = --http-proxy-temp-path=3D/var/tmp/nginx/proxy_temp = --http-scgi-temp-path=3D/var/tmp/nginx/scgi_temp = --http-uwsgi-temp-path=3D/var/tmp/nginx/uwsgi_temp = --http-log-path=3D/var/log/nginx/access.log --with-http_addition_module = --with-http_auth_request_module --with-http_flv_module = --with-http_gunzip_module --with-http_gzip_static_module = --with-http_random_index_module --with-http_realip_module --with-pcre = --with-http_secure_link_module --with-http_slice_module = --with-http_ssl_module --with-http_stub_status_module = --with-http_sub_module --with-http_v2_module --with-stream_ssl_module = --with-mail=3Ddynamic --with-stream=3Ddynamic $ make $ sudo make install 4. The above step should have created ngx_http_modsecurity_module.so = under the nginx source directory, and installed it into = /usr/local/libexec/nginx, at which point the load_module directive in = the nginx configuration should work fine, and you can move on to ruleset = configuration. FYI, all of the above just follows the ~second half of = , after taking care of the prerequisites with FreeBSD = packages instead. Like I said, you could probably relatively easily hack = the nginx port to add in the integration of ModSecurity3-nginx if you = care about that more than keeping up-to-date with nginx source = separately, but then you=E2=80=99d have to avoid overwriting the port = =E2=80=93 YMMV. Thanks, =E2=80=94 Matt Garber