The Taliban and ISIL are creating a perfect storm of carnage in Kabul, adapting to ramped-up security in the war-weary capital - and it is civilians who are paying the price

Three times in the past 10 days Taliban and ISIL extremists have penetrated heavily fortified areas in Afghanistan's capital to carry out attacks that have killed and wounded hundreds of people, including locals and foreigners.

The extremists' chilling ability to strike again and again at the heart of the country despite increased police checks has put security and intelligence failures in the spotlight.

After the latest assault on Monday, an ISIL-claimed attack on an army battalion that killed at least 11 soldiers, president Ashraf Ghani pledged in a tweet that "reforms in our intelligence services and Ministry of Interior are our top priority now".

But as public anger swells, security officials are on the defensive.

"The terrorists are changing their tactics," Mohammad Masoom Stanekzai, the head of Afghanistan's spy agency, told reporters on Sunday.

"It does not mean a lapse (in security). We have foiled many attacks but some are difficult to control."

On January 20 the Taliban launched the first of two massive attacks in Kabul: an hours-long assault on a luxury hotel in which at least 25 people were killed.

One week later an ambulance laden with explosives detonated in a crowded street, killing more than 100 people and wounding hundreds more in one of the deadliest bomb blasts in Kabul in recent years.

On Monday many residents awoke to the sound of gunfire and explosions once more as ISIL militants attacked the battalion.

Relentless Taliban violence is not new to the city. But, analysts say, the insurgents' recent escalation is exacerbated by the lightning increase in ISIL attacks in the capital since 2016.

There is no reason to believe the Taliban and ISIL are partnering operationally, or conversely, competing to outdo each other, says Michael Kugelman of the Wilson Center in Washington, DC.

But "the cumulative effect of their attacks is simply devastating," he said.

As the Taliban ramps up its insurgency to drive out foreign forces and ISIL tries to expand its relatively small foothold in the country, Kabul is becoming more attractive for both groups, said Borhan Osman, a senior analyst with the International Crisis Group.

"Increasing pressure on the battlefield may be leading them to hit back in an area where they can publicly disprove the rhetoric of the US military or Afghan government that they have weakened the Taliban or IS," Mr Osman said using another acronym for ISIL.

That "can also shake public confidence in the government's ability to protect the population."

Western officials told AFP that the militants are adapting to new security measures, such as those implemented since a massive truck bomb in May 2017 killed around 150 and wounded about 400, in Kabul's deadliest attack since the US invasion.

Dozens of truck barriers, checkpoints and security cameras have been installed in the city's downtown and diplomatic areas.

Lorries entering Kabul via major roads are checked by security guards, sniffer dogs and scanners to ensure they are not carrying explosives, rockets or suicide vests.

Cars and their occupants are also physically examined by Afghan police.

The time-consuming checks result in hundreds of trucks waiting for hours before they can proceed - or being turned back if they do not have the correct paperwork.

But attackers continue to get through.

Groups such as ISIL have recruited students, professors and shopkeepers, who hide in the open as they help carry out assaults.

The US training mission is meant to help plug the gaps, but has not managed to do so despite years in the country, said Kugelman, with the recent attacks underscoring that progress is "nowhere near sufficient".

Militants operating in the city cannot be targeted with the amplified bombing campaigns used by the US in other parts of the country.

Some Afghan officials have acknowledged that the security measures in place are not foolproof, but appear to be at a loss as to how to fix the problem.

"It is beyond the capacity of the police to control" all the entrances, a security official said.

"Kabul has more than a hundred ways into the city."

As the city struggles to prepare for further strikes, Afghanistan's international allies are weighing the implications of the latest bloodshed.

NATO Secretary General Jens Stoltenberg said it was "essential to redouble efforts to achieve peace and reconciliation".

But US president Donald Trump on Monday threw into question Washington's long-standing policy of pushing the Taliban towards the negotiating table.

"We don't want to talk with the Taliban," Mr Trump said. "They are killing people left and right."

That carnage is unlikely to abate in the months ahead as militants - particularly the Taliban - come under pressure, according to Mr Osman.

"I'm afraid they are turning Kabul into the battlefield as a message to say 'if you are taking the gloves off we can also do this'."