{"id":1524,"date":"2022-01-06T20:42:11","date_gmt":"2022-01-06T19:42:11","guid":{"rendered":"https:\/\/www.web-workers.ch\/?p=1524"},"modified":"2022-01-07T11:33:04","modified_gmt":"2022-01-07T10:33:04","slug":"how-to-install-and-configure-nginx-naxsi-web-application-firewall-on-freebsd13","status":"publish","type":"post","link":"https:\/\/www.web-workers.ch\/index.php\/2022\/01\/06\/how-to-install-and-configure-nginx-naxsi-web-application-firewall-on-freebsd13\/","title":{"rendered":"How to install and configure nginx-naxsi web application firewall on FreeBSD13"},"content":{"rendered":"\r\n<p>Naxsi &#8220;<a href=\"https:\/\/github.com\/nbs-system\/naxsi\" target=\"_blank\" rel=\"noopener\">Nginx Anti XSS &amp; SQL Injection<\/a>&#8221; is a free, open-source and high-performance web application firewall that can be used to protect your webserver against different types of attacks like SQL Injections and Cross-Site Scripting. Naxsi works by detecting unexpected characters in the HTTP GET and POST requests. In this tutorial, we will show you how to install and configure nginx-naxsi firewall asa\u00a0 reverse proxy on <a href=\"https:\/\/www.freebsd.org\/releases\/13.0R\/announce\/\" target=\"_blank\" rel=\"noopener\">FreeBSD13<\/a> to protect a webserver of your choice behind it.<\/p>\r\n<h3>Install FreeBSD 13 on your system<\/h3>\r\n<p><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1552\" data-permalink=\"https:\/\/www.web-workers.ch\/index.php\/2022\/01\/06\/how-to-install-and-configure-nginx-naxsi-web-application-firewall-on-freebsd13\/2022-01-06-17_42_40-shield-netcult-ch-freebsd13-vmware-remote-console\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_42_40-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=716%2C393&amp;ssl=1\" data-orig-size=\"716,393\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2022-01-06 17_42_40-shield.netcult.ch &#8211; FreeBSD13 &#8211; VMware Remote Console\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_42_40-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=716%2C393&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_42_40-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C165&#038;ssl=1\" alt=\"\" width=\"300\" height=\"165\" class=\"alignnone size-medium wp-image-1552\" srcset=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_42_40-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C165&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_42_40-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?w=716&amp;ssl=1 716w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>We only selected 32-bit compatibility libraries<br \/><br \/><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1553\" data-permalink=\"https:\/\/www.web-workers.ch\/index.php\/2022\/01\/06\/how-to-install-and-configure-nginx-naxsi-web-application-firewall-on-freebsd13\/2022-01-06-17_46_53-shield-netcult-ch-freebsd13-vmware-remote-console\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_46_53-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=717%2C399&amp;ssl=1\" data-orig-size=\"717,399\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2022-01-06 17_46_53-shield.netcult.ch &#8211; FreeBSD13 &#8211; VMware Remote Console\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_46_53-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=717%2C399&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_46_53-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C167&#038;ssl=1\" alt=\"\" width=\"300\" height=\"167\" class=\"alignnone size-medium wp-image-1553\" srcset=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_46_53-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C167&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_46_53-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?w=717&amp;ssl=1 717w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>We created a partition with enough space for all logs in \/var\/log<br \/><br \/><img data-recalc-dims=\"1\" loading=\"lazy\" decoding=\"async\" data-attachment-id=\"1554\" data-permalink=\"https:\/\/www.web-workers.ch\/index.php\/2022\/01\/06\/how-to-install-and-configure-nginx-naxsi-web-application-firewall-on-freebsd13\/2022-01-06-17_50_07-shield-netcult-ch-freebsd13-vmware-remote-console\/\" data-orig-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_50_07-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=717%2C397&amp;ssl=1\" data-orig-size=\"717,397\" data-comments-opened=\"1\" data-image-meta=\"{&quot;aperture&quot;:&quot;0&quot;,&quot;credit&quot;:&quot;&quot;,&quot;camera&quot;:&quot;&quot;,&quot;caption&quot;:&quot;&quot;,&quot;created_timestamp&quot;:&quot;0&quot;,&quot;copyright&quot;:&quot;&quot;,&quot;focal_length&quot;:&quot;0&quot;,&quot;iso&quot;:&quot;0&quot;,&quot;shutter_speed&quot;:&quot;0&quot;,&quot;title&quot;:&quot;&quot;,&quot;orientation&quot;:&quot;0&quot;}\" data-image-title=\"2022-01-06 17_50_07-shield.netcult.ch &#8211; FreeBSD13 &#8211; VMware Remote Console\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_50_07-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?fit=717%2C397&amp;ssl=1\" src=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_50_07-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C166&#038;ssl=1\" alt=\"\" width=\"300\" height=\"166\" class=\"alignnone size-medium wp-image-1554\" srcset=\"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_50_07-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?resize=300%2C166&amp;ssl=1 300w, https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/2022-01-06-17_50_07-shield.netcult.ch-FreeBSD13-VMware-Remote-Console.png?w=717&amp;ssl=1 717w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><br \/>We applied the offered hardening methods as seen in the image.<\/p>\r\n<h3>Enable remote management via SSH<\/h3>\r\n<p>Add following lines to \/etc\/ssh\/sshd_config:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code># Allow root login via sshd\r\nPermitRootLogin yes<\/code><\/pre>\r\n<\/div>\r\n<p>Restart sshd service to apply the setting.<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># \/etc\/rc.d\/sshd restart<\/code><\/pre>\r\n<\/div>\r\n<h3>Update FreeBSD to the latest version<\/h3>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code># freebsd-update fetch\r\n# freebsd-update install<\/code><\/pre>\r\n<\/div>\r\n<h3>Install nginx-naxsi package<\/h3>\r\n<p>Install the package, by doing this you will be asked to download the package-manager.<br \/><span><\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># pkg install nginx-naxsi<\/code><\/pre>\r\n<\/div>\r\n<p><span>Enable the service on startup<br \/><\/span><\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># sysrc nginx_enable=YES<\/code><\/pre>\r\n<\/div>\r\n<h3>Configure nginx to properly load naxsi requirements<\/h3>\r\n<p>Create \/usr\/local\/etc\/nginx\/naxsi.rules with following content:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code>## Enables learning mode\r\nLearningMode;\r\n## Enable rules\r\nSecRulesEnabled;\r\n#SecRulesDisabled;\r\n## URL to redirect to if access is denied\r\nDeniedUrl \"\/DeniedRequest\";\r\n\r\n## Check rules\r\nCheckRule \"$SQL &gt;= 8\" BLOCK;\r\nCheckRule \"$RFI &gt;= 8\" BLOCK;\r\nCheckRule \"$TRAVERSAL &gt;= 4\" BLOCK;\r\nCheckRule \"$EVADE &gt;= 4\" BLOCK;\r\nCheckRule \"$XSS &gt;= 8\" BLOCK;\r\n<\/code><\/pre>\r\n<\/div>\r\n<p>Add http_naxsi_module.so to \/usr\/local\/etc\/nginx\/nginx.conf:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code>load_module \/usr\/local\/libexec\/nginx\/ngx_http_naxsi_module.so;<\/code><\/pre>\r\n<\/div>\r\n<p>Add naxsi_core.rules to the http section of \/usr\/local\/etc\/nginx\/nginx.conf:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code>include naxsi_core.rules;<\/code><\/pre>\r\n<\/div>\r\n<p>Add naxsi.rules to the server section of \/usr\/local\/etc\/nginx\/nginx.conf:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code>include naxsi.rules;<\/code><\/pre>\r\n<\/div>\r\n<p>Find below our sample configuration.<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-plain\" data-lang=\"Plain Text\"><code>load_module                  \/usr\/local\/libexec\/nginx\/ngx_http_naxsi_module.so;\r\nworker_processes             4;\r\n\r\nevents {\r\n    worker_connections       2048;\r\n}\r\n\r\nhttp {\r\n    include                  mime.types;\r\n    include                  naxsi_core.rules;\r\n    default_type             application\/octet-stream;\r\n\r\n    sendfile                 on;\r\n    #tcp_nopush              on;\r\n\r\n    keepalive_timeout        65;\r\n    gzip                     on;\r\n\r\n    server {\r\n        listen               80;\r\n        server_name          some.hostname.dom;\r\n        location \/ {\r\n            include          naxsi.rules;\r\n            proxy_set_header Host $host;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_pass       http:\/\/1.2.3.4;\r\n        }\r\n    }\r\n    server {\r\n        listen               443 ssl;\r\n        server_name          some.hostname.dom;\r\n        ssl_certificate      certs\/somecertfile.pem;\r\n        ssl_certificate_key  certs\/somekeyfile.key;\r\n        ssl_session_cache    shared:SSL:1m;\r\n        ssl_session_timeout  5m;\r\n        ssl_ciphers          HIGH:!aNULL:!MD5;\r\n        ssl_prefer_server_ciphers on;\r\n        location \/ {\r\n            include          naxsi.rules;\r\n            proxy_set_header Host $host;\r\n            proxy_set_header X-Real-IP $remote_addr;\r\n            proxy_pass       https:\/\/1.2.3.4;\r\n        }\r\n    }\r\n}\r\n<\/code><\/pre>\r\n<\/div>\r\n<p>Store your certificates in \/usr\/local\/etc\/nginx\/certs, then restart nginx.<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># service restart nginx<\/code><\/pre>\r\n<\/div>\r\n<p><span>Call the IP of the nginx host with illegal characters to simulate a illegal request.<\/span><\/p>\r\n<p>http:\/\/127.0.0.1\/?a=%3C<\/p>\r\n<p>Check the logfile<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># cat \/var\/log\/nginx\/error.log\r\n2022\/01\/06 18:48:25 [error] 8404#0:*3 NAXSI_FMT: ip=127.0.0.1&amp;server=127.0.0.1&amp;uri=\/&amp;learning=0&amp;vers=0.50&amp;total_processed=3&amp;total_blocked=1&amp;zone0=ARGS&amp;id0=1302&amp;var_name0=a, client: 127.0.0.1, server: , request: \"GET \/?a=&lt; HTTP\/1.0\", host: \"127.0.0.1\"<\/code><\/pre>\r\n<\/div>\r\n<p>Hint: In case you want to have additional features options compieled, simply execute:<\/p>\r\n<div class=\"hcb_wrap\">\r\n<pre class=\"prism undefined-numbers lang-bash\" data-lang=\"Bash\"><code># cd \/usr\/ports\/www\/nginx-naxsi\/work\/nginx-1.18.0\r\n# .\/configure\r\n-- a text ui pops up, select from here what you need to have.\r\n# make\r\n# make install<\/code><\/pre>\r\n<\/div>\r\n<p>&nbsp;<\/p>\r\n","protected":false},"excerpt":{"rendered":"<p>Naxsi &#8220;Nginx Anti XSS &amp; SQL Injection&#8221; is a free, open-source and high-performance web application firewall that can be used to protect your webserver against different types of attacks like [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":1562,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"How to install and configure nginx-naxsi web application firewall on FreeBSD13","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[163],"tags":[69,56,165,164,169,168,166,167],"class_list":["post-1524","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-freebsd","tag-firewall","tag-freebsd","tag-naxsi","tag-nginx","tag-proxy","tag-reverse","tag-waf","tag-web-application-firewall"],"jetpack_publicize_connections":[],"jetpack_featured_media_url":"https:\/\/i0.wp.com\/www.web-workers.ch\/wp-content\/uploads\/2022\/01\/nginx-naxsi1.png?fit=2240%2C1138&ssl=1","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p8sxjX-oA","jetpack-related-posts":[],"jetpack_likes_enabled":true,"_links":{"self":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1524","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/comments?post=1524"}],"version-history":[{"count":38,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1524\/revisions"}],"predecessor-version":[{"id":1566,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/posts\/1524\/revisions\/1566"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media\/1562"}],"wp:attachment":[{"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/media?parent=1524"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/categories?post=1524"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.web-workers.ch\/index.php\/wp-json\/wp\/v2\/tags?post=1524"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}