If your buying from a dealer. Try to work an extended warranty in negotiation, especially if they are not coming off the price much.
Look for the obvious signs of leaks, frayed wires, replaced parts. Look at bolt heads and see if they have ever been removed on body panels. Easy to see the ring of where the bolt was on from the factory. Put your hand on top of the belly pan, if its been in mud it will still be on the top of the belly pan. Drive it for more than 5 minutes (get it up to temperature), put it on the highway, etc. Test the 4wd. Make sure all the bells and whistles still work. Negotiate price, then offer them less. Drive it home.