كتاب الطهارة
3  
Purification
(3a)
Chapter: How to act when relieving oneself - Section 1
(2)
باب آداب الخلاء - الفصل الأول
Mishkat al-Masabih 337
Anas reported that when God’s messenger entered the privy he used to say, "O God, I seek refuge in Thee from male and female devils.”* *One might be inclined to translate this phrase as "from infidelity and act of disobedience,” but the tradition from Zaid b. Arqam (p. 76) is very explicit, and so the translation above is probably the correct one. PT-2 (12-71.) (Bukhari and Muslim).
وَعَنْ أَنَسٍ قَالَ: كَانَ رَسُولُ اللَّهِ صَلَّى اللَّهُ عَلَيْهِ وَسَلَّمَ إِذَا دَخَلَ الْخَلَاءَ يَقُولُ: «اللَّهُمَّ إِنِّي أَعُوذُ بِكَ مِنَ الْخبث والخبائث»
  مُتَّفَقٌ عَلَيْهِ   (الألباني) حكم   :
Reference : Mishkat al-Masabih 337
In-book reference : Book 3, Hadith 49