-
Notifications
You must be signed in to change notification settings - Fork 3
/
wp_malware_cleaner.sh
119 lines (96 loc) · 3.07 KB
/
wp_malware_cleaner.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
# Author name: Ruel Nopal
# Company: Nopla IT solution
# url: www.ruelnopal.com
# Function to install wp cli
install_wp_cli() {
echo "Installing WP CLI"
sudo wget https://raw.githubusercontent.com/wp-cli/builds/gh-pages/phar/wp-cli.phar
echo "Change Permission of WP CLI"
sudo chmod +x wp-cli.phar
echo "Move wp-cli.phar /usr/local/bin/wp"
sudo mv wp-cli.phar /usr/local/bin/wp
wp --info
echo "WP Cli Successfully Installed!"
}
# Function to create a directory
create_directory() {
echo "Creating the folder /$1 ..."
mkdir /$1
echo "Folder /$1 has been created"
}
# Function to move a file or directory
move_item() {
echo "Moving the $1 to the /$2 ..."
mv $1 /$2
echo "Successfully moved $1 to /$2"
}
# Function to download Wordpress files and check the checksum
download_fresh_wordpress() {
echo "Downloading fresh Wordpress files ..."
wget https://wordpress.org/latest.zip
echo "Download complete"
echo "Downloading checksum ..."
wget https://wordpress.org/latest.zip.md5
echo "Checksum download complete"
echo "Verifying checksum..."
md5sum -c latest.zip.md5
if [ $? -eq 0 ]; then
echo "Checksum verification passed!"
else
echo "Checksum verification failed!"
exit 1
fi
echo "Unzipping the Wordpress files ..."
unzip latest.zip
echo "Unzipping, complete"
echo "Moving the fresh Wordpress files to $1 ..."
mv wordpress/* $1
echo "Moving of fresh Wordpress files, complete"
}
# Check if wp cli is installed
if [ -f /usr/local/bin/wp ]; then
echo "Wp CLI is already installed in this machine!"
wp --info
else
install_wp_cli
fi
echo "Input the full path of your Wordpress installation folder..."
echo "If you don't know the detail, run <pwd> command from the Wordpress installation folder and the path will be output."
echo "It should be something like </home/user/wordpress> or </var/www/wordpress>"
read wordpress_path
if [ -z "$wordpress_path" ]; then
exit 1
fi
echo "Create a folder to store the important files?. The Default path is /"
echo "Input folder name: "
read folder_name
if [ -z "$folder_name" ]; then
exit 1
fi
create_directory $folder_name
move_item "$wordpress_path/wp-content" $folder_name
move_item "$wordpress_path/wp-config.php" $folder_name
echo "The next step requires the existing wordpress files to be delete."
echo "If you have important files that you don't have backup, please don't proceed."
read -p "Do you wish to proceedHere's the continuation and the conclusion of the updated bash script:
```bash
? [y/n] " yn
case $yn in
[Yy]* ) rm -rf $wordpress_path/*; break;;
* ) exit 1;;
esac
download_fresh_wordpress $wordpress_path
echo "Deleting default wp-content folder ..."
rm -rf $wordpress_path/wp-content
echo "Successfully deleted"
echo "Restoring the important files ..."
mv /$folder_name/wp-content /$folder_name/wp-config.php $wordpress_path
echo "Restoration complete"
echo "Cleaning un-utilized files/folders ..."
rm -rf latest.zip
rm -rf wordpress
update_remove_compromised "plugin"
update_remove_compromised "theme"
rm wp_malware_cleaner.sh
echo "Please check your site ..."