Sunan Ibn Majah, Volume 5, Book 36, Hadith 4084 (DarusSalam)

It was narrated from Thawban that the Messenger of Allah said: "Three will fight one another for your treasure, each one of them the son of a caliph, but none of them will gain it. Then the black banners will come from the east, and they will kill you in an unprecedented manner." Then he mentioned something that I do not remember, then he said: "When you see them, then pledge your allegiance to them even if you have to crawl over the snow, for that is the caliph of Allah, Mahdi."

حَدَّثَنَا مُحَمَّدُ بْنُ يَحْيَى، وَأَحْمَدُ بْنُ يُوسُفَ، قَالاَ حَدَّثَنَا عَبْدُ الرَّزَّاقِ، عَنْ سُفْيَانَ الثَّوْرِيِّ، عَنْ خَالِدٍ الْحَذَّاءِ، عَنْ أَبِي قِلاَبَةَ، عَنْ أَبِي أَسْمَاءَ الرَّحَبِيِّ، عَنْ ثَوْبَانَ، قَالَ قَالَ رَسُولُ اللَّهِ ـ صلى الله عليه وسلم ـ ‏"‏ يَقْتَتِلُ عِنْدَ كَنْزِكُمْ ثَلاَثَةٌ كُلُّهُمُ ابْنُ خَلِيفَةٍ ثُمَّ لاَ يَصِيرُ إِلَى وَاحِدٍ مِنْهُمْ ثُمَّ تَطْلُعُ الرَّايَاتُ السُّودُ مِنْ قِبَلِ الْمَشْرِقِ فَيَقْتُلُونَكُمْ قَتْلاً لَمْ يُقْتَلْهُ قَوْمٌ ‏"‏ ‏.‏ ثُمَّ ذَكَرَ شَيْئًا لاَ أَحْفَظُهُ فَقَالَ ‏"‏ فَإِذَا رَأَيْتُمُوهُ فَبَايِعُوهُ وَلَوْ حَبْوًا عَلَى الثَّلْجِ فَإِنَّهُ خَلِيفَةُ اللَّهِ الْمَهْدِيُّ ‏"‏ ‏.‏

sunnah.com