...specially concerning the trains being in fact direct or not
Well, de-facto Budapest to Krakow overnight connection is served by through carriages, thus yes it's direct, but it's just couple carriages which actually get reattached from one train to another. For passengers these nuances aren't important, but still just makes sense to know that is is not a full scale train. Similar story with Krakow to Prague, it's also couple through carriages
I was wondering if someone could indicate me the best and cheapest links to book these trains?
In such cases official website of rail companies is the most reliable place to buy the tickets + for sure the cheapest, since rail companies (MAV & PKP) doesn't charge any extra fee. With Hungary (MAV) everything is very easy - just go to their website and buy the tickets you need (our website even has a
step by step guide on how to do it). Discounted tickets Budapest-Krakow for 6 berth couchette start from only 39 euro per passenger, 3 bed sleepers from 45 euro. However remember since it's discounted tickets the number of it is limited per each departure, so it makes sense to buy it in advance (tickets sale starts 60 days in advance)
With Krakow to Prague everything is more complicated, since Polish Railways (PKP) doesn't yet sell tickets like Krakow-Prague online, so you can buy them only in Poland. If it's not an option for you, then there is always a number of agencies, which can serve as a intermediary, although they definitely will charge you extra and for sure not as reliable as actual rail companies running the trains