Filing for bankruptcy can discharge your second mortgage. Filing for Chapter 7 bankruptcy will discharge your personal liability for your second mortgage, but the lien on your home will still remain. If your home has been foreclosed and your second mortgagor did not receive any proceeds form the foreclosure sale, then you can be sued for whatever you owe on the second mortgage. However, since the home is now foreclosed, the second mortgage is now considered an unsecured debt and can be eliminated through a Chapter 7 bankruptcy.
Filing for Chapter 13 can actually eliminate the lien through a process called "lien stripping"-discharging unsecured claims. If your home is now worth the same or less than your first mortgage, then your second mortgage will be considered unsecured debt like your credit card debts i.e. it's not attached to any asset. In this case, Chapter 13 can strip away your unsecured second mortgage, thus effectively removing both your liability and the lien itself.