Weak entangled magnetic fields with mixed polarity occupy the main part of the quiet Sun. The Zeeman effect diagnostics fails to measure such fields because of cancellation in circular polarization. However, the Hanle effect diagnostics, accessible through the second solar spectrum, provides us with a very sensitive tool for studying the distribution of weak magnetic fields on the Sun. Molecular lines are very strong and even dominate in some regions of the second solar spectrum. The CN $B {}^{2} Sigma - X {}^{2} Sigma$ system is one of the richest and most promising systems for molecular diagnostics and well suited for the application of the differential Hanle effect method. The aim is to interpret observations of the CN $B {}^{2} Sigma - X {}^{2} Sigma$ system using the Hanle effect and to obtain an estimation of the magnetic field strength. We assume that the CN molecular layer is situated above the region where the continuum radiation is formed and employ the single-scattering approximation. Together with the Hanle effect theory this provides us with a model that can diagnose turbulent magnetic fields. We have succeeded in fitting modeled CN lines in several regions of the second solar spectrum to observations and obtained a magnetic field strength in the range from 10--30 G in the upper solar photosphere depending on the considered lines.