  The hadronic contribution to the eight forward amplitudes of light-by-light
scattering ($\gamma^*\gamma^*\to \gamma^*\gamma^*$) is computed in lattice QCD.
Via dispersive sum rules, the amplitudes are compared to a model of the
$\gamma^*\gamma^*\to {\rm hadrons}$ cross sections in which the fusion process
is described by hadronic resonances. Our results thus provide an important test
for the model estimates of hadronic light-by-light scattering in the anomalous
magnetic moment of the muon, $a_\mu^{\rm HLbL}$. Using simple parametrizations
of the resonance $M\to \gamma^*\gamma^*$ transition form factors, we determine
the corresponding monopole and dipole masses by performing a global fit to all
eight amplitudes. Together with a previous dedicated calculation of the
$\pi^0\to \gamma^*\gamma^*$ transition form factor, our calculation provides
valuable information for phenomenological estimates of $a_\mu^{\rm HLbL}$. The
presented calculations are performed in two-flavor QCD with pion masses
extending down to 190\,MeV at two different lattice spacings. In addition to
the fully connected Wick contractions, on two lattice ensembles we also compute
the (2+2) disconnected class of diagrams, and find that their overall size is
compatible with a parameter-free, large-$N$ inspired prediction, where $N$ is
the number of colors. Motivated by this observation, we estimate in the same
way the disconnected contribution to $a_\mu^{\rm HLbL}$.
