The U.S. government confidently traced last year's massive Sony hack to North Korea in part because the National Security Agency had itself infiltrated Pyongyang's computer systems, the New York Times reported.

The NSA tried to break into North Korea's networks as early as 2010 with the help of South Korea and other American allies, according to unnamed U.S. and foreign officials and computer experts as well as new documents.

The signal-intelligence agency tried to place malware that could track the internal workings of many of the computers and networks used by North Korea's up to 6,000 hackers. Evidence secretly collected by the hidden software helped persuade President Obama to accuse the government of Kim Jong Un of ordering the Sony attack.

Pyongyang's secretive hacking unit, called "Bureau 121," and the hermit kingdom's main intelligence service, the Reconnaissance General Bureau, command the impressive hacking force, a large part of which operates in China and through connections in Malaysia. The NSA apparently drilled into the Chinese networks that connect North Korea to the outside world.

Though it would not comment directly, the office of National Intelligence Director James Clapper on Monday acknowledged in a statement that the U.S. spy community "has been tracking North Korean intrusions and phishing attacks on a routine basis," Fox News reported.

"While no two situations are the same, it is our shared goal is to prevent bad actors from exploiting, disrupting or damaging U.S. commercial networks and cyber infrastructure," the note read. "When it becomes clear that cyber criminals have the ability and intent to do damage, we work cooperatively to defend networks."

In late December, North Korea experienced widespread Internet outages, for which it blamed the United States, CNN recalled. U.S. officials declined to comment on the incident.

The attack on Sony Pictures Entertainment, which started in November, was considered the North Korean reaction to the release of "The Interview," a movie that depicts Kim, the country's dictator, in a negative light.

Though Pyongyang denied direct involvement through diplomats based in New York, it qualified the hack and release of data by the self-styled hacker group "Guardians of Peace" as "righteous."