I thought that it was illegal to trade with them because they posed a threat to national security.
Do you have a particular region or group that you had in mind? I don't think it would be possible to generalize how, say, the IRA got its weapons versus how, say, Hezbollah got its weapons. This also, of course, changes by time period. Certain kinds of groups found it much easier to get weapons during the cold war than they did before and after that period, for instance.
Hi OP, just a reminder that this subreddit has a 20-year rule against discussing current affairs. So if you're asking about current terrorist group activities, you will not get an answer here.