Mac users have been targeted by hackers with “ransomware” in what is believed to be the first attack of its kind.