There is something called a 'redemption period' which may allow you to pay off the entire mortgage and all the associated late fees and foreclosure fees to retain your home .. but this is rare as you wont typically be able to get a loan for this and it is a lot of cash to come up with on short notice.
You DO want an attorney to answer this question. Every circumstance is different in homes sold at auctions and the homeowner buying it back. There are options you can discuss with a real estate attorney in regards to your question and I do recommend you seek the advice of an attorney if that is your plan.
Mortgage Broker or Lender, Louisville, KY
If you have the money to buy it back the last lender may be entitled to some or all of what you have if there was a deficiency when the house was sold. Get an attorney that knows the foreclosure process before making an offer. Good luck,
NMLS # 6395
Financing Kentucky One Home at a Time
It will depend if you state has a redemptionperiod to allow you to do that. If not you should contact your bank and inquire or seek the advice of an attorney who can negotiate for you. Good luck working things out