A moderate 5.7 magnitude earthquake shook buildings and damaged two mosques in Istanbul on Thursday, slightly injuring eight people and causing residents to rush from buildings.