In just under a fortnight, leaders from some of the world's major economies will gather in South Africa's economic heartland, Johannesburg, for the G20 summit.

But just a few kilometres from the spruced-up, highly secure venue is a city centre which the authorities are struggling to improve and keep safe.

They face major challenges in cleaning up more than 100 derelict buildings, many plagued by rubbish and open sewage, some of which have been taken over by criminal gangs.

There's guns, there's drugs, there's prostitutes, there's everything here, said Nelson Khetani, resident of a building known as MBV1, located in Joubert Park.

Neglect and a lack of maintenance have left vandalised communal kitchens stripped of their fittings, while overflowing human waste covers parts of what used to be the laundry area.

Mr Khetani told BBC Africa Eye that rooms in MBV1 had been hijacked – a phenomenon where spaces or entire residential units are taken over and controlled by criminals to collect rent for themselves and, in some circumstance, provide a base for illegal activities.

The BBC has located and confirmed that there are 102 derelict or abandoned buildings in the inner city, an area of about 18 sq km (seven sq miles), but other media reports have cited much higher figures. Some of these have been hijacked and are unfit for human habitation.

The state of the city was on the mind of President Cyril Ramaphosa when talking about the G20 summit to the city council in March.

I found the city filthy, he said.

It is a painful sight to go through the centre of the city… you have a number of abandoned buildings, buildings that have been hijacked, that are not paying your rates and taxes.

Johannesburg Mayor Dada Morero said at the time that the city was ready to host the G20.

Last month, as part of a clean-up campaign across Johannesburg, the city council said the inner city had been targeted... for the systemic removal of pervasive lawlessness, illegal activities, hijacked properties, and critical by-law infringements.

But the challenges ahead of the world event are huge.

A fire at one of these derelict buildings that killed 76 people two years ago was supposed to spur people into action, but it seems not much has changed.

The BBC visited another inner-city building, Vannin Court, where rooms were covered in dirt and strewn with litter. A strong smell of human faeces permeated the building.

Resident Sinethemba Maqoma told the BBC that council-owned Vannin Court had been hijacked, and that the city council had cut off the water.

The municipality was angry about the crime from this building... that's why they took [away] the water, said another resident, Sinqhiwe Goodman Sithole.

Johannesburg's city council did not respond to the BBC's request for comment about Vannin Court's water supply.

There is also no electricity supply, Mr Maqoma said, adding that they use gas and solar lights.

The lack of utilities means residents cook food using portable gas tanks to power stoves. But without water or fire extinguishers nearby, the fire risks are huge.

Cars abandoned in the building's basement were partly submerged in human waste that was overflowing into an adjacent alleyway. Litter was floating on top of this slow-moving sludge of sewage.

Mr Maqoma showed the BBC a dark, unsanitary bathroom with a toilet that he said he flushes by pouring a bucket of water down it.

When you flush [the toilet], it goes through to the basement, he said.

Since apartheid and white-minority rule ended in 1994, many black and mixed-race residents moved from townships outside the city to the centre to be closer to their workplaces.

This large influx of people put intense pressure on the supply of adequate housing. Coupled with under-investment and the departure of many wealthy landlords, this led to many buildings falling into neglect, and some became havens for illegal activity like hijacking.

Joseph, which is not his real name, is a former hijacker who spoke to the BBC on condition of anonymity. He said he was hired by local criminals to clean a building and then put posters and write 'flat to rent'. But collecting the rent was not the main business.

The main business about the building is cooking the drugs, he said. They cook nyaope neat. Many buildings, plenty of them here in Jo'burg - they've been hijacked like that.

Nyaope is a highly addictive street drug in South Africa, often containing substances like low-grade heroin, cannabis, antiretroviral drugs, and in some cases even rat poison. It can cause abdominal pain, respiratory issues, and depression.

Joseph said he was haunted by those who may have suffered as a result of what happened where he operated.

Some of the time, when I'm sleeping, I can see people, I see people. People died in these buildings. People went missing. I'm sorry for the wrong path in my life, he told the BBC.

Joseph claimed that evictions were prevented by having a good relationship with [the] city council and police, which was a matter of [a] cash bribe.

When asked about the allegations of collusion with building hijackers, the City of Johannesburg's deputy director of communications, Nthatisi Modingoane, said the council had no physical or credible reports that suggested there was any wrongdoing.

Mr Modingoane added that the council will intensify its operations tackling criminal activity in hijacked buildings and make sure that we clean the city.

The eviction of the residents of these derelict and hijacked buildings sounds like the simple answer to the problem.

That could lead to much-needed redevelopment. But it would be an expensive exercise and legally not straightforward.

In the first place, South Africa's constitution protects the right of people to have a home.

This means once a person is settled in a building and they can prove they have nowhere else to go, they cannot be forced out unless the state provides alternative accommodation.

This imposes a cost on the local authority, and moving people out of a building is expensive in itself.

Johannesburg Central's sheriff, whose jurisdiction covers part of the inner city, said evictions could not be carried out on a larger scale or frequently because of financial constraints.

Back in March, the president highlighted the importance for Johannesburg's hijacked buildings to be turned into living accommodations where our people can live lives of dignity.

But for many residents here, that vision remains hollow.

At the MBV1 building, Mr Khetani said he had been living there since 2008 even though it was supposed to be temporary accommodation.

The city has no money and nobody cares.