A shallow earthquake with a preliminary magnitude of 5.7 struck northwest Pakistan on Thursday, the US Geological Survey said.