Recently we performed a non-profit penetration test of OPNsense - an open source, FreeBSD based firewall and routing platform with ~51.47K active instances according to censys.io. The assessment was focused on web GUI and API as well as some parts of the system backend. Work has been carried out in a period from June 12 to June 26, 2023. In total, around 120 hours were committed to the project.
During the test we managed to find many interesting and varied vulnerabilities, e.g., Cross-Site Scripting, Cross-Site Request Forgery, Open Redirect, Insecure Permissions, OS Command Injection and Zip-Slip which eventually leads to root shell. You can find all of them in the Full PDF Report which is also a great example of what our commercial clients receive.
We would like to show you three scenarios of how vulnerabilities that we found could be chained together to perform attacks on the OPNsense instance.
Scenario 1 - Reflected XSS leads to root RCE via Zip-Slip
In this scenario we used Reflected Cross-Site Scripting vulnerability (LT-0017) to deliver our payload to the administrator.
Sending GET request to https://opnsense/ui/cron/item/open/0'+alert(window.origin)+' would result in the following response:
After an administrator clicks on our link, we need to send six requests from their browser. First two requests create new Captive Portal template, another three enable Captive Portal with the selected template, and the last one spawns netcat reverse shell with our brand-new luta.php webshell.
Above script can be base64 encoded and put inside the URL:
What’s interesting is that the application accepts templates in ZIP format, and then it extracts all of their contents to the template directory. However, the way in which the application extracts the files makes it vulnerable to the Zip-Slip attack (LT-0014):
By using ../ sequences it is possible to extract files to other directories. This allows us to extract PHP file to the web root - /usr/local/www.
Our ZIP archive looks like this, where luta.php is a simple PHP web shell:
Since the PHP process is being ran as a root user, the shell is granted root privileges as well.
Proof of Concept Video:
Scenario 2 - Reflected XSS -> OS Command Injection -> root password retrieval via config.xml insecure permissions
In the second scenario the payload is also delivered through Reflected XSS, but this time the vulnerability is introduced in Certificates tab (LT-0002). Sending request to https://opnsense/system_certmanager.php?act=%22%3E%3Csvg/onload=alert(window.origin)%3E&id=0 results in the following response body:
We want to send request to /api/cron/settings/addJob/ in order to add new cron job. The application allows only specific commands to be executed via cron, however, by including single quotes (') and newline character (\n) in the command parameters, we can define completely separate cron job and execute any command as nobody user (LT-0016).
…and turned into an URL:
After the administrator opens the link, we can see our command added to the crontab:
In the above payload we are adding next vulnerability to the chain - even though we only have privileges of user nobody, insecure permissions (LT-0003) grant us read access to the configuration file:
Soon config.xml is sent to our listener:
Congratulations, it’s a bcrypt hash of a root password!
Finally, we feed it to hashcat:
Scenario 3 - CSRF that halts the firewall
This one is quite straightforward. Administrator visits our website, from which we redirect them to https://opnsense/api/core/system/halt, to turn off the instance.
Normally, this request is made using POST method and requires CSRF token, but during the test it turned out that the app accepts GET request as well, and in such case doesn’t require CSRF token.
As a result, the OPNsense instance turns off.
Proof of Concept Video:
We reported found vulnerabilities to OPNsense maintainers and we really want to thank them for a great response. They handled the whole process very professionally, quickly prepared effective patches for many vulnerabilities and included them in the newest releases - OPNsense 23.7 “Restless Roadrunner” as well as business edition 23.4.2. Also, they provided us with reasoning behind decision not to patch some of them right now.
We are very happy about the outcome of the tests and can’t wait to start another project like this soon. Stay tuned!
According to art. 13 of the General Regulation on the Protection of Personal Data of 27 April 2016 (Official Journal EU L 119 of 04.05.2016) I inform that:
1) the administrator of your personal data is Logicaltrust Sp. z o.o. Sp. k. - al. Aleksandra Brücknera 25-43, 51-411 Wrocław,
2) contact with the Personal Data Administrator - firstname.lastname@example.org,
3) Your personal data will be processed for marketing purposes on the basis of Art. 6(1)(a) of the general regulation on the protection of personal data of April 27, 2016..
4) Your personal data will be stored until you withdraw your consent
5) You have the right to request from the administrator access to personal data, the right to rectify their removal or limit processing, the right to withdraw consent and the right to transfer data
6) You have the right to lodge a complaint with the supervisory authority
7) Your data will be processed in an automated manner, including in the form of profiling. Automated decision-making will take place on the principles set out in the regulations (options: subscription, competition, etc.) and the consequence of such processing will be receiving selected marketing information
8) providing personal data is voluntary, however failure to provide data may result in the inability to participate in the newsletter subscription, participate in contests, receive marketing offers, participate in surveys
At the same time, pursuant to Art.6(1)(a) of the general regulation on the protection of personal data of 27 April 2016, I agree to the processing of my personal data for the purpose of subscribing to the newsletter, participation in competitions, receiving marketing offers, participation in surveys
1. About cookies - Cookies are small data files, especially text files, which are stored by a server on your computer. With these files, your device will be recognized and, in consequence, the way a given website is presented will be adjusted to your personal preferences. Cookies usually contain the name of the website from which they originate, information on how long they have been stored on the device and a unique number.
2. Which type of cookies do we use - Session cookies – temporary files which are stored on your device until you log out from a given website or close the Internet browser. Persistent cookies – permanent files that remain on your device for a fixed period (specified in the parameters of the file) or until they are deleted manually. Third-party cookies – files that adjust the way a given website is presented to your personal preferences.