Somalia’s perennial chaos makes the Shabab’s tendrils even harder to remove. Militant groups around the world dabble in the felonious, but the long history of anarchy in Somalia, whose central government imploded in 1991, creates the ideal environment for war profiteers.

Shabab militants are able to extract extortion fees, kidnap Western aid workers along the Kenyan border, collude with Indian Ocean pirates and then retreat to their strongholds with no worries about being arrested or prosecuted because law enforcement is virtually nonexistent in Somalia.

The country’s extreme poverty is another complicating factor. When the United States designated the Shabab a terrorist organization in 2008, setting off sanctions on material support for the group, aid agencies complained bitterly that the American rules were making it impossible to distribute lifesaving aid in Shabab-controlled areas. The American government relaxed the enforcement of some of these rules in 2011, when a famine swept through southern Somalia, to ensure that assistance got to the millions of Somalis who needed it.

While the Shabab control far less territory than they did a few years ago, many people in this region remain terrified of their network of assassins and their continued ability to stage large-scale attacks on civilians, like the massacre in the Kenyan mall or a suicide bombing in Uganda in 2010 that killed scores of people. And as the Shabab transform themselves from a guerrilla movement that once aspired to rule Somalia and fielded a large army of young fighters (Shabab means “youth” in Arabic) to a leaner and more mobile terrorist organization, their costs will go down.

Mr. Schanzer said the attack on the Nairobi mall probably cost the group “close to $100,000,” calculating the price of the automatic rifles, bullets and grenades that were used, along with training costs and possibly rent for a store in the mall that investigators suspect may have been used as a weapon depot before the attack.

Image East Africa's underworld helps to support the Shabab. Credit... The New York Times

Over the weekend, Kenya’s major newspapers reported that the country’s intelligence services had information about a potential strike on the mall but failed to act. American officials said that the warning had been based on fragmentary information and that they had no “actionable” or specific intelligence about the attack.