Al-Qaeda in the Islamic Maghreb has reaped millions by ransoming Western citizens, taxing locals and trading in drugs.