The Messenger of Allah ﷺ said, "Satan comes to one of you and asks, 'Who created the heavens?' He replies, 'Allah.' Then Satan asks, 'Who created the earth?' He replies, 'Allah.' Then Satan asks, 'Who created Allah?' When any of you senses something of this, let him say, 'I believe in Allah and His messengers.'"
حدثنا أبو النضر حدثنا أبو سعيد يعني المؤدب قال أبي واسمه محمد بن مسلم بن أبي الوضاح أبو سعيد المؤدب قال أبي وروى عنه عبد الرحمن بن مهدي وأبو داود وأبو كامل قال ثنا هشام عن أبيه
قال رسول الله ﷺ إن الشيطان يأتي أحدكم فيقول من خلق السماء فيقول الله عز وجل فيقول من خلق الأرض فيقول الله فيقول من خلق الله فإذا أحس أحدكم بشيء من هذا فليقل آمنت بالله وبرسله
Its chain of transmission is sahih. Bukhari related it in the chapter on the description of Iblis, from Yahya bin Bukayr. Muslim related it in the Book of Faith, from Abdul-Malik bin Shuayb bin Layth bin Saad, from Zuhayr bin Harb and Abd bin Humayd, from Harun bin Maruf and Muhammad bin Abbad, and from Muhammad bin Hatim. Abu Dawud related it in the Book of Sunnah, from Harun bin Maruf.In some versions the wording occurs, "Whoever encounters this should seek refuge in Allah and stop." The meaning is that one should turn away from this false thought and take refuge with Allah, Most High, in banishing it.Imam Maziri said, the apparent sense of the hadith is that the Prophet commanded them to repel these thoughts by turning away from them and rejecting them outright, without engaging in argument or reflecting on how to refute them.He said, what is said regarding this matter is that such thoughts are of two kinds. As for those that are not firmly settled and were not brought about by some doubt that arose, these are the ones to be repelled simply by turning away from them, and it is to this kind that the hadith should be applied, and it is to the like of these that the term "whispering" (waswasah) is properly applied. It is as though, since it was a passing matter with no real basis, it occurred without any need to examine proof, for it had no foundation to be examined in the first place. As for firmly settled thoughts that were produced by some genuine doubt, these cannot be repelled except through argument and reflection on how to refute them.