In regard to the nature of Jinns, the Quran says: “and we created the jinn earlier out of a piercing fire.” Therefore, jinns do exist and they also have prophets like man does. They are obligated to worship God and have Muslims and disbelievers depending on their beliefs and actions. Satan, who did not prostrate to Adam, is also amongst the jinns.
Harming with God’s permission!
Because all powers in the world have been granted by God, therefore, it is possible to say that if one harms others, it is through God’s power. Even when fire burns or a knife cuts it is with His permission. Similarly, a magician cannot oppose God’s will but God has given them the power to corrupt as a means of testing them, and this does not mean he is pleased with their corruption.
Jinns: truth or myth?
The creatures that you referred to in your question are named jinns in the Quran. Satan was also a jinn. Literally, the word “jinn” refers to anything that is hidden and cannot be seen. In regard to the nature and creation of jinns, the Quran says: “and We created the jinn earlier out of a piercing fire.” Therefore, jinns do exist and they have prophets like man does. They are obligated to worship God and have Muslims and disbelievers depending on their beliefs and actions. Satan, who did not prostrate to Adam, is also among the jinns.
Yes, sometimes people speak of frightening creatures that do not really exist, but the verses and ahadith that speak of jinns all show that this creature truly does exist.
According to verse 102 of surah Baqarah, the Jews would use black magic and sorcery, obtaining these powers from two sources:
1- The devils that existed at the time of Prophet Solomon and would teach people magic so people could cause corruption using it.
2- Two angels that had descended to earth and would teach people how to undo curses.
In this verse God has spoken of two angels (not jinns) with the names of Harut and Marut that would teach people magic due to certain compelling reasons. However, the people would learn certain things from them by which they could create dispute and division between a man and his wife.
Therefore, first: people did not learn magic from the jinns, instead they learned it from the angels. Second: The Quran does not say that the angels taught the people such evil methods, but rather it was the people that would learn how to do what they did from them.
As you know, there is a great difference between the two. Sometimes a teacher teaches his student something to use to solve his scientific problems, but the student misuses that method due to his evil intentions. The knowledge and science of making bombs and other weapons are an example of such misuse. It was man that misused these sciences, instead of using them for further development and progress.
When we observe the Sha’n Nuzul (occasion of revelation) of the verse, we can clearly find such a meaning. The Sha’n Nuzul says: “These two angels would teach people magic so that they could undo the curses of the magicians, and would warn people that they were being tested with the magic and that they should be careful not to go astray and misuse this knowledge.”
For further information about the Sha’n Nuzul of this verse and about the story of Harut and Marut, you can refer to: Question 4960 (website: 5247).
The answer to the problem of “Harming with God’s permission”
When we observe the meaning of the verse, it is trying to answer a question that might come up: One could assume, on hearing that the sorcerers caused separation between a husband and his wife, that the sorcerers were powerful enough to disturb the divinely ordained arrangement of the world; that they could undo divine decree and change the system created by Allah. This statement clears things up and emphasizes that sorcery draws its strength from divine decree; it cannot affect anything but with the permission of Allah. Therefore, the sorcerers act within the framework of the system designed by Allah.
This part of the verse is referring to one the fundamental principles of Tawhid, that all powers in this world come from God’s power, even when fire burns or a sword cuts. No magician can oppose God’s will in this world or can limit God’s power and control. The power a magician has is a power that he has been given by God. Some make good use of this power while others misuse it, and this freedom is a means of testing people.
The fact that the effect of each and every thing is in God’s hands does not mean that He is pleased with people performing magic and harming others, rather it means that magic is a way of using the rules that God has placed for this world. For example, the sharpness of a knife and how it cuts softer things is one of these rules, and through this law people benefit a lot. Now, if an innocent person is killed with a knife, the killer has misused the rules and laws of this world which have been set by God. Therefore, one may say that the killer did so with God’s permission, but that does not mean God is pleased with this crime or that He gave the killer permission to do so. Instead God has clearly warned killers from committing crimes and violating people’s rights and promised them severe punishment.
1- Question 4960 (site: 5247) (Harut and Marut)
2- Question 2992 (site: 3237) (Attributing evil to God)
 Mo’in, Mohammad, Farhange Mo’in, pg. 457, Behzad Publications, Tehran, 1386.
 Raghib Isfahani, Al-Mufradat fi Gharib al-Quran, vol. 1, pg. 203.
 Ana’am, 130: "O company of jinn and humans! Did there not come to you apostles from yourselves, recounting to you my signs and warning you of the encounter of this Day?" They will say," We testify against ourselves." The life of this world had deceived them, and they will testify against themselves that they had been faithless.
 Ahghaf, 29: This verse refers to a group of the jinns becoming Muslims. There are many verses that speak of jinns that are disbelievers.
 Kahf, 50: “When we said to the angels," Prostrate before Adam," they prostrated, but not Iblis. He was one of the jinn, so he transgressed against his Lord's command.”
 Learning magic in order to undo curses and go against magicians is permissible.
 عن الرضا(ع):وَ أَمَّا هَارُوتُ وَ مَارُوتُ فَکَانَا مَلَکَیْنِ عَلَّمَا النَّاسَ السِّحْرَ لِیَحْتَرِزُوا بِهِ سِحْرَ السَّحَرَةِ وَ یُبْطِلُوا بِهِ کَیْدَهُم
 The precise meaning of the verse is: “And they followed what the devils pursued during Solomon's reign and Solomon did not turn faithless, but it was the devils who were faithless teaching the people magic, and what was sent down to the two angels at Babylon, Harout and Marout, and they would not teach anyone without telling] him [," We are only a test, so do not be faithless." But they would learn from those two that with which they would cause a split between man and his wife though they could not harm anyone with it except with Allah's leave. And they would learn that which would harm them and bring them no benefit; though they certainly knew that anyone who buys it has no share in the Hereafter. Surely, evil is that for which they sold their souls; had they known!)”
 With help from Tafsir al-Mizan, vol. 1, pg. 355.
 Makarem Shirazi, Tafsir Nemouneh, vol. 1, pg. 377.
 God says in the Quran: “Do not kill a soul [whose life] Allah has made inviolable, except with due cause, and whoever is killed wrongfully, we have certainly given his heir an authority. But let him not commit any excess in killing, for he enjoys the support [of law]” Isra, 33.