When the principal and surety are liable for any claim, such surety may pay the same, and recover thereon against all liable to the surety. If a judgment against principal and surety has been paid by the surety, the surety shall be subrogated to all the rights of the creditor, and may take an assignment thereof, and enforce the same by execution or otherwise, as the creditor could have done. All questions between the parties thereto may be heard and determined on motion by the court upon such notice as may be prescribed by it.