كتاب الْمَسَاجِدِ وَمَوَاضِعِ الصَّلاَةِ
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 d

Abu Salama narrated that Abu Huraira told him that when the Messenger of Allah (ﷺ) pronounced:

" Allah listened to him who praised Him." and before prostration, he would recite this in the 'Isya' prayer: O Allah! rescue 'Ayyash b. Abu Rabi'a, and the rest of the hadith is the same as narrated by Auza'i to the words:" Like the famine (at the time) if Joseph." but he made no mention of that which follows afterwards.
وَحَدَّثَنِي زُهَيْرُ بْنُ حَرْبٍ، حَدَّثَنَا حُسَيْنُ بْنُ مُحَمَّدٍ، حَدَّثَنَا شَيْبَانُ، عَنْ يَحْيَى، عَنْ أَبِي سَلَمَةَ، أَنَّ أَبَا هُرَيْرَةَ، أَخْبَرَهُ أَنَّ رَسُولَ اللَّهِ صلى الله عليه وسلم بَيْنَمَا هُوَ يُصَلِّي الْعِشَاءَ إِذْ قَالَ ‏"‏ سَمِعَ اللَّهُ لِمَنْ حَمِدَهُ ‏"‏ ‏.‏ ثُمَّ قَالَ قَبْلَ أَنْ يَسْجُدَ ‏"‏ اللَّهُمَّ نَجِّ عَيَّاشَ بْنَ أَبِي رَبِيعَةَ ‏"‏ ‏.‏ ثُمَّ ذَكَرَ بِمِثْلِ حَدِيثِ الأَوْزَاعِيِّ إِلَى قَوْلِهِ ‏"‏ كَسِنِي يُوسُفَ ‏"‏ ‏.‏ وَلَمْ يَذْكُرْ مَا بَعْدَهُ ‏.‏
Reference : Sahih Muslim 675d
In-book reference : Book 5, Hadith 376
USC-MSA web (English) reference : Book 4, Hadith 1431
  (deprecated numbering scheme)