Bankruptcy law is hundreds of years old and is designed to protect creditors actually. That’s why there is a separate court to handle things and involved independent outsiders and judges that oversee things. It works and is used every time there is a financial crisis and thousands of times per day at the individual level.
This sort of thing is specifically prevented and handled by a principle called fraudulent conveyance. This principle causes the court to look back in time to what the assets and liabilities were closer to the time of the start of the financial difficulties of the debtor.