Coder Social home page Coder Social logo

ssnepenthe / soter Goto Github PK

View Code? Open in Web Editor NEW
0.0 4.0 1.0 316 KB

Check your WordPress site for vulnerabilities against the WPScan Vulnerabilities Database API.

License: GNU General Public License v2.0

PHP 86.02% Shell 5.71% CSS 8.27%
vulnerabilities wpvulndb wordpress-plugin slack-notifications email-notifications wpscan-vulnerability-database wordpress php

soter's Introduction

soter

This plugin checks your site for security vulnerabilities against the WPScan Vulnerability Database API.

Originally inspired by the Sensio Labs Security Checker and the Friends of PHP Security Advisories, which unfortunately do not track WordPress vulnerabilities.

A less intrusive alternative to the WPScan vulnerability scanner.

NOTE: This plugin does not verify the integrity of files on your server - it only checks installed packages by name/version against a list of known vulnerabilities provided by the WPScan API.

Requirements

WordPress 4.7 or later, PHP 5.4 or later and Composer.

Installation

$ composer require ssnepenthe/soter

Usage

Once activated, this plugin will check your site against the WPScan API twice daily and notify you when vulnerabilties are detected.

The plugin is configurable by visiting settings > soter in wp-admin:

  • Notification frequency: Choose whether to receive notifications after every scan where vulnerabilities are detected or only to receive notifications when your sites status changes.
  • Ignored plugins and themes: Select any packages that should not be checked against the WPScan API. This is intended for custom packages which are not tracked by the API and therefore would generate unnecessary HTTP requests or possible false positives.
  • Send email notifications: Enable/disable email notifications.
  • Email address: Provide an email address to notify if other than your site administrator email.
  • Email type: Choose whether you prefer HTML or text emails.
  • Send Slack notifications: Enable/disable Slack notifications.
  • Slack WebHook URL: Provide a URL for a Slack "Incoming WebHook" integration if you wish to receive Slack notifications.

Extending

There are two ways to easily extend the functionality of this plugin.

Via Pimple

Use the Pimple extend() method to modify plugin services.

To add a new notifier, for example, you can extend notifier_manager.

This is the preferred method for adding new notifiers as it will automatically honor the frequency setting configured by the site admin.

class Sms_Notifier implements Soter\Notifier_Interface {
    public function is_enabled() {
        // Return boolean indicating whether this notifier is currently enabled.
    }

    public function notify( Soter_Core\Vulnerabilities $vulnerabilities ) {
        // Build and send the message.
    }
}

_soter_instance()->extend( 'notifier_manager', function( Soter\Notifier_Manager $manager, Pimple\Container $container ) {
    $manager->add( new Sms_Notifier );

    return $manager;
} );

Via WordPress hooks

In the process of scanning a site, each package is individually checked against the WPScan API.

After each package check is complete, the soter_package_check_complete action is triggered.

add_action( 'soter_package_check_complete', function( Soter_Core\Vulnerabilities $vulnerabilities, Soter_Core\Response $response ) {
    switch ( $response->get_package()->get_type() ) {
        case Soter_Core\Package::TYPE_PLUGIN:
            // ...
        case Soter_Core\Package::TYPE_THEME:
            // ...
        case Soter_Core\Package::TYPE_WORDPRESS:
            // ...
    }
}, 10, 2 );

After all package checks are complete, the soter_site_check_complete action is triggered.

add_action( 'soter_site_check_complete', function( Soter_Core\Vulnerabilities $vulnerabilities ) {
    foreach ( $vulnerabilities as $vulnerability ) {
        // ...
    }
} );

Acknowledgements

This plugin wouldn't be possible without the work of the WPScan team and their amazing WPScan Vulnerabilities Database.

The email templates for this plugin are created from the Postmark Transactional Email Templates which are released under the MIT license.

WP-CLI

If it feels more appropriate to you to be checking your site from the command line, you're in luck! Soter Command is a companion package for WP-CLI that allows you to do just that.

There are also at least two similar command packages available on Github:

soter's People

Contributors

ssnepenthe avatar

Watchers

 avatar  avatar  avatar  avatar

Forkers

pombredanne

soter's Issues

Update uninstall hook

Uninstall hook should also delete any remaining posts of type soter_vulnerability and possibly plugin transients.

Revisit use of DIRECTORY_SEPARATOR

Used in the Checker and Options_Page classes to split plugin slug from basename.

However - it looks like WP uses get_plugins() -> plugin_basename() -> wp_normalize_path() to replace back slashes with forward slashes so this may not work on Windows?

Testing

Test scaffolding is in place but unused...

Terrible "Vulnerable Site" presentation in wp-admin

Currently a giant admin notice is slapped together and displayed on the plugin settings page. It is painful to look at.

It would be much better to create some sort of list table implementation, either on a new page or with a tabbed navigation on the current page.

Some additional presentation ideas:

  • Make use of the "plugin_row_meta" or "after_plugin_row_*" filters to flag vulnerable plugins on the plugin list page. Not sure if there are any similar filters for themes.
  • Add an icon/badge to the wp admin bar and/or admin menu items.
  • Create a dashboard widget listing current vulnerabilities.

Work on email templates

DRY up email templates a bit for reuse...

I can think of at least three emails I would like to include:

  • Congrats, no vulnerabilities found...
  • Uh oh, X vulnerabilities found...
  • Error when checking site...

Settings overrides in WP-CLI `security check-site` command

The primary security check-site command honors plugin settings as defined by administrator on the Settings > Soter page.

Ideally, the user should be able to override all settings when running this command.

Enable/disable email, set email type, set email address to send notifications to, ignored packages.

No indication of vulnerable state when frequency == only on change

When notification frequency is set to only send after scans where status has changed - you will get a single notification and then there is no further indication that your site is vulnerable.

It would be very easy to forget to update and then never receive another notification.

One option would be to drop this setting completely - it was only implemented for the email host header injection vuln which hasn't been patched for a while.

Another (probably better) option would be to have some sort of visual indication in wp-admin. This might go hand-in-hand with implementing DB notifications or could just be a flag in the settings table.

0.3.x todo list

  • Multisite - test and update as necessary to work in multisite.
  • Add link to settings page in plugin_action_links?
  • Re-run checker after plugin/theme/core update.
    • Consider how to handle when updates are done outside of wp-admin (composer, manually uploading, etc.)
  • Should the abbreviated (x vulnerabilities detected) admin notice be dismissable?
  • Is there any reason to make other formatters for WP-CLI (json and yaml)?
  • The 12 hour response cache + 12 hour cron schedule likely means that packages are only truly being checked every 24 hours. Verify and adjust as necessary.
  • Add an ignore flag and an email flag to the WP-CLI commands.
  • Switch to transient caching?
  • User agent used by WPClient.php should be site specific.
  • In results class - don't store prepared meta in DB - prepare it on the fly.
  • Add progress bar to wp-cli check-site command

Filterable cache lifetime?

Cache lifetime for API responses and vulnerable site notice is HOUR_IN_SECONDS. Would it be beneficial to allow this to be changed?

Uncaught TypeError #2

Popped up in prep for testing #21.

Fatal error: Uncaught TypeError: Argument 1 passed to SSNepenthe\Soter\Checker::__construct() must be of the type array, null given, called in /srv/www/wordpress-default/public_html/wp-content/plugins/soter/src/class-plugin.php on line 253 and defined in /srv/www/wordpress-default/public_html/wp-content/plugins/soter/src/class-checker.php:71

Track vulnerability references

WPScan API responses include a number of references on vulnerabilities.

Ex:

"references":{
	"url":[
		"http://www.securityfocus.com/bid/66381/"
	],
	"cve":[
		"2014-2265"
	]
}

At least the following are valid keys: url, cve, osvdb, secunia.

Not sure if it is guaranteed to be set.

These should be saved along with the rest of the vulnerability data in the soter_vulenrability post type. Data can be used for admin notices, email notifications and CLI output.

Consider deleting plugin transients on uninstall

Transients are all prefixed so we should be able to run a delete query where option_name like transient_soter% or option name like transient_timeout_soter%.

Not sure if this is a good idea or not... WordPress will already take care of expired transients on core upgrade.

Undefined offset

Also popped up in prep for testing #21...

Notice: Undefined offset: 1 in /srv/www/wordpress-default/public_html/wp-content/plugins/soter/src/class-checker.php on line 174

Bad prefix in transient garbage collection task

In the WP_Transient_Cache class, $prefix is limited to 12 characters before appending the "_" character.

In Transient_Garbage_Collection, there is no character limit.

In this instance, there is no problem since the prefix (soter) is only 5 characters, but it should be updated regardless.

PHP version requirement

PHP requirement is set at 5.6 or above via composer but 5.4 or above via requirements checker class.

Actual requirement is 5.6 for use of argument unpacking and function imports.

Uncaught TypeError

Fatal error: Uncaught TypeError: Argument 1 passed to SSNepenthe\Soter\Listeners\Log_Vulnerability_Ids::log_vulnerability_ids() must be of the type array, object given, called in /srv/www/wordpress-default/public_html/wp-includes/class-wp-hook.php on line 298 and defined in /srv/www/wordpress-default/public_html/wp-content/plugins/soter/src/Listeners/class-log-vulnerability-ids.php:51

0.2.x Todo List

  • More descriptive output, adjustable via verbosity flags.
  • Basic validation on config values.
  • Better handling of non-200 response codes.
  • Some phpcs love.
  • Update readme.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.