Reader small image

You're reading from  OPNsense Beginner to Professional

Product typeBook
Published inJun 2022
PublisherPackt
ISBN-139781801816878
Edition1st Edition
Right arrow
Author (1)
Julio Cesar Bueno de Camargo
Julio Cesar Bueno de Camargo
author image
Julio Cesar Bueno de Camargo

Julio Cesar Camargo is a cybersecurity professional with +15 years of experience working with open-source software. He started with Conectiva Linux and later became the official instructor helping dozens of students. As an aviation enthusiast and airplane pilot, he strives to bring all the aviation best practices to his professional routine. Julio started working with OPNsense in 2016, contributing to the project with code, official forum moderation, articles, Udemy course, and promotions in Europe. He founded Cloudfence in 2018, a cybersecurity startup and a Luso-Brazilian-managed security services firm with an open-source DNA. As its CTO, Julio aims to spread open source security as a service to companies from different parts of the world.
Read more about Julio Cesar Bueno de Camargo

Right arrow

Chapter 18: Website Protection with OPNsense

With the NGINX plugin, OPNsense becomes a full-featured, solid Web Application Firewall (WAF). It can help you to protect your network and your web servers with the addition of the NGINX plugin. By the end of this chapter, you will be able to use OPNsense as a reverse proxy, WAF, and web server load balancer.

In this chapter, we will explore the following topics:

  • Publishing websites to the world
  • About the NGINX plugin
  • Installing and configuring
  • Adding WAF rules
  • Troubleshooting

Technical requirements

This chapter requires a clear understanding of how a web server works. Complete knowledge of DNS HTTP(S) and TLS protocols is also essential.

Publishing websites to the world

Nowadays, our modern internet is, essentially, based on web applications. It is rare to see a modern app that is built to run installed on a computer, and even the smartphone-based apps are, for the most part, a responsive version of the website. While managing an OPNsense firewall, you will probably have to deal with websites and web applications. As a modern next-generation firewall solution, OPNsense can provide enough features to keep a website safely online, protecting it against threats. In the following sections, we will explore the NGINX plugin, which does an outstanding job while publishing web server applications and websites protected by OPNsense.

About the NGINX plugin

In the old days, a firewall was just a packet filtering system, and to publish a web server service to the internet, simply adding a NAT rule was enough. With the evolution of the internet, more sophisticated web applications were raised, but the attacks followed at the same pace, becoming more harmful. Good firewall solutions added features such as IDS and IPS to increase the protection level of applications and the users behind them. Still, web applications require more detailed filters to protect them against the threats of bad actors than packet filtering and a network IPS.

A solution to help web servers and applications become better protected emerged: HTTP reverse proxies. Similar to a web proxy, the reverse proxy stands between the users and the web servers, but in reverse, that is, the users are outside the local network and the web servers are inside.

The following diagram illustrates how a reverse proxy works:

Figure 18...

Installing and configuring the NGINX plugin

To install the NGINX plugin, follow these steps:

  1. Go to the System | Firmware | Plugins tab:

Figure 18.2 – Adding the NGINX plugin

  1. To add the plugin, find it and click on the + button.

Before enabling the NGINX service, we need to adjust the webGUI configuration to avoid any port conflict between NGINX and the Lighttpd (the process that serves the webGUI).

  1. To change the webGUI connection port, go to System | Settings | Administration.
  2. Change the TCP port option from 443 to another port such as 8443, for example.
  3. Check the HTTP Redirect Disable web GUI redirect rule option. This will free TCP port 80 (HTTP):
Figure 18.3 – The webGUI configurations details

Figure 18.3 – The webGUI configurations details

Note

The following steps will change the ports of the webGUI. Ensure that you have the firewall rules to allow access from the webGUI to the new TCP port configuration before...

Adding WAF rules

The NGINX plugin implements a WAF with the help of the NAXSI (NGINX Anti XSS & SQL Injection) module. This module works with predefined rules that match 99% of known patterns found in website vulnerabilities. The NAXSI module was created and maintained by NBS System, a French security company (ref: https://www.nbs-system.com/):

  1. To add the NAXSI rules to the NGINX plugin, go to the HTTP(S) menu, followed by the Naxsi WAF Policy submenu. When the rules haven't been installed, the following button will be visible:
Figure 18.15 – The NAXSI download rules button

Figure 18.15 – The NAXSI download rules button

  1. Click on the Download button to install the rules. You will be prompted with a dialog box about the NAXSI rules licensing. You must click on the Accept and Download button to agree with the license terms (the GPLv3 license):

Figure 18.16 – The NAXSI license terms dialog

After it has been downloaded, the rules will...

Troubleshooting

As a complex system, a reverse proxy or a WAF can lead you to troubleshooting scenarios that require a lot of logs reading along with some web server and application knowledge. Here, we will explore a few tools that might help you to solve a quest.

Testing for configuration issues

Sometimes, even with all of the help and automations that the webGUI plugin frontend has, some configuration issues could appear, making the NGINX service unable to start. To test the NGINX configuration, you can log in to the OPNsense CLI and run the following command:

root@OPNsense-1:~ # nginx -t
nginx: the configuration file /usr/local/etc/nginx/nginx.conf syntax is ok
nginx: configuration file /usr/local/etc/nginx/nginx.conf test is successful

For a more complete testing and configuration output, you can also run nginx -t.

Logs reading

In the webGUI, we find the NGINX | Logs menu. Inside this page, it is possible to check every created HTTP server log file and the NGINX...

Summary

At this point, you can affirm that OPNsense has a robust security stack and can even act as a WAF in the frontline of a cloud or network infrastructure. This chapter taught you how to install and configure the NGINX plugin, and you also learned how to enable its WAF features and protect the infrastructure of web servers. In the following chapter, we will jump into the CLI world and see how it can extend your tools and knowledge by executing commands in OPNsense.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
OPNsense Beginner to Professional
Published in: Jun 2022Publisher: PacktISBN-13: 9781801816878
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Julio Cesar Bueno de Camargo

Julio Cesar Camargo is a cybersecurity professional with +15 years of experience working with open-source software. He started with Conectiva Linux and later became the official instructor helping dozens of students. As an aviation enthusiast and airplane pilot, he strives to bring all the aviation best practices to his professional routine. Julio started working with OPNsense in 2016, contributing to the project with code, official forum moderation, articles, Udemy course, and promotions in Europe. He founded Cloudfence in 2018, a cybersecurity startup and a Luso-Brazilian-managed security services firm with an open-source DNA. As its CTO, Julio aims to spread open source security as a service to companies from different parts of the world.
Read more about Julio Cesar Bueno de Camargo