كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
5  
The Book of Mosques and Places of Prayer
(54)
Chapter: It is recommended to say qunut in all prayers if a calamity befalls the Muslims – and refuge is sought from Allah (regarding that). It is recommended to say qunut in Subh at all times. And the clarification that it is to be said after raising the head from bowing in the final rak`ah, and it is recommended to say it out loud
(54)
باب اسْتِحْبَابِ الْقُنُوتِ فِي جَمِيعِ الصَّلاَةِ إِذَا نزَلَتْ بِالْمُسْلِمِينَ نَازِلَةٌ ‏‏
Sahih Muslim 675 a

Abu Salama b. Abd al-Rahman b. 'Auf heard Abu Huraira say:

(When) Allah's Messenger (ﷺ) (wished to invoke curse or blessing on someone, he would do so at the end) of the recitation in the dawn prayer, when he had pronounced Allah-o-Akbar (for bending) and then lifted his head (saying):" Allah listened to him who praised Him; our Lord! to Thee is all praise" ; he would then stand up and say:" Rescue al-Walid b. Walid, Salama b. Hisham, and 'Ayyash b. Abd Rabi'a, and the helpless among the Muslims. O Allah! trample severely Mudar and cause them a famine (which broke out at the time) of Joseph. O Allah! curse Lihyan, Ri'l, Dhakwan, 'Usayya, for they disobeyed Allah and His Messenger." (The narrator then adds): The news reached us that he abandoned (this) when this verse was revealed:" Thou but no concern in the matter whether He turns to them (mercifully) or chastises them; surely they are wrongdoers" (ill. 127)
حَدَّثَنِي أَبُو الطَّاهِرِ، وَحَرْمَلَةُ بْنُ يَحْيَى، قَالاَ أَخْبَرَنَا ابْنُ وَهْبٍ، أَخْبَرَنِي يُونُسُ بْنُ يَزِيدَ، عَنِ ابْنِ شِهَابٍ، قَالَ أَخْبَرَنِي سَعِيدُ بْنُ الْمُسَيَّبِ، وَأَبُو سَلَمَةَ بْنُ عَبْدِ الرَّحْمَنِ بْنِ عَوْفٍ أَنَّهُمَا سَمِعَا أَبَا هُرَيْرَةَ، يَقُولُ كَانَ رَسُولُ اللَّهِ صلى الله عليه وسلم يَقُولُ حِينَ يَفْرُغُ مِنْ صَلاَةِ الْفَجْرِ مِنَ الْقِرَاءَةِ وَيُكَبِّرُ وَيَرْفَعُ رَأْسَهُ ‏"‏ سَمِعَ اللَّهُ لِمَنْ حَمِدَهُ رَبَّنَا وَلَكَ الْحَمْدُ ‏"‏ ‏.‏ ثُمَّ يَقُولُ وَهُوَ قَائِمٌ ‏"‏ اللَّهُمَّ أَنْجِ الْوَلِيدَ بْنَ الْوَلِيدِ وَسَلَمَةَ بْنَ هِشَامٍ وَعَيَّاشَ بْنَ أَبِي رَبِيعَةَ وَالْمُسْتَضْعَفِينَ مِنَ الْمُؤْمِنِينَ اللَّهُمَّ اشْدُدْ وَطْأَتَكَ عَلَى مُضَرَ وَاجْعَلْهَا عَلَيْهِمْ كَسِنِي يُوسُفَ اللَّهُمَّ الْعَنْ لِحْيَانَ وَرِعْلاً وَذَكْوَانَ وَعُصَيَّةَ عَصَتِ اللَّهَ وَرَسُولَهُ ‏"‏ ‏.‏ ثُمَّ بَلَغَنَا أَنَّهُ تَرَكَ ذَلِكَ لَمَّا أُنْزِلَ ‏{‏ لَيْسَ لَكَ مِنَ الأَمْرِ شَىْءٌ أَوْ يَتُوبَ عَلَيْهِمْ أَوْ يُعَذِّبَهُمْ فَإِنَّهُمْ ظَالِمُونَ‏}‏ ‏.‏
Reference : Sahih Muslim 675a
In-book reference : Book 5, Hadith 373
USC-MSA web (English) reference : Book 4, Hadith 1428
  (deprecated numbering scheme)