Is it permissible to learn magic and charm in order to abrogate and inactivate it or to use it in legitimate ways, for instance striking the enemies of Islam?
As if, fire is not extinguished by fire, magic will not be abrogated by magic, but it will be abrogated by praying in presence of God and recitation of His verses; as He has said: ﴿قَالَ مُوسَىٰ مَا جِئْتُمْ بِهِ السِّحْرُ ۖ إِنَّ اللَّهَ سَيُبْطِلُهُ ۖ﴾; “Moses said: What you have brought is magic, indeed God will nullify it”. However, what strikes the enemies of Islam is not magic, rather is implementing Islam, and with this description magic is absolutely not permissible, however knowing its methods in order to prevent or distinguish it from miracle, in case of necessity, has no problem; as God has said about Harut and Marut: ﴿وَمَا يُعَلِّمَانِ مِنْ أَحَدٍ حَتَّىٰ يَقُولَا إِنَّمَا نَحْنُ فِتْنَةٌ فَلَا تَكْفُرْ ۖ﴾; “And they would not teach (the magic) to anyone except when they said: We are only a trial, so do not become disbeliever”; meaning do not use what you are learning; as if communicating with the devils is not permissible for anyone other than the Caliph of God on earth; as God has said about Solomon peace be upon him: ﴿وَمِنَ الْجِنِّ مَنْ يَعْمَلُ بَيْنَ يَدَيْهِ بِإِذْنِ رَبِّهِ ۖ﴾; “And among the jinn were those who worked for him by the permission of his Lord” and their uncovering to the friends of God is not regarded as communicating with them; as one of our companions informed us and said:
«ذُکِرَ عِنْدَ ٱلْمَنْصُورِ فُلانٌ، فَقالَ: أَدْرَکْتُ شَیْطانَهُ بِمُلْتَقَی ٱلطَّریقَیْنِ فَأَرَدْتُ أَنْ أَقْتُلَهُ فَهَرَبَ مِنِّي! أَلا وَاللّهِ لَو قَتَلْتُهُ لَٱرْتاحَ ٱلرَّجُلُ کَأَنَّما نَشِطَ مِنْ عِقالٍ! قُلْتُ: أَلَهُ شَیْطانٌ جُعِلْتُ فِداکَ؟ قالَ: نَعَمْ وَ یُقالُ لَهُ ٱلْمَتْکُونُ یَأتیهِ بِکُلِّ صُورَةٍ فَیُغْوِیهِ إِلّا أَنَّهُ لا یَأتِیهِ بِصُورَةِ ٱلْمَهْدِيِّ»; “In the presence of Mansoor, a person (one of the false claimants) got mentioned, then he said: I found his devil at a fork, so I wanted to kill him, then he ran away from me! I swear to God, if I had killed him, the man would have been relieved as if he had been released from chains! I asked: may I be your sacrifice, is there a devil for him? He said: yes, and his name is Matkun, he comes to him with every face, so he deceives him, except he does not come to him with the face of Mahdi”!