The agency has put software in thousands of computers that allows for surveillance and can also create a path for launching cyberattacks, according to documents, experts and officials.