Rangers left it late as they came from behind to beat second-tier Greenock Morton to book a Viaplay Cup quarter-final place.