By Gary Duffy
BBC News, Rio de Janeiro
The sprawling favelas of Rio de Janeiro are home to more than a million of Brazil's poorest citizens.
Militia groups claim to offer protection to poor communities
Many of these shanty towns are controlled by drug gangs, and there are regular and violent confrontations with the police.
But a growing number of these neighbourhoods are being taken over by what are known here as militias, complicating an already difficult security situation.
These are vigilante-style operations run by off-duty or former police officers and firemen, who throw out the drug gangs and claim to offer protection to the community, but at a price.
"The payments we have discovered they get are very attractive," Rio police investigator Claudio Ferraz told the BBC News website.
"Because literally they occupy an area and charge a fee or a payment, almost like a tax inside that community, like a lord of the manor. They have complete power over some areas."
Militias have been around for some time, but analysts believe the number has been growing in recent years, while the authorities insist they are trying to deal with the threat.
However while there has been some police action against suspected militia groups, questions have also been raised about whether the police in Rio can deal effectively with corruption among their colleagues.
In the favelas, few want to talk openly about militias - and one representative from a local community group would only speak without being identified.
"They control everything, they make demands, they kill. If you don't follow their way and do what they say, you go straight to the grave," the woman said.
'Safest area in Rio'
Critics say it is the failure of the state to establish itself in Rio's poorest communities which has allowed the drug gangs and militias to move in and take over.
The favela of Tavares Bastos seems to show that things can be different.
With a spectacular view of Rio de Janeiro this is one of the few shanty towns in Rio de Janeiro not controlled by drug gangs or militias.
The reasons for this are obvious - just a short distance up the hill is the headquarters of Bope, the heavily-armed elite squad of Rio's police.
Not everyone in Rio admires the city's elite police unit, which has been accused of many human rights violations. But in the community of Tavares Bastos people say the proximity of this specialist force has brought a unique quality of life to their favela.
Congressman Jair Bolsonaro suggests legalising the militias
"This community has become, with Bope here, the safest area in Rio de Janeiro," says one man. "We don't have any more drug traffickers or thieves, and our children can live peacefully, without fear."
A woman added: "We don't have traffickers here any more, we don't have robbers. Now, it's very quiet."
But in other parts of Rio the picture is more sinister, and as many as 100 of the more than 700 favelas in Rio may now be controlled by militias, although the authorities say it is difficult to be exact.
And while the state government in Rio says it wants to eliminate these self-appointed vigilantes, at least one politician puts forward a controversial argument for a different approach.
"They offer security and in this way they can maintain order and discipline in their communities - what they call militias," says Jair Bolsonaro, a deputy in the Brazilian congress.
"The government should support them, as they don't have the ability to combat the drug traffickers - and perhaps in the future they should legalise them."
'Kind of dictatorship'
It seems in some communities there is a level of acceptance, even support for militias, as a preferred alternative to drug gangs, and this can also reflect a lack of trust in the police.
But the authorities and other observers say militias control communities using fear and violence, demanding payments for services such as gas and cable TV, even at times controlling access to the internet.
There are not enough police for every community, an ex-officer says
"I think militias are much worse than drug traffickers," said Gilberto Ribeiro, Rio's police chief.
"They fight the traffickers because they want to take over the area and afterwards they start to subjugate the people and create illegal benefits for their own good."
"It's really frightening to realise that these people in these poor communities are living under a different kind of dictatorship," says Julita Lemgruber, director of the centre of studies of security and citizenship at the University of Candido Mendes in Rio.
"These are groups that are illegally armed and illegally controlling a territory."
For one experienced former police officer the reasons all this has happened is obvious.
"There aren't enough police to occupy 700 favelas," former police captain Rodrigo Pimentel told Brazil's TV Globo network in a special report on militias. "This is a fact.
"The militias place protection shifts with 15, 20 or 40 men in the communities. The average is around 15 to 20. They implement their protection shifts which have a price. So it is not easy.
"The state cannot do it - to occupy 700 communities - and the militia can."
For the often beleaguered communities of Rio's favelas, the militias say they offer security the state has failed to provide.
In reality, it seems they are just another indication of the violence and lack of proper government which continues to blight the lives of those who live here.