Bifurcation of free and forced vibrations for nonlinear wave and Kirkhoff equations via Nash-Moser theory