The Messenger of Allah ﷺ said, "Every ruler has two inner circles of advisors. One urges him toward what is right and forbids him from what is wrong, and the other spares no effort in corrupting him. Whoever is protected from the harm of the latter has truly been protected, and a ruler belongs to whichever of the two prevails over him."
أخبرنا محمد بن يحيى بن عبد الله قال حدثنا معمر بن يعمر قال حدثني معاوية بن سلام قال حدثني الزهري قال حدثني أبو سلمة بن عبد الرحمن
قال رسول الله ﷺ ما من وال إلا وله بطانتان بطانة تأمره بالمعروف وتنهاه عن المنكر وبطانة لا تألوه خبالا فمن وقي شرها فقد وقي وهو من التي تغلب عليه منهما
Bukhari narrated it in the Book of Rulings, Chapter on the Confidants of the Ruler and His Council, hadith 7198, from the hadith of Muawiya bin Salam, as a suspended chain (muallaqan). It also appears in Al-Kubra, hadith 7824.