KABUL, Afghanistan — The Taliban are not as lonely as they once were. The pariahs who protected Osama bin Laden and quickly collapsed when the U.S. counter-attacked after September 11, 2001, have been developing contacts with neighboring states and even with Russia, driven out of Afghanistan in 1989.

There’s nothing simple about this picture, and, interestingly, it appears partly tied to Russian efforts to oppose the spread in Afghanistan of groups pledging allegiance to the so-called Islamic State in Syria and Iraq. That same concern has helped to forge links between the Taliban and their longtime enemies in Iran.

And the Russian connection is emerging, ironically, at the same time that Afghanistan’s Uzbek warlord and vice president, Abdul Rashid Dostum, has openly warmed to his onetime allies in Russia and tried to strengthen ties to the former Soviet states on Afghan frontier.

Dostum visited Moscow and Grozny this month and launched an offensive just last week in provinces near the Turkmenistan border. Dostum lumped the Taliban together with Daesh, a common Arabic acronym for the Islamic state, on his enemies list.

“The countries of the Commonwealth of Independent States from Russia to Tajikistan and Turkmenistan, all these states are willing to stand with us against Daesh [one of the acronyms for the so-called Islamic State], against extremism, against the bloodthirsty Taliban,” Dostum declared.

But The Daily Beast has learned that Russia and some of these neighboring states may be playing a double game, or, at the very least keeping their options open if the Taliban manage to retake power.

A former Afghan Taliban governor and member of the group’s military committee, who does not want to be cited by name, tells The Daily Beast that “the American global attitude and the threat from ISIS makes for a convergence of Taliban and Russian interests, and we could not rule out further cooperation, depending on the emerging scenario in the Middle East.”

That is, if Russia proves successful in its Syrian venture to defend the Assad dictatorship (which is far from certain), the Taliban will be encouraged to increase their contacts and perhaps cooperation with the government of Russian President Vladimir Putin.

But for now the contacts with Moscow are being kept very quiet and often are conducted through cut-outs. The main venue for the talks is Tajikistan, just north of Afghanistan’s embattled Kunduz province, whose intelligence operatives may have been involved with a substantial shipment of arms to the Taliban. The government and intelligence services of Tajikistan are understood by the Taliban to have remained close clients of Moscow.

“Tajikistan is under the extreme influence of the Russians, so whatever happened, it’s not possible without Russians approval,” said the former Taliban governor.

When the Taliban seized the city of Kunduz at the end of last month, the group’s new leader, Mullah Akhtar Muhammad Mansoor, was careful to say that the Taliban presented no threat and had not intention of infiltrating beyond Afghanistan’s borders.

Some sources suggest the contacts go back to 2013 and were opened at the request of the Russians, but the clearest narrative is much more recent.

One central figure is Dr. Tahir Shamalzi, the younger brother of a former Taliban leader, who headed a delegation of what’s widely known as the Taliban “ransom and peace committee” that visited the Tajikistan capital of Dushanbe last May. At the time, the Taliban were holding prisoner four Tajikistan border guards who apparently had been sent across the river that marks the frontier with Afghanistan to cut wood.

Shamalzai was traveling with a fake passport, according to our sources. The intermediary for the talks in Dushanbe allegedly is one Ibrahim Achakzai, who has a scrap metal business there.

In exchange for the guards’ release, the Taliban wanted weapons. “Dr. Tahir Shamalzai traveled from Kabul airport to Dushanbe, inspected the weapons, and crossed with the weapons from Tajikistan into Afghanistan,” a senior Taliban leader tells The Daily Beast.

How many weapons? Our sources us words like “big” and “significant,“ but won’t go into details. A Taliban sub-commander in Kunduz who goes by the name Qari Omar tells The Daily Beast that the then-commander of forces there, Mullah Rahmatullah, was pleased with the deal and gave the four Tajik guards turbans and Afghan dress before turning them over to a Tajik border post.

As it happens, Mullah Rahmatullah was killed in Kunduz during the U.S.-led bombing that accompanied the government counterattack, which had a certain air of desperation after a major city had fallen to the Taliban for the first time since 2001.

“Of course the weapons we got freshly from the Afghan-Tajk border played a key role in the fight for Kunduz,” said Sub-Commander Qari Omar.

A diplomatic source says Pakistan, which has close ties to the Afghan Taliban, is aware of the Taliban contacts with the Russians, and some former Taliban say they are surprised anyone is surprised. “If we could talk to the West, what’s wrong talking to Russians and Afghanistan’s neighbors in north?” as one put it.

At a peace conference in Qatar last summer, according to Qustad Qari Bu-Rahman, who attended on behalf of Hizb Islami Afghanistan (the Hikmatyar group), “A Russian who spoke perfect Pashto was there as an observer. He was called on demand of the Taliban, so there’s no doubt about the Taliban and Mosco having contact.”

It appears the Taliban and Russians first made direct contact in mid-2013 to discuss the fate of a Russian pilot captured after his helicopter made an emergency landing in an area near Kabul under Taliban influence.

“That release was also part of a weapons and money deal,” a senior Afghan leader told The Daily Beast.

Taliban sources says Dr. Tahir Shamalzi and others have made several trips to China as well as to the former Soviet republics. China is said to be concerned about a small numbers of East Turkestan Independence Movement fighters, Uyghurs from Xinjiang, who are living in southern Afghanistan.

“We told them they are in Afghanistan, and we could stop them from making anti-Chinese activities, but we could not hand over or displace from our areas,” the former Taliban governor told The Daily Beast.

(Afghan government sources, on the other hand, say that last year President Ashraf Ghani handed over several members of the East Turkistan Independence Movement to the Chinese in Kabul.)

Will Taliban contacts with the once-hostile neighbors go far beyond hostage deals? A common refrain in Kabul diplomatic circles contends that the Taliban are turning away from any plans to support international terrorist groups, and focusing on their role as local Afghan resistance fighters opposed not only to Ghani’s government and the American presence, but to ISIS as well.