If you have a square wave generator, then the output will be relatively rich in odd harmonics. The third harmonic for instance is only about 10dB down on the fundamental.
If you set the generator for 1/3rd of the output frequency you need, and connect it to a passive high pass filter to reject the fundamental and pass the 3rd harmonic, or better still a band pass filter tuned to the 3rd harmonic, you will get some output. A low pass filter will not do.
With good filters with low losses, you may approach an output voltage of 30% of the fundamental input voltage, which is what -10dB means.
Whether you can build good passive filters, which means appreciating the effect of source impedance and loading on its response, and designing for it properly, and whether that is enough output for you is another matter.
If this is an interesting exercise in 'can it be done', I'd say go for it for the lols. If this is a real attempt to build bench test gear that you don't have to worry about and nurse, then I'd say build the proper test gear from scratch, or buy it.
There is one consideration I have. If that '40kHz' means you want to drive an ultrasonic transducer, then you may have it fairly easy. The transducer itself is fairly 'bandpassy', and a small series capacitor may be all the high pass filter you need. Whack a 13.3kHz square wave into it through a small capacitor and see whether you get what you need.