The problem of radiative transfer in the ro-vibrational molecular bands under condition of local thermodynamic equilibrium breakdown in a planetary atmosphere is generalized for the case taking into account the extinction (i.e. scattering and absorption) of the continuum radiation produced by aerosols. The method for calculating the nonequilibrium populations of vibrational states of gas molecules in the planetary atmospheres is developed. Formation of the values of the non-equilibrium populations of the excited vibrational states of the CO
2 molecules (in the application to the atmosphere of Mars) within the framework of the model of radiative transfer in the near-infrared bands of this molecule taking into account the extinction of radiation in the continuum produced by aerosol particles has been investigated for the first time. The most complete optical model of the CO
2 and CO molecules is used. A distinctive feature of this model is the detailed accounting of the overlap in frequency of the lines in the spectral range of 1.05-15 μm, which belong to all ro-vibrational transitions of different isotopologues of the CO
2 and CO molecules included into the optical model, as well as accounting for the reflection of radiation by the surface of the planet.