An Afghan soldier and police officer have turned their guns on foreign troops they work with, killing two and injuring several others, hours after the Taliban's leader boasted about his fighters' infiltration of government security forces and called for more attacks.

Two US special forces soldiers were killed in western Farah province by a newly recruited member of the Afghan Local Police, shortly after they handed him a gun during an inauguration ceremony.

"As soon as they gave the weapon to Ismail to begin training, suddenly he took the gun and opened fire toward the US soldiers," Farah provincial police chief Agha Noor Kemtoz told the Associated Press.

Hours later, in a volatile corner of southern Kandahar province, an Afghan soldier opened fire on a group of Nato troops, but was shot before he could kill anyone, said Nato spokesman Major Martin Crighton. The attacker later died of his wounds.

It was the second Friday in a row that there have been "insider attacks" on foreign soldiers. Last Friday, six US troops were killed, and there were other non-fatal attacks this week. Last Saturday, an Afghan policeman also shot dead nine of his fellow officers.

Afghan and Nato officials have been desperately searching for a way to staunch the growing tide of these shootings, which are badly damaging morale on the critical mission to train Afghan forces as foreigners head home.

There are intelligence agents undercover in many Afghan army units to seek out insurgent sympathisers, and Nato has created a system of "guardian angels" – soldiers who watch over fellow troops when they are with armed Afghan forces.

Even so, the attacks have been increasing, with 31 this year so far, compared with 21 in all of 2011. They have killed 39 people, while in all of last year 35 died.

The attacks were welcomed by Taliban leader Mullah Muhammad Omar in his annual message marking Eid al-Fitr, the end of the fasting month of Ramadan. He also called on more security forces to turn against their allies.

"Mujahideen have cleverly infiltrated in the ranks of the enemy according to the plan given to them last year ... they easily carry out decisive and co-ordinated attacks, inflicting heavy losses," the message, published online in English translation, said. "We expect others to display the same boldness and spirit."

The leader of Nato and US forces in Afghanistan, General John Allen, attacked the Taliban statement as "insane language", and described the police and soldiers who turn on their allies as "the worst of humanity … Mullah Omar has issued an unmistakable message of death, hate and hopelessness for the Afghan people".

Nato commanders argue that the attackers account for the tiniest portion of security forces, now more than 300,000 strong, and say many are driven by personal grudges rather than ideology.

But infiltration might be easier to tackle systematically than the chance collision of personal problems and anger at western troops. And the shooters' motivation has no bearing on how the attacks affect sentiment both in Afghanistan and the countries that lose soldiers.