Waarom 777 een slecht idee is (hosting)

Uit De Vliegende Brigade
Versie door Jeroen Strompf (overleg | bijdragen) op 29 feb 2020 om 15:44 (→‎Het verzwakt het hele systeem)
(wijz) ← Oudere versie | Huidige versie (wijz) | Nieuwere versie → (wijz)
Naar navigatie springen Naar zoeken springen

Ik host sites op eigen VPS'en. Daarbij maak ik gebruik van Apache als webserver. Het configureren van rechten op bestanden en mappen, is een complex klusje. Ik weet dat het een slecht idee is om mappen/bestanden kenmerk 777 te geven (=gebruiker, groep & other kunnen lezen, schrijven en executeren): Je loopt een groot risico om gehacked te worden, als other mag schrijven en executeren.

Echter, waarom is dat precies???

Voorbeeld: Uploaden & executeren van scripts ipv. afbeeldingen?

Als een bezoeker afbeeldingen kan uploaden, kan hij/zij een PHP-bestand uploaden (desgewenst met de extentie .jpg want dat maakt Linux niet uit) en dat vervolgens executeren. Dan kan hij/zij de site overnemen, en met een beetje pech de hele webserver. Ik weet dat dit voorkomt: Een enkele keer heb ik te maken met een gehackte site, waarbij er inderdaad php-bestanden in de map media zijn beland.

Maar hoe belanden die scripts daar? Gebruikers mogen standaard niet eens een profielafbeelding uploaden. Misschien is er al eerder ergens een fout?

Het verzwakt het hele systeem

Ik denk dat ik het heb gevonden [1] (licht herschreven):

When you chmod 777 your website, you have no security whatsoever. Any user on the system can 
change or delete any file in your website. But more seriously, remember that the web server 
acts on behalf of visitors to your website, and now the web server is able to change the files
that it's executing. 

If there are any programming vulnerabilities in your website, they can be exploited to deface
your website, insert phishing attacks, or steal information from your server without you ever
knowing.

Deze post bevestigt dit: Het vormt niet direct een probleem, maar maakt eventuele problemen wel een stuk erger:

If the attacker only has access to the web interface (not to the files, say, via another account 
on the same shared hosting) then mode 777 doesn't directly open any vulnerabilities. What it 
does is make it easier for the attacker to change things on the site once they get in some other 
way.

For instance, suppose you have a WordPress site and there's a bug somewhere that allows the 
attacker to execute arbitrary PHP code under the credentials of the server daemon (this has 
happened many times in the past and will no doubt happen again in the future). The code for 
WordPress itself is stored in .php files that the server daemon can read. If those files are 
mode 777 then the attacker can write to them - which means they can modify the code - changing 
what your site does. Perhaps they install a "drive by exploit" kit and now everyone who visits 
your site gets their browser hacked. Perhaps they install a SEO spam kit and now Google thinks 
you're selling Viagra (but if you visit the site directly it's invisible -- yes, this really 
happens).

Samenvatting: Het hoeft geen probleem te zijn, maar als je ook maar de geringste zwakte hebt rondom je webserver, wordt het wél een probleem.

Zie ook