It was running OS version v6.37.1 and current firmware was 3.29.
...
How did this happend?
...
However, keep in mind i had a strong password.
A number of vulnerabilities, including ones allowing to break in without knowing the password, has been fixed since 6.37.1, so this is the most likely reason - along with firewall rules which did not block access to management services from the internet.
A less likely possibility is cross-platform malware, which you might have downloaded to your PC from an infected web page, which has attacked your router from the LAN side, and may even have keylogged the password as you were typing it in.
And what can i do to prevent this from ever happening again?
Now export (
not backup) the current configuration into a file, download the file to your PC, and then netinstall the router with the long-term version of RouterOS. Use the default configuration of that version and only modify it with what is really necessary - your saved export will help you with that.
Do not import the file with the export as a whole, just use it as an information source.
The only way how to keep the router secure against attacks from LAN is to manage it only via serial port or to dedicate an Ethernet interface for management, and disable access to management services also from the "regular LAN".