Among those offering eulogies for Ahmed Wali Karzai on Wednesday, Fauzia Kofi kept her condolences brief, preoccupied by a thought that had kept her awake the previous night.

“If they can kill Ahmed Wali, then they can kill any of us,” said Kofi, a member of Afghanistan’s parliament. “What does this mean for our security?”

Kofi frantically rearranged her 10-member security detail Wed­nesday, replacing several bodyguards she considered questionable.

“The longer they’re here,” she said, “the more time the Taliban has to recruit them.”

After a string of recent attacks targeting top officials, Afghan political, military and business leaders who are responsible for establishing a stable democracy in their country have more immediate — and more paralyzing — concerns about their personal safety. Afghanistan has long been a land of shifting alliances and uncertain loyalties, but increasingly, members of the ruling class are being forced to look to their inner circles for possible infiltrators.

In the past several months, Gen. Mohammad Daud Daud, northern Afghanistan’s top police commander; Gen. Khan Mohammad Mujahid, the police chief of the southern province of Kandahar; and Gen. Abdul Rahman Sayedkhili, the police chief of the northern province of Kunduz, were killed in attacks for which the Taliban has taken credit.

Many say the targeted attacks, including the one Tuesday on the president’s powerful and divisive half brother, were inside jobs — a sign of the Taliban’s growing ability to infiltrate the Afghan security establishment. The man accused of killing Karzai, Sardar Mohammad, had built trust with the family for many years, working as a guard and police commander. The Taliban has asserted responsibility for Karzai’s killing, but Mohammad’s motives are not known.

“The enemy has changed its tactic and has focused now on infiltration, and there is no measure to stop this,” said a top Afghan security official, who spoke on the condition of anonymity.

In recent months, insurgents who have penetrated Afghan police and military ranks have also targeted Americans, a strategy that has created friction between U.S. troops and the Afghan security forces they are training.

Many Afghan officials, meanwhile, have survived close calls. In June, not long after Samiullah Qatra was appointed Sayedkhili’s successor in Kunduz, he was nearly killed in a suicide attack, too. Four of Qatra’s bodyguards were killed.

“I believe that whenever one’s death is destined, you will die,” Qatra said. “Still, we have taken our measures by focusing on intelligence-gathering and providing education to the police.”

At the parliament, protected by a smattering of run-down checkpoints and dysfunctional metal detectors, Afghan officials vacillated between resignation and hysteria. Some refused to make any changes to their security details. Others met with guards to demand swift improvements and heightened protection.

The parliament’s security unit advised politicians to avoid gathering in large numbers except for scheduled meetings. Kofi was promised that the unit would keep her abreast of possible threats.

Sitting in a meeting room outside the parliament’s main chamber, she sighed. The government had warned her last month that she was on a list of Taliban targets, Kofi said.

“I’m not safe even in my bedroom,” she said.

Among politicians here, there’s little uniformity when it comes to personal security. Kofi, like most members of parliament, uses state-provided bodyguards, recruited by a central government she doesn’t much trust. The Interior Ministry uses the same vetting process for high-level bodyguards as the nation’s police force — an organization that Taliban members have repeatedly infiltrated in recent months.

But wealthy, well-connected politicians fund their own security details, which often amount to small-scale militias. Abdul Zahir Qadir, the son of a former Afghan vice president, keeps a staff of 20 military-trained bodyguards.

“I’ve known them my whole life,” he said. “Their fathers were my father’s bodyguards. Their grandfathers were my grandfather’s bodyguards.”

Qadir sat in his air-conditioned office, wearing a watch speckled with diamonds under a beige shalwar kameez. In the past decade, there have been three attempts on his life. He smiles as he tells the stories, proud of having fooled death.

His father, Abdul Qadir, was not so lucky. In 2002, he was shot 35 times as he stepped out of his car in Kabul. He had decided that morning not to bring bodyguards.

“We must always be ready for death,” Qadir said. As if on cue, someone knocked loudly at his door. Qadir flinched, and then laughed.

Other prominent Afghans have come to rely on private security companies that boast vetting processes more stringent than the government’s.

Kabul-based White Eagle Security coordinates with tribal leaders, police chiefs and provincial officials before hiring its guards. That system has been largely effective, but in Afghanistan, said Ian Hall, a White Eagle official, no vetting process is without problems.

“In the current situation, you can’t trust anyone,” he said.

Special correspondent Sayed Salahuddin contributed to this report.