Find all WordPress folders with 777 permissions

How to find all folders with 777 permissions


As the owner of a dedicated server provided shared hosting services, you will find that many of your clients will install applications such as WordPress. So far so good. However, once they start getting stuck with file and folder permissions, they generally go crazy and set everything to 777 in order to fix the problems. Great, they get their site working! Now begin your problems.

With these liberal file and folder permissions together with some not-so-well written plugins, it is only a matter of time before the hackers and crackers target these weak WordPress sites and start injecting all manner of redirects and mail spammers on your server.

Using ‘find’ to locate those weaknesses

So, here is a nifty solution to find all those weak WordPress installations. The following find will list all WordPress installations that contain folders with 777 permissions:

find /var/www/vhosts/*/httpdocs/wp-content -perm 0777 -type d | grep -v "wp-content/"

Give this a whirl on your Plesk server and take a look at the list, navigate to each folder and tighten up the permissions as below:

cd /var/www/vhosts/dodgydomain.co.uk/httpdocs
find . -type d -exec chmod 755 {} \;
find . -type f -exec chmod 644 {} \;
chmod 750 ../httpdocs

These permission changes eliminate all unnecessary 777 permissions.

Ok, let’s automate the whole process

What? You have lots of these? Then here is a nifty script to automate the process for you:

df=`find /var/www/vhosts/*/httpdocs/wp-content -perm 0777 -type d | grep -v "wp-content/" \
| sed "s/wp-content//g"`

for line in $df;
  do
    echo $line
    cd $line
    find $line -type d -exec chmod 755 {} \;
    find $line -type f -exec chmod 644 {} \;
    chmod 750 $line
  done

This makes things a little more difficult for any would-be injection attempts. If your directory structure is different to the standard Plesk structure simply modify the find command as required.

Was this helpful?
Find all WordPress folders with 777 permissions written by UKC average rating 5/5 - 2 user ratings