Is it permissible to learn magic to defend Islam?
It is not permissible to learn any form of Taweezaat (amulets worn for protection from evils) or magic that involves uttering words or performing such actions that would cause one to come out of the fold of Islam. However, it would be permissible to use that which does not involve such words or actions to defend Islam if there is no other effective way for fulfilling this purpose.
And Allah knows best.
فی الشامیۃ: وللسحر فصول کثیرۃ فی کتبہم، فلیس کل مایسمی سحرًا کفرًا، إذ لیس التکفیر بہ لما یترتیب علیہ من الضرر بل لما یقع بہ مما ہو کفر کاعتقاد انفراد الکواکب بالربوبیۃ أو إہانۃ قرآن أو کلام مکفر ونحو ذالک. اھ (۱/ ۴۵) واللہ اعلم.