Kandahar, the second largest city in Afghanistan, is largely in the hands of Moslem guerrillas, who have government posts on the defensive and frequently under siege, according to a free-lance photographer who spent most of last month in and around the city.

Soviet troops are rarely seen in the southern Afghan city, but stay outside it at the heavily guarded airport, said Terence White, 35, of New Zealand.

A similar situation prevailed in the third largest city, Herat, at least as recently as October, according to Dominique Vergos, a French photographer who emerged then from more than a year of traveling with the guerrillas in Afghanistan. Vergos said armed Afghan guerrillas known as mujaheddin were able to ride around openly in jeeps, and he estimated that they controlled about three-fourths of Herat, a city in western Afghanistan near the Iranian border that is rarely visited by westerners.

The accounts of White and Vergos during visits to Bangkok last week indicated that more than five years after the Soviets invaded Afghanistan, they face growing problems in trying to crush the Moslem guerrillas and build up the Moscow-installed government of Babrak Karmal.

The mujaheddin long have been reported to have effective control of the countryside, with the Soviet occupation troops -- estimated to be 115,000 -- dominating the cities and major roads. But the descriptions by White and Vergos of such a tenuous grip on the two largest cities after the capital, Kabul, point to potentially serious problems for the Soviets and their Afghan government proteges.

Afghan guerrilla leaders interviewed across the Pakistani border in Peshawar earlier this month said the fighting in Kandahar had been the fiercest of any winter since the Soviet invasion in 1979. Although the leaders said they were in control of most of Kandahar Province, the resistance forces have been hampered by several factors.

Gulbaddin Hekmatyar, who heads the fundamentalist Hizbi Islami group that has units fighting in Kandahar, said the Soviets are shifting their attacks from the central provinces to border provinces such as Kandahar. Their air raids, he said, have been disrupting the flow of food, ammunition and -- most important now -- warm clothing.

The photographers described extensive Soviet air operations, including almost daily strikes on Kandahar and surrounding villages by bombers and helicopters, as the Soviets appear to rely increasingly on their unmatched air power. Despite reports of an increasing flow of arms to the guerrillas from foreign donors, the guerrillas still lack sufficient antiaircraft weapons with which to resist the Soviet air strikes, the photographers said.

White said he left for Afghanistan from neighboring Pakistan with a convoy of eight jeeps in which the mujaheddin were carrying arms, ammunition and other supplies into the Kandahar area. He said that while they drove mostly at night through the desert, switching off headlights when approaching government posts, they occasionally -- to his surprise -- used main roads without incident.

In the countryside, armed mujaheddin even traveled freely on public buses carrying their Kalashnikov rifles, White said.

On entering Kandahar, White said, he found normal day-to-day activities in the city's bazaar area, with shops selling flat loaves of Afghan bread, meat, fruit, vegetables and other items, while armed guerrillas walked around casually.

Outside one tea shop, White said, an Afghan was cleaning a light machine gun. He said that when he asked the guerrillas what would happen if a patrol of Soviet or Afghan soldiers came into the bazaar, the mujaheddin laughed at what they regarded as a naive question.

"They don't, because they would be captured or killed," he quoted Mullah Mohammed Zay, a local commander from the Jamiat-i-Islami guerrilla organization, as saying.

White said that on another