That would work
How hard is it to mount those?
Technically not hard at all. Legally virtually impossible. After all if people were allowed to mount guns on their ships we might have piracy. (Oh we already do. I guess gun control on the ocean doesn't work any better than gun control in Wash DC.)
On top of which, any history of piracy points out that pirates can't function without a safe port to hide in and sell booty. That means corrupt port officials, and a corrupt government getting it's share of the swag.