It is narrated from Sayyiduna Abu Sa'id al-Khudri (may Allah be pleased with him) that the Prophet (peace and blessings be upon him) led the prayer and took off his sandals, and the people also took off their sandals. When he (peace and blessings be upon him) finished, he asked: "Why did you take off your sandals?" They said: O Messenger of Allah! We saw that you took yours off, so we took ours off too. He (peace and blessings be upon him) said: "Jibril (peace be upon him) came to me and informed me that there was filth on the sandals. When one of you comes to the mosque, he should turn his sandals over and look for filth on them; if there is filth on them, he should rub them against the ground and then pray in them."
This hadith is known through Hammad bin Salamah, from Abu Na'amah Abd Rabbih al-Sa'di, from Abu Nadrah. It has also been narrated from al-Hajjaj bin al-Hajjaj, from Abu Amir al-Khazzaz, from Abu Na'amah, and that is not strong; and it has been narrated through another way, which is not preserved (ghayr mahfuz), from Ayyub al-Sakhtiyani, from Abu Nadrah.
Hadith Referenceالسنن الكبرى للبيهقي / كتاب الصلاة / 4087