Is it permissible to learn magic in order to counteract it or to use it for a legitimate purpose, such as harming the enemies of Islam?
Magic is not nullified by magic; rather, it is nullified by the remembrance of Allah, His supplications, and the recitation of His verses. Just as fire is not extinguished by fire but by water, and Musa did not attempt to nullify magic with similar magic. Instead, he sought refuge in Allah, and Allah nullified it with His sign; as He has said: ﴿مَا جِئْتُمْ بِهِ السِّحْرُ ۖ إِنَّ اللَّهَ سَيُبْطِلُهُ﴾[1]; “What you have brought is magic. Indeed, Allah will nullify it,” and it is narrated from Jabir ibn Abdullah and Anas ibn Malik that they said: «سُئِلَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَآلِهِ وَسَلَّمَ عَنِ النُّشْرَةِ، فَقَالَ: هُوَ مِنْ عَمَلِ الشَّيْطَانِ»[2]; “The Messenger of Allah
was asked about nushrah, and he said: ‘It is from the work of Satan.’” The term nushrah refers to the practice of counteracting magic with magic, and for this reason Al-Hasan has said: «لَا يَحُلُّ السِّحْرَ إِلَّا سَاحِرٌ»[3]; “Magic is undone (by magic) only by a magician.” As for nullifying magic through the remembrance of Allah, His supplications, and the recitation of His verses, this is certainly permissible. Based on this understanding, the narration from Ja‘far ibn Muhammad is interpreted, who said to Isa ibn Shaqafi: «حُلَّ، وَلَا تَعْقِدْ»[4]; “Undo it, but do not bind it,” if the narration is authentic. There is no doubt that the greatest harm to the enemies of Islam comes from following the rulings of Islam, not from abandoning them. Therefore, magic is not permissible in any form, contrary to the claims of the disbelievers. As they consider two types of magic: “black magic” and “white magic,” and they say that “white magic” is permissible, while this is a false claim against Allah. Even some people among them assert that Sulayman
practiced white magic; while Allah refuted them in His Book, saying: ﴿وَمَا كَفَرَ سُلَيْمَانُ وَلَكِنَّ الشَّيَاطِينَ كَفَرُوا يُعَلِّمُونَ النَّاسَ السِّحْرَ﴾[5]; “And Sulayman did not disbelieve, but the devils disbelieved, teaching people magic.” Thus, He has considered magic as disbelief.
Yes, there is no harm in learning about its types and causes in order to prevent it or to distinguish it from miracles when necessary, because what is forbidden is only its practice. As Allah, the Exalted, mentioned regarding the two angels in Babylon, Harut and Marut: ﴿وَمَا يُعَلِّمَانِ مِنْ أَحَدٍ حَتَّى يَقُولَا إِنَّمَا نَحْنُ فِتْنَةٌ فَلَا تَكْفُرْ﴾[6]; “But they do not teach anyone unless they say: ‘We are only a trial, so do not disbelieve.’” That is, do not use what you have learned of magic, for doing so is disbelief; as it has been narrated from the Ahl al-Bayt in the interpretation of this verse: «إِنَّ هَارُوتَ وَمَارُوتَ كَانَا مَلَكَيْنِ عَلَّمَا النَّاسَ السِّحْرَ لِيَحْتَرِزُوا عَنْ سِحْرِ السَّحَرَةِ وَيُبْطِلُوا بِهِ كَيْدَهُمْ، وَمَا عَلَّمَا أَحَدًا مِنْ ذَلِكَ شَيْئًا إِلَّا قَالَا لَهُ: ﴿إِنَّمَا نَحْنُ فِتَنُهُ فَلَا تَكْفُرْ﴾، فَكَفَرَ قَوْمٌ بِاسْتِعْمَالِهِمْ لِمَا أُمِرُوا بِالْإِحْتِرَازِ مِنْهُ»[7]; “Harut and Marut were two angels who taught people magic so that they could guard themselves against the magic of magicians and invalidate their schemes, and they did not teach anyone anything without first saying to them: ‘We are only a trial, so do not disbelieve.’ But some people disbelieved by using what they were commanded to avoid,” and in another narration: «كَانَ بَعْدَ نُوحٍ عَلَيْهِ السَّلَامُ قَدْ كَثُرَ السَّحَرَةُ وَالْمُمَوِّهُونَ، فَبَعَثَ اللَّهُ عَزَّ وَجَلَّ مَلَكَيْنِ إِلَى نَبِيِّ ذَلِكَ الزَّمَانِ بِذِكْرِ مَا تَسْحَرُ بِهِ السَّحَرَةُ، وَذِكْرِ مَا يُبْطَلُ بِهِ سِحْرُهُمْ وَيُرَدُّ بِهِ كَيْدُهُمْ، فَتَلَقَّاهُ النَّبِيُّ عَنِ الْمَلَكَيْنِ، وَأَدَّاهُ إِلَى عِبَادِ اللَّهِ بِأَمْرِ اللَّهِ عَزَّ وَجَلَّ، فَأَمَرَهُمْ أَنْ يَقِفُوا بِهِ عَلَى السِّحْرِ، وَنَهَاهُمْ أَنْ يَسْحَرُوا بِهِ النَّاسَ، وَهَذَا كَمَا يَدُلُّ عَلَى السُّمِّ مَا هُوَ، وَعَلَى مَا يُدْفَعُ بِهِ غَائِلَةُ السُّمِّ»[8]; “After Noah , magicians and deceivers became numerous, so Allah, the Almighty, sent two angels to the prophet of that time with knowledge of the magic used by the magicians, and the knowledge of what could invalidate their magic and counter their schemes. The prophet learned this from the angels and conveyed it to the servants of Allah by the command of Allah, the Almighty. He instructed them to understand magic but forbade them from using it against people. This is similar to understanding poison, what it is, and what can be used to counteract its harm.”