First thing first, You need to keep your Windows Operating System/Server version always up to date. Always install Microsoft's updates/Recent updates. Plus, You need to use a good Antivirus/total protection or firewall system security whatever you call.
Regarding the Ransomware attack prevention, Check below posted link.
https://support.microsoft.com/en-us/help/2696547/how-to-enable-and-disable-smbv1-smbv2-and-smbv3-in-windows-and-windows-server
Source - Microsoft.com
Let us know if you have any inquiries or questions regarding this topic.