Quick & Dirty Bashscript zum WordPress von Viren befreien

Wenn man viele Installationen von Viren befreien will hat man irgendwann schlichtweg keine Lust mehr das alles manuell zu machen. Aber wofür gibt es Bashscripte. Hier gibts nun eins, was ziemlich quick & dirty ist, aber seinen Zweck erfüllt. Ich kommentiere das jetzt nicht groß, man muss es eh manuell anpassen wenn man es nutzen will, ein wenig Bash-Kenntnisse braucht man somit eh, und damit versteht es sich von selbst.

Dass der Kram auf einem Webspace lag war eine gewisse Herausforderung. Aber wofür hat man als Linux / Mac-User curlftpfs. Also – man mountet den gesamten Webspace nach /media/ftp und kann wie lokal an den Dateien arbeiten. In /media/clean lag eine virenfreie Installation mit allen Plugins und Themes aus der Liste im Bashscript, die als Vorlage diente.

Der Code ist sicher noch optimierbar, man könnte z.B. ein Scan nach zusätzlichen und somit möglicherweise gefährlichen Dateien hinzufügen, man könnte auf nicht behandelte Themes und Plugins aufmerksam machen, aber ich brauchte das jetzt gerade nicht, also ist es nicht dabei. Vielleicht kann das ja irgendwer als Codeschnipsel brauchen:

#!/bin/bash

for INSTALLATION in "einblog" "nocheinblog" "naechstesblog"
do

cd /media/ftp/www/$INSTALLATION/

echo "Current Installation: $INSTALLATION"

# files in base folder
echo "Write Base Files"
rm -rf wp-activate.php wp-load.php wp-trackback.php index.php wp-admin wp-login.php xmlrpc.php license.txt wp-blog-header.php wp-cron.php wp-mail.php liesmich.html wp-comments-post.php wp-includes wp-settings.php readme.html wp-config-sample.php wp-links-opml.php wp-signup.php wp-pass.php wp-register.php
cp -R  ../../../clean/index.php ../../../clean/wp-activate.php ../../../clean/wp-config-sample.php ../../../clean/wp-links-opml.php ../../../clean/wp-settings.php ../../../clean/license.txt ../../../clean/wp-admin ../../../clean/wp-load.php ../../../clean/wp-signup.php ../../../clean/liesmich.html ../../../clean/wp-blog-header.php ../../../clean/wp-cron.php ../../../clean/wp-login.php ../../../clean/wp-trackback.php ../../../clean/readme.html ../../../clean/wp-comments-post.php ../../../clean/wp-includes ../../../clean/wp-mail.php ../../../clean/xmlrpc.php ../../../clean/wp-pass.php ../../../clean/wp-register.php ./
cp ../../../clean/wp-content/index.php wp-content/


# themes
echo "Write Themes"
for THEME in "twentyfourteen" "twentythirteen" "twentytwelve" "twentyeleven" "twentyten"
do
        if [ -d "./wp-content/themes/$THEME/" ]; then
                rm -rf wp-content/themes/$THEME/
                cp -a ../../../clean/wp-content/themes/$THEME wp-content/themes/$THEME
        fi
done
cp ../../../clean/wp-content/themes/index.php wp-content/themes/

#languages
echo "Write Languages"
cp ../../../clean/wp-content/languages/*.po ../../../clean/wp-content/languages/*.mo wp-content/languages/
cp ../../../clean/wp-content/languages/themes/*.po ../../../clean/wp-content/languages/themes/*.mo wp-content/languages/themes/
cp ../../../clean/wp-content/languages/plugins/*.po ../../../clean/wp-content/languages/plugins/*.mo wp-content/languages/plugins/

# plugins
echo "Write Plugins"
for PLUGIN in "advanced-custom-fields" "all-in-one-favicon" "akismet" "antispam-bee" "automatic-seo-links" "german-slugs" "google-sitemap-generator" "pretty-link" "statify" "svegliat-buttons" "table-of-contents-plus" "tablepress"  "wordpress-seo" "wplike2get"
do
        if [ -d "./wp-content/plugins/$PLUGIN/" ]; then
                rm -rf wp-content/plugins/$PLUGIN/
                cp -a ../../../clean/wp-content/plugins/$PLUGIN wp-content/plugins/$PLUGIN
        fi
done
cp ../../../clean/wp-content/plugins/index.php ../../../clean/wp-content/plugins/hello.php wp-content/plugins/

# prepare upgrading and correct file rights
echo "prepare upgrading and correct file rights"
mkdir wp-content/tmp
find /media/ftp/www/$INSTALLATION/ -type d -exec chmod 750 {} +
find /media/ftp/www/$INSTALLATION/ -type f -exec chmod 640 {} +
find /media/ftp/www/$INSTALLATION/wp-content/uploads/ -type d -exec chmod 770 {} +
find /media/ftp/www/$INSTALLATION/wp-content/uploads/ -type f -exec chmod 660 {} +

done

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht.