sucuri-scanner
Last commit date
inc
8 years ago
languages
8 years ago
src
8 years ago
LICENSE
14 years ago
index.html
11 years ago
readme.txt
8 years ago
sucuri.php
8 years ago
sucuri.php
302 lines
| 1 | <?php |
| 2 | |
| 3 | /** |
| 4 | * Plugin Name: Sucuri Security - Auditing, Malware Scanner and Hardening |
| 5 | * Description: The <a href="https://sucuri.net/" target="_blank">Sucuri</a> plugin provides the website owner the best Activity Auditing, SiteCheck Remote Malware Scanning, Effective Security Hardening and Post-Hack features. SiteCheck will check for malware, spam, blacklisting and other security issues like .htaccess redirects, hidden eval code, etc. The best thing about it is it's completely free. |
| 6 | * Plugin URI: https://wordpress.sucuri.net/ |
| 7 | * Author URI: https://sucuri.net/ |
| 8 | * Text Domain: sucuri-scanner |
| 9 | * Author: Sucuri Inc. |
| 10 | * Version: 1.8.7 |
| 11 | */ |
| 12 | |
| 13 | |
| 14 | /** |
| 15 | * Main file to control the plugin. |
| 16 | * |
| 17 | * The constant will be used in the additional PHP files to determine if the |
| 18 | * code is being called from a legitimate interface or not. It is expected that |
| 19 | * during the direct access of any of the extra PHP files the interpreter will |
| 20 | * return a 403/Forbidden response and immediately exit the execution, this will |
| 21 | * prevent unwanted access to code with unmet dependencies. |
| 22 | * |
| 23 | * @package Sucuri Security |
| 24 | * @author Daniel Cid <dcid@sucuri.net> |
| 25 | * @license Released under the GPL. |
| 26 | * @copyright Since 2010 Sucuri Inc. |
| 27 | * @since File available since Release 0.1 |
| 28 | * @link https://wordpress.org/plugins/sucuri-scanner/ |
| 29 | * @link https://wordpress.sucuri.net/ |
| 30 | */ |
| 31 | define('SUCURISCAN_INIT', true); |
| 32 | |
| 33 | /** |
| 34 | * Plugin dependencies. |
| 35 | * |
| 36 | * List of required functions for the execution of this plugin, we are assuming |
| 37 | * that this site was built on top of the WordPress project, and that it is |
| 38 | * being loaded through a pluggable system, these functions most be defined |
| 39 | * before to continue. |
| 40 | * |
| 41 | * @var array |
| 42 | */ |
| 43 | $sucuriscan_dependencies = array( |
| 44 | 'wp', |
| 45 | 'wp_die', |
| 46 | 'add_action', |
| 47 | 'remove_action', |
| 48 | 'wp_remote_get', |
| 49 | 'wp_remote_post', |
| 50 | ); |
| 51 | |
| 52 | /* terminate execution if dependencies are not met */ |
| 53 | foreach ($sucuriscan_dependencies as $dependency) { |
| 54 | if (!function_exists($dependency)) { |
| 55 | /* Report invalid access if possible. */ |
| 56 | header('HTTP/1.1 403 Forbidden'); |
| 57 | exit(0); |
| 58 | } |
| 59 | } |
| 60 | |
| 61 | /* check if installation path is available */ |
| 62 | if (!defined('ABSPATH')) { |
| 63 | /* Report invalid access if possible. */ |
| 64 | header('HTTP/1.1 403 Forbidden'); |
| 65 | exit(0); |
| 66 | } |
| 67 | |
| 68 | /** |
| 69 | * Plugin's constants. |
| 70 | * |
| 71 | * These constants will hold the basic information of the plugin, file/folder |
| 72 | * paths, version numbers, read-only variables that will affect the functioning |
| 73 | * of the rest of the code. The conditional will act as a container helping in |
| 74 | * the readability of the code considering the total number of lines that this |
| 75 | * file will have. |
| 76 | */ |
| 77 | |
| 78 | /** |
| 79 | * Unique name of the plugin through out all the code. |
| 80 | */ |
| 81 | define('SUCURISCAN', 'sucuriscan'); |
| 82 | |
| 83 | /** |
| 84 | * Current version of the plugin's code. |
| 85 | */ |
| 86 | define('SUCURISCAN_VERSION', '1.8.7'); |
| 87 | |
| 88 | /** |
| 89 | * The name of the Sucuri plugin main file. |
| 90 | */ |
| 91 | define('SUCURISCAN_PLUGIN_FILE', 'sucuri.php'); |
| 92 | |
| 93 | /** |
| 94 | * Unique name of the plugin text domain. |
| 95 | */ |
| 96 | define('SUCURISCAN_TEXTDOMAIN', 'sucuri-scanner'); |
| 97 | |
| 98 | /** |
| 99 | * The name of the folder where the plugin's files will be located. |
| 100 | * |
| 101 | * Note that we are using the constant FILE instead of DIR because some |
| 102 | * installations of PHP are either outdated or are not supporting the access to |
| 103 | * that definition, to keep things simple we will select the name of the |
| 104 | * directory name of the current file, then select the base name of that |
| 105 | * directory. |
| 106 | */ |
| 107 | define('SUCURISCAN_PLUGIN_FOLDER', basename(dirname(__FILE__))); |
| 108 | |
| 109 | /** |
| 110 | * The fullpath where the plugin's files will be located. |
| 111 | */ |
| 112 | define('SUCURISCAN_PLUGIN_PATH', WP_PLUGIN_DIR . '/' . SUCURISCAN_PLUGIN_FOLDER); |
| 113 | |
| 114 | /** |
| 115 | * The fullpath of the main plugin file. |
| 116 | */ |
| 117 | define('SUCURISCAN_PLUGIN_FILEPATH', SUCURISCAN_PLUGIN_PATH . '/' . SUCURISCAN_PLUGIN_FILE); |
| 118 | |
| 119 | /** |
| 120 | * The local URL where the plugin's files and assets are served. |
| 121 | */ |
| 122 | define('SUCURISCAN_URL', site_url(dirname(str_replace(ABSPATH, '', SUCURISCAN_PLUGIN_FILEPATH)))); |
| 123 | |
| 124 | /** |
| 125 | * Remote URL where the public Sucuri API service is running. |
| 126 | * |
| 127 | * We will check if the constant was already set to allow developers to use |
| 128 | * their own API service. This is useful both for the execution of the tests |
| 129 | * as well as for website owners who do not want to send data to the Sucuri |
| 130 | * servers. |
| 131 | */ |
| 132 | if (!defined('SUCURISCAN_API_URL')) { |
| 133 | define('SUCURISCAN_API_URL', 'https://wordpress.sucuri.net/api/'); |
| 134 | } |
| 135 | |
| 136 | /** |
| 137 | * Latest version of the public Sucuri API. |
| 138 | */ |
| 139 | define('SUCURISCAN_API_VERSION', 'v1'); |
| 140 | |
| 141 | /** |
| 142 | * Remote URL where the firewall API service is running. |
| 143 | */ |
| 144 | define('SUCURISCAN_CLOUDPROXY_API', 'https://waf.sucuri.net/api'); |
| 145 | |
| 146 | /** |
| 147 | * Latest version of the firewall API. |
| 148 | */ |
| 149 | define('SUCURISCAN_CLOUDPROXY_API_VERSION', 'v2'); |
| 150 | |
| 151 | /** |
| 152 | * The maximum quantity of entries that will be displayed in the last login page. |
| 153 | */ |
| 154 | define('SUCURISCAN_LASTLOGINS_USERSLIMIT', 25); |
| 155 | |
| 156 | /** |
| 157 | * The life time of the cache for the audit logs to help API perforamnce. |
| 158 | */ |
| 159 | define('SUCURISCAN_AUDITLOGS_LIFETIME', 600); |
| 160 | |
| 161 | /** |
| 162 | * The maximum quantity of entries that will be displayed in the audit logs page. |
| 163 | */ |
| 164 | define('SUCURISCAN_AUDITLOGS_PER_PAGE', 50); |
| 165 | |
| 166 | /** |
| 167 | * The maximum quantity of buttons in the paginations. |
| 168 | */ |
| 169 | define('SUCURISCAN_MAX_PAGINATION_BUTTONS', 16); |
| 170 | |
| 171 | /** |
| 172 | * Frequency of the file system scans in seconds. |
| 173 | */ |
| 174 | define('SUCURISCAN_SCANNER_FREQUENCY', 10800); |
| 175 | |
| 176 | /** |
| 177 | * The life time of the cache for the results of the SiteCheck scans. |
| 178 | */ |
| 179 | define('SUCURISCAN_SITECHECK_LIFETIME', 1200); |
| 180 | |
| 181 | /** |
| 182 | * The life time of the cache for the results of the get_plugins function. |
| 183 | */ |
| 184 | define('SUCURISCAN_GET_PLUGINS_LIFETIME', 1800); |
| 185 | |
| 186 | /** |
| 187 | * The maximum execution time of a HTTP request before timeout. |
| 188 | */ |
| 189 | define('SUCURISCAN_MAX_REQUEST_TIMEOUT', 5); |
| 190 | |
| 191 | /** |
| 192 | * Sets the text that will preceed the admin notices. |
| 193 | * |
| 194 | * If you have defined SUCURISCAN_THROW_EXCEPTIONS to throw a generic exception |
| 195 | * when an info or error alert is triggered, this text will be replaced by the |
| 196 | * type of alert that was fired (either Info or Error respectively) which is |
| 197 | * useful when you are executing code in a testing environment. |
| 198 | */ |
| 199 | define('SUCURISCAN_ADMIN_NOTICE_PREFIX', '<b>SUCURI:</b>'); |
| 200 | |
| 201 | /* Fix missing server name in non-webview context */ |
| 202 | if (!array_key_exists('SERVER_NAME', $_SERVER)) { |
| 203 | $_SERVER['SERVER_NAME'] = 'localhost'; |
| 204 | } |
| 205 | |
| 206 | /* Load all classes before anything else. */ |
| 207 | require_once('src/sucuriscan.lib.php'); |
| 208 | require_once('src/request.lib.php'); |
| 209 | require_once('src/fileinfo.lib.php'); |
| 210 | require_once('src/cache.lib.php'); |
| 211 | require_once('src/option.lib.php'); |
| 212 | require_once('src/event.lib.php'); |
| 213 | require_once('src/hook.lib.php'); |
| 214 | require_once('src/api.lib.php'); |
| 215 | require_once('src/mail.lib.php'); |
| 216 | require_once('src/command.lib.php'); |
| 217 | require_once('src/template.lib.php'); |
| 218 | require_once('src/fsscanner.lib.php'); |
| 219 | require_once('src/hardening.lib.php'); |
| 220 | require_once('src/interface.lib.php'); |
| 221 | require_once('src/auditlogs.lib.php'); |
| 222 | require_once('src/sitecheck.lib.php'); |
| 223 | require_once('src/integrity.lib.php'); |
| 224 | require_once('src/firewall.lib.php'); |
| 225 | require_once('src/installer-skin.lib.php'); |
| 226 | |
| 227 | /* Load page and ajax handlers */ |
| 228 | require_once('src/pagehandler.php'); |
| 229 | |
| 230 | /* Load handlers for main pages (lastlogins). */ |
| 231 | require_once('src/lastlogins.php'); |
| 232 | require_once('src/lastlogins-loggedin.php'); |
| 233 | require_once('src/lastlogins-failed.php'); |
| 234 | require_once('src/lastlogins-blocked.php'); |
| 235 | |
| 236 | /* Load handlers for main pages (settings). */ |
| 237 | require_once('src/settings.php'); |
| 238 | require_once('src/settings-general.php'); |
| 239 | require_once('src/settings-scanner.php'); |
| 240 | require_once('src/settings-integrity.php'); |
| 241 | require_once('src/settings-hardening.php'); |
| 242 | require_once('src/settings-posthack.php'); |
| 243 | require_once('src/settings-alerts.php'); |
| 244 | require_once('src/settings-apiservice.php'); |
| 245 | require_once('src/settings-webinfo.php'); |
| 246 | |
| 247 | /* Load global variables and triggers */ |
| 248 | require_once('src/globals.php'); |
| 249 | |
| 250 | /** |
| 251 | * Uninstalls the plugin, its settings and reverts the hardening. |
| 252 | * |
| 253 | * When the user decides to deactivate and/or uninstall the plugin it will call |
| 254 | * this method to delete all traces of data inserted into the database by older |
| 255 | * versions of the code, will remove the scheduled task, will delte the options |
| 256 | * inserted into the sub-database associated to a multi-site installation, will |
| 257 | * revert the hardening applied to the core directories, and will delete all the |
| 258 | * security logs, cache and additional data stored in the storage directory. |
| 259 | */ |
| 260 | function sucuriscan_deactivate() |
| 261 | { |
| 262 | global $wpdb; |
| 263 | |
| 264 | if ($wpdb) { |
| 265 | /* Delete all the possible plugin related options from the database */ |
| 266 | $sql = "SELECT * FROM {$wpdb->options} WHERE option_name LIKE 'sucuriscan%'"; |
| 267 | $options = $wpdb->get_results($sql); |
| 268 | foreach ($options as $option) { |
| 269 | delete_site_option($option->option_name); |
| 270 | delete_option($option->option_name); |
| 271 | } |
| 272 | } |
| 273 | |
| 274 | /* Delete scheduled task from the system */ |
| 275 | wp_clear_scheduled_hook('sucuriscan_scheduled_scan'); |
| 276 | |
| 277 | /* Delete settings from the database if they exist */ |
| 278 | $options = SucuriScanOption::getDefaultOptionNames(); |
| 279 | foreach ($options as $option_name) { |
| 280 | delete_site_option($option_name); |
| 281 | delete_option($option_name); |
| 282 | } |
| 283 | |
| 284 | /* Delete hardening in standard directories */ |
| 285 | SucuriScanHardening::dewhitelist('ms-files.php', 'wp-includes'); |
| 286 | SucuriScanHardening::dewhitelist('wp-tinymce.php', 'wp-includes'); |
| 287 | SucuriScanHardening::unhardenDirectory(WP_CONTENT_DIR); |
| 288 | SucuriScanHardening::unhardenDirectory(WP_CONTENT_DIR . '/uploads'); |
| 289 | SucuriScanHardening::unhardenDirectory(ABSPATH . '/wp-includes'); |
| 290 | SucuriScanHardening::unhardenDirectory(ABSPATH . '/wp-admin'); |
| 291 | |
| 292 | /* Delete cache files from disk */ |
| 293 | $fifo = new SucuriScanFileInfo(); |
| 294 | $fifo->ignore_files = false; |
| 295 | $fifo->ignore_directories = false; |
| 296 | $fifo->run_recursively = false; |
| 297 | $directory = SucuriScan::dataStorePath(); |
| 298 | $fifo->removeDirectoryTree($directory); |
| 299 | } |
| 300 | |
| 301 | register_deactivation_hook(__FILE__, 'sucuriscan_deactivate'); |
| 302 |