Is it permissible to resort to magic for doing good things and defeating Satan through written symbols and words for protection (hirz) or talismans, for example, by writing on a mug and drinking water from it with the intention of healing, or writing on paper to carry all the time? Is it permissible to harness the jinn in this case?
It is prohibited to learn, teach, use, and gain from magic in all its forms, even when used to stop [other] magic, unless it is [absolutely] necessary for a matter of greater benefit such as saving the life of a respected person who is under the influence of magic. As for harnessing jinn, it is prohibited if it harms a person who must not be harmed.