It will cost quite a bit more money of a dealer handles a purchase, lease payoff, and resale, for obvious reasons.
This is actually a fairly routine process and I have handled these several times for clients here in CA.
Open up the dialogue with the leasing entity, not the originating dealership. Get the payoff, or residual if the lease is concluding, and ask about any additional fees that may be due. The very last thing in the world the lessor wants is to have to send the truck around to pick up that car.
For this reason, you may be able to negotiate a lower amount to purchase the vehicle. This was more common a few years ago when residuals were woefully inaccurate(for a variety of reasons) but is still known to happen on occasion. Why not try?
Depending on the vehicle, the original deal structure and length of term, very often the lessee can make a couple of thousand dollars on transactions of these kinds. Of course, it isn't like 'profit'...after all, it is their money! They have already purchased whatever leverage they have or don't have.
If the mileage is significantly under the alloted amount, it is crazy not to at least run an ad and see what comes up.
Finally, if you are over your alloted mileage, do a quick study on average pricing in your area for your vehicle specs. You may well be able to sell the car, or at least attempt to sell the car, and may be able to minimize the damage. If you have to make up the difference in cash, well...you were going to do that anyway!
Also, please don't park your car when your mileage is close or feel bad about it. These are not really 'penalty' charges, they are simply the cost of the additional use that you did not pay for in advance.
Nobody knows how their lives might change over a lease term, and deferring the payment of this usage until the end of the lease is not a bad thing. These miles will cost you perhaps 33% more, but what if you hadn't used them? There are no refunds on lease mileage!! Also, no crying in baseball.
Source: CAR FU: Self-Defense for Car Buyers