The short answer is YES, you can you get a virus on iOS 12 beta. Viruses and all forms are malware are possible on any and all platforms. Every single version of every single OS built in the past, present, or future CAN be affected by malware. That being said, iOS 12 beta is not any more susceptible to the possibility than any other release, and in fact is likely the least susceptible iOS version.
As some other members have pointed out, there are some considerations you should think about before installing any update, beta versions especially:
1) Always have a backup. Assume you will lose everything. Those without backups frequently do lose data and those with backups virtually never do. It is best to have BOTH an iCloud backup and an iTunes backup stored locally on a computer.
2) Consider your usage. If you depend on your device for income, safety, well-being, or even basic day to day functioning, then DO NOT update to a beta release. Apple recommends installing beta software on secondary devices only that you do not depend on functioning day-to-day. In some cases that are particularly important (for example a device that is being used for emergency response notifications) it would be wise to consider foregoing even public release updates.
3) Consider your technical skills. This includes the ability to troubleshoot problems, restore your device, create and restore backups, and provide useful feedback regarding bugs. If you are not 100% confident in these skills, DO NOT install a beta software version. When running on beta software, you will not be able to get software (and in some cases hardware) related service or support from Apple.