Hey and welcome to this blog post by me, my name is Michael Pedersen I am 34 years old and I love open source and security stuff. In August of 2019 I started my journey into the danish InfoSec community and along the way I came across Security Distractions because they too love open source and security! Now one year later I have been invited to join the blog and I am very pleased to be able to publish this first post and hopefully have many more to come. So again – Welcome 🙂
On many of my projects I often need a firewall to segment networks, apply different rules, intercept traffic etc. For this I alway use pfSense, because it’s easy to setup, has a ton of functionality, is very well documented and of course free and opensource, which we like.
But unfortunately this is not a blog post about pfSense and how awesome and fun it is to play around with. Actually, this is more of a fusion of different sources that I have put together, to solve a problem I was facing – so let us get started.
For one of my projects I was going to intercept traffic from a client network using pfSense and the squid proxy service and have all traffic written to the squid access log. The second step was then to ship the logs into an Elasticsearch instance and the best way to do this is using Elastic Beats, in this case Filebeat. This is where the challenge awaited.
As you probably know, pfSense is running on FreeBSD and as of the moment, the package manager does not provide any easy install of Elastic components. I searched the internet for a while, not having much luck until I fell over this blog post written by a Swedish pentester called Christoffer Claesson. It seemed he had found an answer to this within an ongoing github issue, but felt that it was to good not to have on its own blog – I totally agree. The original idea was posted by another guy called jakommo which you can read here.
Now, jakommos idea was straight forward. Simply download the github repository and build the beat you wanted yourself. Hell, why did I not think of that! Christoffers and jakommo already has some of the steps covered, but I would like to follow up on them and add a few things.
There is a few prerequisites that you need to get up and running before you start.
- Get a fresh FreeBSD machine up and running, preferably the same versions as your pfSense box.
- Make sure you can reach your FreeBSD box via SSH. You might need to edit the /etc/ssh/sshd_config and allow root login (not best practice – I know)
The following steps updates the pkg repository and installs the tools needed to be able to clone the filebeat repository and built it from source. This will furthermore install a bunch of dependencioes, which is why this is done on a separate BSD machine to avoid polluting the pfSense box.
root@freebsd:~ # pkg update -f root@freebsd:~ # pkg install git gmake go bash root@freebsd:~ # git clone https://github.com/elastic/beats.git root@freebsd:~ # cd beats/filebeat/ root@freebsd:~/beats/filebeat/ # gmake
When the process is done, you should now be able to do this:
Now step back one dir, and create an archive of the filebeat folder.
root@freebsd:~/beats/filebeat/ # cd .. root@freebsd:~ # tar -czvf filebeat.tar.gz ./filebeat/
This concludes the work with our temporary FreeBSD box, now we have to copy the archive out to our local machine so we can get it to our pfSense box. You can do this any way you like, I prefer to use secure copy from my local machine:
Next up, we need to upload our filebeat archive to our pfSense box. This can be done the same way, or you can use the WebUI like this:
All right, we are almost there. Log into your pfSense box using the console or SSH. If you used the WebUI to upload the archive, you will find the file in the /tmp/ folder. Now you can move it to wherever you want on pfSense and extract the archive. For this tutorial I simply stayed inside the /tmp/ dir.
And there you have it. All you have to do now is configure the filebeat to fit your needs and type ./filebeat.
Caveats… Always with the caveats…
- This has only been tried in a virtual environment but I can’t see why this should not work on hardware as well.
- When you start filebeat it will run in the foreground of the shell you are using. I will try to do a post on how to get it running as a service instead.
- I have tried this with Filebeat 7.8 and the master branch (8.0 as of this writing).
Outro… (you still listening?)
Lastly, I want to give a shout out to my friend David Thejl-Clayton and his custom squid log format that you can find in our github repo here. David has spent a great deal of time to define a custom log format optimized with all relevant fields critical for detection and analyzing of proxy alerts.
Cheers – Michael