Advertisement
adamreece-webbox

remove-wp-toolkit.sh

Mar 16th, 2021
1,302
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.99 KB | None | 0 0
  1. #!/bin/bash
  2. # /root/remove-wp-toolkit.sh
  3.  
  4. printf "Removing cPanel WordPress Toolkit infection from customer sites\n"
  5.  
  6. if [[ $EUID -ne 0 ]]; then
  7.    printf "[Error] This script must be run as root.\n"
  8.    exit 1
  9. fi
  10.  
  11. consent=0
  12. consent_message="[Modification skipped. Run again with option \"--consent\" you accept this modification."
  13.  
  14. if [[ -n "$1" ]] && [[ $1 == "--consent" ]]; then
  15.     printf "[Warning] Consent to modify has been specified.\n"
  16.     consent=1
  17. fi
  18.  
  19.  
  20.  
  21. printf "\n\n\nScanning user home folders...\n"
  22.  
  23. for user_home_root in $(find /home/ -maxdepth 1 -type d ! -path /home/ | sort); do
  24.     user_name=$(basename "${user_home_root}")
  25.     printf "\nScanning user ${user_name} at path \"${user_home_root}\":\n"
  26.  
  27.     if [ -d "${user_home_root}/.wp-toolkit/" ]; then
  28.         printf " - Removed \"/.wp-toolkit/\"\n"
  29.  
  30.         if [ $consent -ge 1 ]; then
  31.             rm -rf "${user_home_root}/.wp-toolkit/"
  32.         else
  33.             echo $consent_message
  34.         fi
  35.     fi
  36.  
  37.     if [ -f "${user_home_root}/.wp-toolkit-identifier" ]; then
  38.         printf " - Removed \"/.wp-toolkit-identifier\"\n"
  39.  
  40.         if [ $consent -ge 1 ]; then
  41.             rm -f "${user_home_root}/.wp-toolkit-identifier"
  42.         else
  43.             echo $consent_message
  44.         fi
  45.     fi
  46.  
  47.     if [ -d "${user_home_root}/wordpress-backups/" ]; then
  48.         printf " - Removed \"/wordpress-backups/\"\n"
  49.  
  50.         if [ $consent -ge 1 ]; then
  51.             rm -rf "${user_home_root}/wordpress-backups/"
  52.         else
  53.             echo $consent_message
  54.         fi
  55.     fi
  56. done
  57.  
  58.  
  59.  
  60. printf "\n\n\nScanning WordPress installations in user sites...\n"
  61.  
  62. for site_htdocs_root in $(cat /etc/userdatadomains | cut -d"=" -f9 | sort); do
  63.     if [ ! -f "${site_htdocs_root}/wp-config.php" ]; then
  64.         continue; # If this file is present then we likely don't have a WordPress installation
  65.     fi
  66.  
  67.     printf "\nScanning site at path \"${site_htdocs_root}\":\n"
  68.  
  69.     if grep -q "define('WP_AUTO_UPDATE_CORE', 'minor');// This setting is required to make sure that WordPress updates can be properly managed in WordPress Toolkit. Remove this line if this WordPress website is not managed by WordPress Toolkit anymore." "${site_htdocs_root}/wp-config.php"; then
  70.         printf " - Cleaned \"/wp-config.php\"\n"
  71.  
  72.         if [ $consent -ge 1 ]; then
  73.             sed -e "${site_htdocs_root}/wp-config.php" -i "s|define('WP_AUTO_UPDATE_CORE', 'minor');// This setting is required to make sure that WordPress updates can be properly managed in WordPress Toolkit. Remove this line if this WordPress website is not managed by WordPress Toolkit anymore.||g"
  74.         else
  75.             echo $consent_message
  76.         fi
  77.     fi
  78.  
  79.     if [ -d "${site_htdocs_root}/wp-content/maintenance/" ]; then
  80.         printf " - Removed \"/wp-content/maintenance/\"\n"
  81.  
  82.         if [ $consent -ge 1 ]; then
  83.             rm -rf "${site_htdocs_root}/wp-content/maintenance/"
  84.         else
  85.             echo $consent_message
  86.         fi
  87.     fi
  88.  
  89.     if [ -f "${site_htdocs_root}/wp-content/maintenance.php" ]; then
  90.         printf " - Removed \"/wp-content/maintenance.php\"\n"
  91.  
  92.         if [ $consent -ge 1 ]; then
  93.             rm -rf "${site_htdocs_root}/wp-content/maintenance.php"
  94.         else
  95.             echo $consent_message
  96.         fi
  97.     fi
  98. done
  99.  
  100.  
  101.  
  102. exit 0
  103.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement