The National Security Agency infected more than 50,000 networks across the globe with malware as part of a massive surveillance effort.