Monday, June 5, 2017

Node.js Security Scanner: Web Exploit Detector

10:48 AM Leave a Reply
Node.js Security Scanner: Web Exploit Detector


Node.js Security Scanner: Web Exploit Detector

     The Web Exploit Detector is a Node.js application (and NPM module) used to detect possible infections, malicious code and suspicious files in web hosting environments. This application is intended to be run on web servers hosting one or more websites. Running the application will generate a list of files that are potentially infected together with a description of the infection and references to online resources relating to it.







Installation

The simplest way to install Web Exploit Detector is as a global NPM module: –

npm install -g web_exploit_detector

If you are running Linux or another Unix-based OS you might need to run this command as root (e.g. sudo npm install -g web_exploit_detector).



Running

     If you have installed Web Exploit Detector as an NPM module (see above) then running the scanner is as simple as running the following command, passing in the path to your webroot (location of your website files):

wed-scanner --webroot=/var/www/html

Other command-line options are available, simply run wed-scanner --help to see a help message describing them.

Running the script in this way will produce human-readable output to the console. This is very useful when running the script with cron for example as the output can be sent as an e-mail whenever the script runs.

The script also supports the writing of results to a more computer-friendly JSON format for later processing. To enable this output, see the --output command line argument.



Recursive directory snapshots

    The Web Exploit Detector also comes with two utilities to help to identify files that might have changed unexpectedly. A successful attack on a site usually involves deleting files, adding new files or changing existing files in some way.



Snapshots

    A snapshot (as used by these utilities) is a JSON file which lists all files as well as a description of their contents at the point in which the snapshot was created. If a snapshot was generated on Monday, for example, and then the site was attacked on Tuesday, then running a comparison between this snapshot and the current site files afterwards will show that one or more files were added, deleted or changed. The goal of these utilities therefore is to allow these snapshots to be created and for the comparisons to be performed when required.

The snapshot stores each file path together with a SHA-256 hash of the file contents. A hash, or digest, is a small summary of a message, which in this case is the file’s contents. If the file contents change, even in a very small way, the hash will become completely different. This provides a good way of detecting any changes to file contents.



Usage

The following two utilities are also installed as part of Web Exploit Detector: –

wed-generate-snapshot: this utility allows a snapshot to be generated for all files (recursively) in a directory specified by “–webroot”. The snapshot will be saved to a file specified in the “–output” option.
wed-compare-snapshot: once a snapshot has been generated it can be compared against the current contents of the same directory. The snapshot to check is specified using the “–snapshot” option. The base directory to check against is stored within the snapshot, but if the base directory has changed since the snapshot was generated then the –webroot option can be used.


Workflow

     Snapshots can be generated as frequently as required, but as a general rule of thumb they should be generated whenever a site is in a clean (non-infected) state and whenever a legitimate change has been made. For CMS-based sites like WordPress, snapshots should be created regularly as new uploads will cause the new state to change from the stored snapshot. For sites whose files should never change, a single snapshot can be generated and then used indefinitely ensure nothing actually does change.



Rule engine

The application operates using a collection of “rules” which are loaded when the application is run. Each rule consists of an ID, name, description, list of URLs, tags, deprecation flag and most importantly a set of tests.

Each individual test must be one of the following: –

A regular expression: the simplest type of test, any value matching the regex will pass the test.
A Boolean callback: the callback function must return a Boolean value indicating if the value passes the test. The callback is free to perform any synchronous operations.
A Promise callback: the callback function must return a Promise which is resolved with a Boolean value indicating if the value passes the test. This type of callback is free to perform any asynchronous operations.
The following test types are supported: –

“path”: used to check the file path. This test must exist and should evaluate to true if the file path is considered to match the rule.
“content”: used to check the contents of a file. This test is optional and file contents will only be read and sent to rules that implement this test type. When this test is a function, the content (string) will be passed as the first argument and the file path will be passed as the second argument, allowing the test to perform additional file operations.

Download