“Resh Laqish said, ‘… If one comes to defile himself, he is provided an opening; if one comes to purify himself, he is assisted” (BT Shabbat 104a).
“Come and see: In the middle of the sky, a lustrous path is woven—Celestial Serpent—all gossamer stars clustered with mounds upon mounds, encharged with requiting the deeds of inhabitants of the world. Similarly, numerous bands of dazzling demons issue from this supernal, primordial serpent—by whom Adam was seduced—and they are all encharged with requiting deeds of the world.
So if a person comes to purify himself, he is assisted from above; his Lord’s assistance encircles him, and he is protected, called ‘holy.’ If a person comes to defile himself, numerous bands of dazzling demons lie in wait for him; they all hover over him, surrounding him, defiling him, and he is called ‘impure.’ They all go in front of him, proclaiming, ‘Impure! Impure!—as is said: He shall call out, ‘Impure! Impure!’ (Leviticus 13:45). All of them are linked with that primordial serpent, requiting countless deeds of the world.
Rabbi Yitsḥaq and Rabbi Yose were walking from Tiberias to Lydda. Rabbi Yitsḥaq said, ‘I am amazed at that wicked Balaam, all of whose actions stemmed from the side of impurity! Here we learn a mystery: All species of נְחָשַׁיָּא (neḥshayya), sorcery, throughout the world are linked with, and issue from, that primordial נָחָשׁ (naḥash), serpent—slimy spirit of impurity. So all witchcraft of the world is named accordingly: נְחָשִׁים (neḥashim), serpentine sorcery, all issuing from this side. Whoever is drawn here becomes defiled. Furthermore, he must defile himself in order to draw upon himself that side of impure spirit. For we have learned: As one arouses, so he draws upon himself supernal holiness from above—and is sanctified. If one arouses the side of impurity, he draws upon himself a spirit of impurity—and is defiled. As already mentioned, we have learned that if a person comes to defile himself, he is defiled.
So in order to draw upon himself impure spirit from that supernal serpent, that wicked Balaam defiled himself every night with his donkey, engaging with her conjugally [see BT Sanhedrin 105a–b; Zohar 3:207a], in order to become defiled and draw upon himself impure spirit; then he enacted his sorcery.
To begin with, he would take one of those snakes and offer up incense before it. Then he split its head, extracted its tongue, took certain herbs, and burned everything—concocting incense. Next he took the snake’s head, split it in four, and concocted another incense. He traced a circle, recited a formula, and performed further rites—until he had drawn upon himself impure spirits, who revealed to him what he needed. Through them he accomplished his acts, by their knowledge derived from that celestial serpent. He continued his acts of sorcery until he had drawn upon himself a spirit from that primordial serpent. This is how he discovered and grasped knowledge of sorcery and divination; so it is written: He did not go, as time after time, to encounter נְחָשִׁים (neḥashim), serpentine sorceries (Numbers 24:1)—neḥashim, serpents, literally! The essential root lies in impurity, as has been said; subsequently all begins solely in this….
‘All these practices, all of Balaam’s knowledge—where did he learn it? He replied, ‘From his father. But in those mountains of the East, land of the East, he mastered all kinds of sorcery and divination—for in those mountains reside Uzza and Azael, whom the blessed Holy One had cast down from heaven. Bound in iron chains, they divulge sorcery to human beings; so from there Balaam knew, as is said: From Aram, Balak led me; Moab’s king, from mountains of the East (ibid. 23:7)” (Zohar 1:125a–126a, cf. Tiqqunei ha-Zohar 69, 97a).