IS has successfully tapped a rich vein of extremism in Afghanistan.
Middle-class Afghans turned jihadists have assisted the Islamic State group's expansion from its stronghold in Afghanistan's restive east to Kabul, analysts say, helping to make the capital one of the deadliest places in the country.
IS has claimed nearly 20 attacks across Kabul in 18 months, with cells including students, professors and shopkeepers evading Afghan and US security forces to bring carnage to the highly fortified city.
It is an alarming development for Kabul's war-weary civilians and beleaguered security forces, who are already struggling to beat back the resurgent Taliban, as well as the US counter-terrorism mission in Afghanistan.
"This is not just a group that has a rural bastion in eastern Afghanistan -- it is staging high casualty, high visibility attacks in the nation's capital and I think that's something to be worried about," said analyst Michael Kugelman of the Wilson Center in Washington.
The Islamic State-Khorasan Province (IS-K), the Middle East group's affiliate in Afghanistan and Pakistan, emerged in the region in 2014, largely made up of disaffected fighters from the Taliban and other jihadist groups in Afghanistan, Pakistan and Central Asia.
It claimed its first attack in Kabul in the summer of 2016. Since then the Sunni group has struck at security forces and Shiites with increasing frequency, helped by its growing network in the capital.
There is no shortage of recruits, analysts say. IS has successfully tapped a rich vein of extremism in Afghanistan that has existed for decades and crosses socio-economic groups -- fanned by growing internet access among urban youth.
"We are talking about a generation which has been desensitised to different types of violence and violent extremism," said Borhan Osman, a senior analyst with the International Crisis Group.
"It should not come as a surprise that some of the youth inculcated in the ideology of jihadism embrace the next version of jihadism, the most violent one."
Members and supporters of IS cells in Kabul hide in the open, living with their families and going to classes or work every day, Osman said.
The militants meet at night to discuss jihad, or holy war, and plot attacks on targets in the city they know well -- well enough to adapt to changes, such as tightened security in the wake of a massive truck bomb in May that killed around 150 people.
"It's an adaptive structure reacting to the counter measures," a Western diplomat told AFP.
"From May to December what we have seen is different types of attacks, smaller attacks that are getting through."
An Afghan security source previously told AFP that "20 or more" IS-K cells were operating in the city.
- 'Hunt them down' -
Osman, an expert on militant networks in Afghanistan, said it was difficult to know how many IS-K fighters were in Kabul but their ranks were constantly being replenished by the group's recruitment efforts on social media as well as in universities, schools and mosques.
"You can't say they are all poor -- a number of them come from middle-class Kabuli families. Some are university educated. Some have a high school education," he said, adding that most have some religious education as well.
An Afghan security source agreed. "The new wave of extremists is not an uneducated farmer. It is mainly people with a good level of education," he told AFP on condition of anonymity.
While the Taliban remains by far the biggest threat to Afghanistan's security forces and government, IS-K has dominated headlines in recent months with attacks in Kabul, including three last month alone which killed dozens of people.
Some have come within metres of embassies and NATO's Resolute Support mission, a disconcerting reply to vows by the head of US Forces-Afghanistan General John Nicholson to "hunt them down" until they are "annihilated".
Last year the US dropped the so-called Mother of All Bombs, the largest non-nuclear weapon ever used in combat, on IS strongholds in Nangarhar. That has been followed by intense aerial bombing by Afghan and US forces.
But analysts point out that the strategy has failed to destroy IS -- and may have even pushed more militants into Kabul, where using that sort of overwhelming firepower is not an option.
- New IS base? -
The group's resilience has raised fears that Afghanistan could become a new base for IS fighters fleeing the battlefields of Syria and Iraq, where the group has lost swathes of territory.
But the exact nature of links between IS in Afghanistan and the Middle East remains unclear.
The Afghan government claims there is no connection. Analysts told AFP there is communication, and AFP reported last month that French and Algerian fighters, some arriving from Syria, had joined IS in northern Afghanistan where the group has established new bases.
Regardless of links, the goals of IS in the Middle East and in Afghanistan appear to be aligned: stirring up sectarian violence.
"The real game is to provoke a lot of Sunni hatred towards Shias (Shiites)," Vanda Felbab-Brown, a senior fellow at the Brookings Institution, told AFP.
She said she was "waiting" for an attack on a major Sunni mosque, whether by a frustrated Shiite or by IS pretending to be Shiites in order to inflame Sunni anger.
But, its success in the capital aside, IS will struggle to turn Afghanistan into a new sectarian front, predicts Kugelman, who points out that most cleavages in Afghanistan are ethnic, not sectarian.
At any rate, he says, "why would you want your new front to be in a place where you have some of the most relentless levels of firepower being used against you?"