I don’t think it’s “legal” to declare war on an organization, either. That’s why we invaded Afghanistan instead of invading al-Qaida. Get real.
In deference to your ignorance…. It’s legal.
Perhaps you’ve heard of the Barbary Pirates.
Get real.