El País said the virus was apparently introduced via email and was first spotted at the beginning of March.
A computer virus infected the Spanish defence ministry's intranet this month with the aim of stealing high tech military secrets, El País newspaper said on Tuesday, citing sources leading the investigation as suspecting a foreign power behind the cyber attack.
A defence ministry spokesman said the ministry would not comment.
El País said the virus was apparently introduced via email and was first spotted at the beginning of March. However, it could have gone undetected for months in an intranet with more than 50,000 users.
Although the network does not carry classified information, the paper said its sources were concerned about a wider infection to other networks with the purpose of accessing information related to secret military technology.
The investigation had yet to determine who was responsible for the cyber attack, but sources told El País it was too technically complex to be done by standard hackers. "There is a state behind it," they said.