Russian President Vladimir Putin attends a meeting with Indian Prime Minister Narendra Modi on the sidelines of the St. Petersburg International Economic Forum (SPIEF), Russia, June 1, 2017. REUTERS/Dmitri Lovetsky/Pool

ST PETERSBURG, Russia (Reuters) - President Vladimir Putin said on Thursday that patriotic Russian hackers may have staged cyber attacks against countries that had strained relations with Moscow on their own initiative, but said the Russian state had never been involved in such hacking.

Putin, speaking to international media at an economic forum in St Petersburg, was answering a question about allegations Moscow might try to interfere in this year's German elections.

Moscow's attitude towards cyber crime is under intense scrutiny after U.S. intelligence officials alleged that Russian hackers had tried to help Republican Donald Trump win the White House, something Russia has flatly denied.

"If they (hackers) are patriotically-minded, they start to make their own contribution to what they believe is the good fight against those who speak badly about Russia. Is that possible? Theoretically it is possible," said Putin.

Likening hackers to free-spirited artists acting according to their moods, he said cyber attacks could be made to look like they had come from Russia when they had not.

Putin also said he was personally convinced that hackers could not materially alter election campaigns in Europe, America or elsewhere.

"On a state level we haven't been involved in this (hacking), we aren't planning to be involved in it. Quite the opposite, we are trying to combat it inside our country," said Putin.

(Reporting by Denis Pinchuk; Writing by Alexander Winning; Editing by Andrew Osborn)