You would be a NON arms length buyer, which is not illegal, but does require disclosure on the sales contract. If you are capable of buying the home quickly, before the foreclosure sale, you should be able to do so. I definitely recommend consulting a NY real estate attorney QUICKLY to get more definitive legal advice. You don’t mention if you are paying cash or obtaining a mortgage. Can tell you that getting a mortgage on a non-arms length, investment property in foreclosure is a huge long shot, not likely to happen under any circumstances.
If the property is in the stage before the auction, then yes you will be able to buy it. If it goes up for auction, then you could try buying it at the property auction. Remember that time is of the essence here – the longer you wait the less chance you will be able to stop the foreclosure process and the price will go up as more interest and fees are added.