'New', '1'=>'OK', '2'=>'Changed', '3'=>'Missing', '4'=>'Added', '98'=>'Not Watched', '99'=>'Checking...' ); function wordpress_sentinel() { $this->parse_uri(); $this->wp_theme_dir = get_theme_root(); $this->wp_plugin_dir = WP_PLUGIN_DIR; $this->wp_wordpress_dir = dirname(WP_CONTENT_DIR); } function site_check() { // Check for issues and display admin message if(!preg_match("/page=wordpress_sentinel/", $_SERVER['REQUEST_URI'])) { $this->build_section_list(); global $wpdb; $changed = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."wordpresssentinel_section WHERE status = ".WPS_STATE_CHANGED); $new = $wpdb->get_var("SELECT COUNT(*) FROM ".$wpdb->prefix."wordpresssentinel_section WHERE status = ".WPS_STATE_NEW); if($changed || $new) add_action('admin_notices', 'wordpress_sentinel_admin_warning'); } // Periodic (mock cron) checking for changes $action_interval = 5; // minutes $check_interval = 2; // hours $site_check = intval(get_site_option('wordpress_sentinel_site_check')); if($site_check + ($delay * 60) < time()) { $this->build_section_list(); $all_sections = array_merge($this->base, $this->themes, $this->plugins); foreach($all_sections as $section) { if($section->state == WPS_STATE_NEW) continue; $delta_time = time() - strtotime($section->last_checked); $threshold = 60 * 60 * $check_interval; if($delta_time > $threshold) { $this->check_section($section->id, false); break; } } delete_option('wordpress_sentinel_site_check'); add_option('wordpress_sentinel_site_check', time()); } } function admin_panel() { $this->build_section_list(); print '
| $column | "; print "$header"; foreach($sections as $section) { print "|||
|---|---|---|---|
| ".$this->display_section_name($section)." | "; print "".$section->location." | "; print "".$section->files." ".$section->snapshot_made." | ";
print "".$this->states[$section->state]." | "; print "
As Wordpress grows in popularity, it also becomes a bigger target for the hacking community. It is hard to think of anything more frustrating than finding that your site is redirecting or displaying content which is not your own.
If you are hacked, there are four questions that you have to address:
The purpose of this plugin is to alert you when you have been hacked and to address questions 2 & 3. Wordpress Sentinel acts as a watchdog that knows how your install is supposed to look and then alert you when something gets changed.
First, install the plugin and go to the Wordpress Sentinel option under Settings. It should list content under Wordpress, Themes and Plugins.
Second, click the "Snapshot Everything" button, and every file in your Wordpress install, as well as installed Themes and Plugins will be catalogued.
Periodically, the plugin will check a portion of the items for which snapshots have been taken. If any changes are detected, an administrative message will be displayed in Wordpress Admin. If this happens, go back to the Wordpress Sentinel option under Settings. The offending item will be marked as "Changed" in Red. If you click details, you can see what files have been changed and you can determine if this was a valid change or an intrusion and take the appropriate action.
Obviously, the plugin isn't watching what you are doing, so if you make changes to a Theme or install a new Plugin, or even Upgrade Wordpress to a newer version, it is going to notice that something changed and let you know. When this happens (and it will happen), just go to the Wordpress Sentinel option, find the item that you changed or added, and Refresh the Snapshot. (The "Snapshot Everything" button should never be used except when the plugin is first installed.)
The first thing to do is to look at the Wordpress Sentinel page and figure out what items have been changed. Take a screenshot and then look at the details of those items to see what files have been affected. If Wordpress is changed, you need to replace every file that is changed, although usually removing the existing install and replacing it with a clean install is the best course.
If a plugin has been corrupted, it needs to be completely removed and reinstalled. Just updating over the existing install is not advised, as any malicious files that have been added would remain.
If a theme has been corrupted, then things may get complicated. If it is a stock theme that can be removed and reinstalled, then do that. If it is a custom theme, then every modified file needs to be carefully examined and cleaned up. You may need someone with advanced skills in site development to help separate the template content from the injected code.
That is really beyond the scope of this plugin. The best course of action is to keep Wordpress as well as all plugins and themes up to date. If you know the time the hack occurred (and this plugin helps you determine that) then it is also a good idea to have an Analyst look through your server logs and try to isolate the entry point.
Cannot display details for section '$section_id' - Section Not Found
| $column | "; print "$header"; $sql = "SELECT * FROM ".$wpdb->prefix."wordpresssentinel_file WHERE section_id = $section_id"; $section_files = $wpdb->get_results($sql); foreach($section_files as $section_file) { $icon = $section_file->watch ? "watch.png" : "nowatch.png"; $action = $section_file->watch ? "nowatch" : "watch"; $watch = "$section_id,$action=>$section_file->file_id))."'>". "|||
|---|---|---|---|
| $watch ".$section_file->location." | "; print "".$section_file->size." | "; print "".$section_file->update_date." | "; print "".$this->states[$section_file->status]." | "; print "
Snapshots Updated for Everything
Cannot generate snapshot for section '$section_id' - Section Not Found
Snapshot Updated for ".$section_row->name. "
Check Performed for Everything (Possible Issues Found)
Check Performed for Everything
Cannot perform check for section '$section_id' - Section Not Found
Check Performed for ".$section_row->name. " (Possible Issues Found)
Check Performed for ".$section_row->name."
Wordpress Sentinel: "; print "Install files have changed. (Details)