The cyber attack began spreading across the globe on Fridayand by Monday had infected 300,000 computers in more than 150countries.

"These attacks help focus the minds of chief technology officers across corporations to make sure security protocols are up to date, and you often see bookings growth at cyber security companies as a result," said Neil Campling, head of technology research at Northern Trust.

Investors treated the attack as a buying opportunity for security stocks rather than a cause for concern over the risk it posed to companies, with the pan-European STOXX 600 <.STOXX> index closing higher and major U.S. indices also up.

In London, shares in cloud network security firm Sophos (>> Sophos Ltd) jumped more than 7 percent to a record high and security firm NCC Group (>> NCC Group PLC) rose 2.7 percent.

U.S.-listed shares in cyber security firms FireEye (>> FireEye Inc) rose 8 percent, and peers Symantec (>> Symantec Corporation) and Palo Alto Networks (>> Palo Alto Networks Inc) were up around 3 percent.

The cyber security ETF rose 3.3 percent.

The attack would "refocus IT attention on updating security infrastructure and procedures" and benefit providers in email, network, and endpoint security, analysts at Wedbush wrote in a research report, highlighting Proofpoint (>> Proofpoint Inc) and Splunk (>> Splunk Inc) as stocks to watch. Proofpoint shares jumped 7.5 percent.

Analysts at Bernstein said desktop virtualization vendors Citrix Systems (>> Citrix Systems, Inc.) and VMware (>> VMware, Inc.) could indirectly benefit from the upgrade cycle, while defense companies Raytheon (>> Raytheon Company) and BAE Systems (>> BAE Systems plc) should similarly get a boost in their commercial cyber security businesses.

Government spending on computer security should also help General Dynamics (>> General Dynamics Corporation), Lockheed Martin (>> Lockheed Martin Corporation) and Northrop Grumman (>> Northrop Grumman Corporation), Bernstein said.

Companies' spending on cyber security protection is set toincrease 10 percent in Britain and Europe by 2020, according to Brian Lord, a managing director of cyber and technology at cyber security firm PGI, as outdated IT systems get a refresh.

"In many companies, there's been an increase in investment in IT but not in the security that sits around it, so this investment is likely to play a bit of catch-up," said Lord, who spent 21 years at UK government intelligence service GCHQ.

The risks of security breaches, particularly when they result in the leak of sensitive customer data, has in the past had a direct impact on share prices as investor confidence is shaken.

"Reducing the cost of security breaches by only 10 percent can save global enterprises $17 billion annually," MorganStanley said in a report published on Monday.

The U.S. broker upgraded networking equipment giant Cisco Systems (>> Cisco Systems, Inc.) to "overweight." Cisco shares, part of the Dow Jones Industrial Average <.DJI> were up 2.3 percent.

With few pure-play, publicly traded software and network security companies in Europe, a London-listed cyber security exchange-traded fund (ETF) , whose holdings include Cisco and FireEye, was in demand, ending up 3.4 percent.

In Helsinki, Finnish digital security firm F-Secure (>> F-Secure Oyj) jumped as much as 5.1 percent to a 16-year high.

(To view a graphic on how cyber security ETF beats broader market, click http://reut.rs/2qJm5sE)

(To view a graphic on how ransomware attack works, where and when it spread , click http://tmsnrt.rs/2qIUckv)

(Additional reporting by Danilo Masoni and Megan Davies; Editing by Bill Rigby and Nick Zieminski)

By Helen Reid