Wordfence CLI 文档
Wordfence CLI 文档,介绍命令行安全扫描用法。
- Autocomplete of CLI's Subcommands and Parameters
- Configuration
- Frequently Asked Questions
- Installation
- Output
- Wordfence CLI Subcommands
- Updating your Installation
- Site Counting Configuration
- Examples
- Database Scan Configuration
- Examples
- Malware Scan Configuration
- Examples
- Remediation
- Faster Scanning with Vectorscan
- Remediation Configuration
- Examples
- Vulnerability Scan Configuration
- Examples
Autocomplete of CLI's Subcommands and Parameters
The source code for Wordfence CLI comes with a script that can be used to automatically suggest or fill in subcommands and command line parameters. To use these autocompletions from bash, you can run source ./scripts/complete.bash from the base of the source code directory. If you are using zsh, you can run the following prior to running source on the bash completion file:
autoload -Uz +X compinit && compinit
autoload -Uz +X bashcompinit && bashcompinit
Once this is done, you can use the Tab key to suggest subcommands or parameters when running wordfence from the command line.
Examples
$ source wordfence-cli/scripts/complete.bash
$ wordfence vuln-scan -
--accept-terms -E -l --no-debug --output --quiet --smtp-user
--banner --email -L --no-help --output-columns --read-stdin -t
-c --email-from --license --no-informational --output-format --relative-content-path --theme-directory
-C --exclude-vulnerability --log-level --no-output --output-headers --relative-mu-plugins-path -v
--cache -f -m --no-output-headers --output-path --relative-plugins-path --verbose
--cache-directory --feed -M --no-prefix-log-levels -p --require-path --version
--check-for-update -h --no-accept-terms --no-purge-cache -P -s -w
--color --help --no-banner --no-quiet --path-separator --sendmail-path --wfi-url
--configuration -i --noc1-url --no-read-stdin --plugin-directory --smtp-host --wordpress-path
-d -I --no-cache --no-require-path --prefix-log-levels --smtp-password
--debug --include-vulnerability --no-check-for-update --no-verbose --purge-cache --smtp-port
-e --informational --no-color --no-version -q --smtp-tls-mode
$ wordfence malware-scan -
-a --debug --images -n --no-include-all-files --output-columns -s --wfi-url
--accept-terms -e --include-all-files -N --no-match-all --output-format --scanned-content-limit --workers
--allow-io-errors -E --include-files --no-accept-terms --no-output --output-headers --sendmail-path -x
--banner --email --include-files-pattern --no-allow-io-errors --no-output-headers --output-path --smtp-host -X
-c --email-from --include-signatures --no-banner --no-prefix-log-levels --pcre-backtrack-limit --smtp-password -z
--cache --exclude-files -l --noc1-url --no-progress --pcre-recursion-limit --smtp-port
--cache-directory --exclude-files-pattern -L --no-cache --no-purge-cache --prefix-log-levels --smtp-tls-mode
--check-for-update --exclude-signatures --license --no-check-for-update --no-quiet --progress --smtp-user
--chunk-size --file-list-separator --log-level --no-color --no-read-stdin --purge-cache -v
--color -h -m --no-debug --no-verbose -q --verbose
--configuration --help -M --no-help --no-version --quiet --version
-d -i --match-all --no-images --output --read-stdin -w
Configuration
Configuration can be set through command line arguments, or configured globally through the wordfence-cli.ini file. Once Wordfence CLI is installed, we recommend running wordfence configure to interactively configure Wordfence CLI's global options.
wordfence configure Command Line Arguments
-o,--overwrite: Overwrite any existing configuration file without prompting-r,--request-license: Automatically request a free license without prompting-w,--workers: Specify the number of worker processes to use for malware scanning-D,--default: Automatically accept the default values for any options that are not explicitly specified. This will also result in a free license being requested when terms are accepted.
Global Command Line Arguments
These arguments apply to all subcommands.
General Options:
-c,--configuration: Path to a configuration INI file to use. (default:~/.config/wordfence/wordfence-cli.ini)-l,--license: Specify the license to use.--version: Display the version of Wordfence CLI.-h,--help: Display help information.--accept-terms: Automatically accept the terms required to invoke the specified command. The latest terms can be viewed using thewordfence termscommand and found at https://www.wordfence.com/wordfence-cli-license-terms-and-conditions/. Register to receive updated Wordfence CLI Terms of Service via email at https://www.wordfence.com/products/wordfence-cli/#terms. Join our WordPress Security mailing list at https://www.wordfence.com/subscribe-to-the-wordfence-email-list/ to get security alerts, news, and research directly to your inbox.
Output Control:
Email:
-E,--email: Email address(es) to which to send reports.--email-from: The From address to use when sending emails. If not specified, the current username and hostname will be used.--smtp-host: The host name of the SMTP server to use for sending email.--smtp-port: The port of the SMTP server to use for sending email.--smtp-tls-mode: The SSL/TLS mode to use when communicating with the SMTP server. none disables TLS entirely. smtps requires TLS for all communication while starttls will negotiate TLS if supported using the STARTTLS SMTP command. Options:none,smtps,starttls(default:starttls)--smtp-user: The username for authenticating with the SMTP server.--smtp-password: The password for authentication with the SMTP server. This should generally be specified in an INI file as including passwords as command line arguments can expose them to other users on the same system.--sendmail-path: The path to the sendmail executable. This will be used to send email if SMTP is not configured. (default:sendmail)
Logging:
-v,--verbose: Enable verbose logging. If not specified, verbose logging will be enabled automatically if stdout is a TTY. (use--no-verboseto disable)-d,--debug: Enable debug logging. (use--no-debugto disable)-q,--quiet: Suppress all output other than scan results. (use--no-quietto disable)--prefix-log-levels: Prefix log messages with their respective levels. This is enabled by default when colored output is not enabled.
-L,--log-level: Only log messages at or above the specified level. Options:DEBUG,VERBOSE,INFO,WARNING,ERROR,CRITICAL
Caching:
--cache-directory: A path to use for cache files. (default:~/.cache/wordfence)--cache: Enable caching. Caching is enabled by default. (use--no-cacheto disable)--purge-cache: Purge any existing values from the cache.
wordfence-cli.ini
By default, the configuration file will reside at ~/.config/wordfence/wordfence-cli.ini. This INI file is best suited for global configuration options for Wordfence CLI. The license is the only item that's typically configured here.
Global INI Options
[DEFAULT]
license = <your license key>
verbose = [on|off]
debug = [on|off]
banner = [on|off]
quiet = [on|off]
email = <recipient email address for reports>
email_from = <sender email address for reports>
smtp_host = <hostname of SMTP server for mailing reports>
smtp_port = <port for SMTP server for mailing reports>
smtp_tls_mode = [none|smtps|starttls]
smtp_user = <username>
smtp_password = [on|off]
sendmail_path = <path to sendmail executable, used when SMTP is not configured>
cache_directory = <path to a directory to use for caching>
cache = [on|off]
Subcommand INI Options
See documentation for each subcommand for its respective INI options. Most command line options can also be set in the INI file. Generally, only settings that should be applied every time CLI is invoked should be stored in the config file. For example, don't store options specific to one site being scanned in the global config file. Global options may also be overwritten for each subcommand section.
Wordfence CLI can be configured to send a summary of scan results (both the malware scan and the vulnerability scan) to an email address. The email will only send when the scan actually finds something, for instance a file contains malware, or a WordPress plugin has a vulnerability. An email will also not be sent in the event a scan fails. We recommend reviewing scan findings regularly.
Configuration
The following command line arguments can be supplied to either the malware scan or the vulnerability scan to tell CLI how to send email. If using SMTP, we recommend storing the configuration in the INI rather than supplying credentials as command line parameters.
-E,--email: Email address(es) to which to send reports.--email-from: The From address to use when sending emails. If not specified, the current username and hostname will be used.--smtp-host: The host name of the SMTP server to use for sending email.--smtp-port: The port of the SMTP server to use for sending email.--smtp-tls-mode: The SSL/TLS mode to use when communicating with the SMTP server. none disables TLS entirely. smtps requires TLS for all communication while starttls will negotiate TLS if supported using the STARTTLS SMTP command. Options:none,smtps,starttls(default:starttls)--smtp-user: The username for authenticating with the SMTP server.--smtp-password: The password for authentication with the SMTP server. This should generally be specified in an INI file as including passwords as command line arguments can expose them to other users on the same system.--sendmail-path: The path to the sendmail executable. This will be used to send email if SMTP is not configured. (default:sendmail)
If you do not have access to an external SMTP server, sendmail can be used as a local relay. We recommend going through the process of authenticating your server as an email sender using SPF, DKIM, and DMARC to prevent emails from CLI from being flagged as spam.
Attaching Output Files
Using the --output-path option in conjunction with --email will cause the output file to be added as an attachment to the emailed report.
Further reading
Frequently Asked Questions
How do I get a license?
Licenses can be obtained at https://www.wordfence.com/products/wordfence-cli/.
The scanner has identified malware. What do I do now?
If you do not know what the file is, we recommend making a backup before you remove it, in case it was a false positive. We always recommend saving a backup copy of the file first, whether by making a full backup of the system or by saving only the file and the location where it belongs, so you can replace it if necessary.
What permissions are required to install/run CLI?
Wordfence CLI can be installed and run as any user, including root. When installing using pip as root, pip will return a warning about running as root. Using that installation method, we recommend installing using pip as a non-priveledged user.
What the difference is between Wordfence CLI and WP-CLI?
Wordfence CLI is a stand-alone, command-line, malware scanner written in Python. WP-CLI is a WordPress command-line utility for managing a WordPress installation written in PHP. They are 2 separate and distinct pieces of software and are unrelated.
If I have Wordfence CLI, do I need the Wordfence plugin too?
If you are a WordPress site owner who is looking for a security solution, the Wordfence plugin offers comprehensive protection and intrusion detection. Wordfence CLI can be used alongside the Wordfence plugin. Wordfence CLI would be used instead of the malware detection functionality of the Wordfence plugin's scan.
If I want to run Wordfence CLI alongside the Wordfence plugin, as a replacement for the malware scanner, are there any scanner settings I can turn off in the plugin to reduce redundancy?
Yes. Within the Wordfence plugin scan options, you can disable the "Scan file contents for backdoors, trojans and suspicious code" scan option and rely on Wordfence CLI to perform the malware scan.
I got the error "Failed to locate libpcre". What do I do?
Wordfence CLI uses the libpcre library to run our signatures against files. There's a few ways to install it depending on your system:
For Debian/Ubuntu flavors of Linux:
apt-get install libpcre
Or
apt-get install libpcre3
For Red Hat/Fedora based Linux distributions:
dnf install pcre
How often are signatures refreshed locally?
Once every 24 hours. You can use the --purge-cache command line argument to refresh the signature set.
How many workers can I run on my system?
That's really up to you, but we recommend for a fast scan two workers per CPU core.
What is the most performant way recommended to run a scan?
We recommend two workers per CPU core for the fastest possible scan. For busy production systems, we recommend limiting the worker count to reduce the impact on the availability of production services.
What file types are scanned by default?
The default scan will scan .php, .phtml, .html, .js, and .svg files by default. Using the --images option will expand the file list to .jpg, .jpeg, .mp3, .avi, .m4v, .mov, .mp4, .gif, .png, .tiff, .svg, .sql, .js, .tbz2, .bz2, .xz, .zip, .tgz, .gz, .tar, .log, .err. If there are specific file types you want to match, you can use the --include-files or --include-files-pattern to define a custom set of files/file types to scan. See the configuration for more details.
I got the error "Unable to locate content directory for site at /path/to/wordpress". What do I do?
This is likely from a WordPress installation using a custom wp-content directory. There are a number of things CLI will check to determine where plugin and theme files are stored:
- We check if the relative path
wp-content/pluginsandwp-content/themesexists. - We look in the wp-config.php file for the
WP_CONTENT_DIRand/orWP_PLUGIN_DIRconstants.
If we are unable to find a path from either of those checks, CLI will return this error. You can use one of the following command line parameters to tell CLI where to find plugins and themes:
-p,--plugin-directory: Path to a directory containing WordPress plugins to scan for vulnerabilities.-t,--theme-directory: Path to a directory containing WordPress themes to scan for vulnerabilities.-C,--relative-content-path: Alternate path of the wp-content directory relative to the WordPress root.-P,--relative-plugins-path: Alternate path of the wp-content/plugins directory relative to the WordPress root.-M,--relative-mu-plugins-path: Alternate path of the wp-content/plugins directory relative to the WordPress root.
Why am I receiving a "Rate limit reached" error message?
Some Wordfence API endpoints used by CLI have rate limits in place to prevent abuse. CLI has a built-in caching mechanism that should avoid rate limits when using the default configuration.
If you encounter this error, ensure that caching is enabled.
Do I need to enable caching? How does it work?
Yes, caching is necessary to avoid API rate limits and ensure CLI performs as expected. It should only ever be disabled temporarily for debugging purposes.
The cache utilizes filesystem storage, saving data to a directory configurable via the --cache-directory option on the command line or the cache_directory directive in the INI file. By default, this is set to ~/.cache/wordfence.
If using CLI with the same license across multiple hosts, consider using a shared cache via a network filesystem (it must support flock) or upgrading to a paid license for higher rate limits.
Installation
Installation with pip
This is the simplest method for installing CLI.
pip install wordfence
This should build and install an executable of Wordfence CLI at the following directory when run as the username user:
/home/username/.local/bin/wordfence
If run as root, the executable path should be:
/usr/local/bin/wordfence
Verify the executable works correctly on your system:
wordfence version
You should see output similar to this:
Wordfence CLI 3.0.1
Once this is done, we recommend reviewing the configuration to go through configuring a license followed by running your first scan.
Install the Debian package
This method will work for Debian and Debian-based Linux distros (Ubuntu, Linux Mint, Kali, etc) where you have root access to the system.
sudo apt install ./wordfence.deb
For older distros, you can also use the following commands to install CLI.
sudo dpkg -i wordfence.deb
sudo apt -f install
Verify the executable works correctly on your system:
wordfence --version
You should see output similar to this:
Wordfence CLI 3.0.1
Once this is done, we recommend reviewing the configuration to go through configuring a license followed by running your first scan.
Install the RPM package
This method will work for Red Hat Enterprise Linux 9 and compatible distributions (AlmaLinux, Rocky Linux, etc) where you have root access to the system. You must have the CodeReady Linux Builder (CRB) repo enabled before installing.
On RHEL, run:
subscription-manager repos --enable codeready-builder-for-rhel-9-$(arch)-rpms
On RHEL-compatible distributions, run:
dnf config-manager --set-enabled crb
You should now be able to install the RPM package:
sudo dnf install ./wordfence-el9.rpm
Verify the executable works correctly on your system:
wordfence version
You should see output similar to this:
Wordfence CLI 3.0.1
Once this is done, we recommend reviewing the configuration to go through configuring a license followed by running your first scan.
Binaries
Binaries for Wordfence CLI can be downloaded on the Releases page of the GitHub repository (under Assets of each release) along with source code, and the .whl files:
https://github.com/wordfence/wordfence-cli/releases
The binary files are in the format wordfence_yyyy.tar.gz where yyyy is the CPU architecture. The following example uses AMD64 as the architecture.
We recommend verifying the authenticity of the download prior to extracting the archive. You can do this by following the steps outlined below prior to following the rest of these installation steps.
Extract the binary:
tar xvzf wordfence_amd64.tar.gz
Verify the binary works correctly on your system:
./wordfence version
You should see output similar to this:
Wordfence CLI 3.0.1
Once this is done, we recommend reviewing the configuration to go through configuring a license followed by running your first scan.
Docker
To install Wordfence CLI using Docker, you can clone the GitHub repo to your local environment:
git clone git@github.com:wordfence/wordfence-cli.git
cd ./wordfence-cli
docker build -t wordfence-cli:latest .
Once the Docker image is built, you can start the docker container with the volumes you wish to scan:
docker run -v /var/www:/var/www wordfence-cli:latest version
You should see output similar to this:
Wordfence CLI 3.0.1
Once this is done, we recommend reviewing the configuration to go through configuring a license followed by running your first scan.
Manual Installation
To install Wordfence CLI manually, you can clone the GitHub repo to your local environment:
git clone git@github.com:wordfence/wordfence-cli.git
cd ./wordfence-cli
pip install .
python main.py version
You can additionally build the wheel archive and generate an executable:
pip install build~=0.10
python -m build --wheel
pip install dist/wordfence-*.whl
The executable should be installed to ~/.local/bin/wordfence.
If you encounter an error about libpcre.so similar to this one:
OSError: libpcre.so: cannot open shared object file: No such file or directory
You may need to install the libpcre library.
Verifying the Authenticity of a Release Asset
The checksum file for all release assets is sgned using GPG as part of the build process. We recommend verifying the authenticity of the checksum file and then verifying the checksum of the downloaded release asset prior to extracting, installing, or executing any code.
To verify the signature of the checksums file, first download and import our public GPG key:
wget https://www.wordfence.com/wp-content/uploads/public.asc
gpg --import public.asc
You can optionally sign our public key with your own private key:
gpg --lsign-key 00B225C7030F26FF4A3D3481F82623ECE1DB0FBB
Download the checksums.txt and checksums.txt.asc files from GitHub releases. You can then verify the authenticity of the checksums.txt file (replace the filenames with paths to the copies you've downloaded):
gpg --assert-signer 00B225C7030F26FF4A3D3481F82623ECE1DB0FBB --verify checksums.txt.asc checksums.txt
If your version of GPG doesn't include --assert-signer you can just run (you may see a warning using this method):
gpg --verify checksums.txt.asc checksums.txt
You should see output similar to this:
gpg: Signature made Fri Aug 18 16:27:11 2023 EDT
gpg: using EDDSA key 00B225C7030F26FF4A3D3481F82623ECE1DB0FBB
gpg: issuer "opensource@wordfence.com"
gpg: Good signature from "Wordfence <opensource@wordfence.com>" [ultimate]
gpg: signer '00B225C7030F26FF4A3D3481F82623ECE1DB0FBB' matched
Now that you've verified the checksums file, you can confirm that the checksum of your download matches. For example, if you downloaded the wordfence_amd64.tar.gz (the standalone Linux executable for the x86_64 architecture) to the same directory as checksums.txt, you can verify the checksum matches with:
sha256sum --ignore-missing -c checksums.txt
Output
By default Wordfence CLI will print a banner followed by which paths it was supplied for scanning:
▓▓▓
▓▓▓▓▓ ▓▓▓▓▓ _ __ __ ____
▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓ | | / /___ _________/ / / __/__ ____ ________
▓▓ ▓ ▓▓ | | /| / / __ \/ ___/ __ /_/ /_/ _ \/ __ \/ ___/ _ \
▓▓ ▓▓ ▓▓▓ ▓▓ ▓▓ | |/ |/ / /_/ / / / /_/ /_ __/ __/ / / / /__/ __/
▓▓ ▓ ▓ ▓ ▓▓ |__/|__/\____/_/ \____/ /_/ \___/_/ /_/\___/\___/
▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓ ____ _ ___
▓▓ ▓▓▓ ▓ ▓▓▓ ▓ ▓▓▓ ▓▓ / ___| | |_ _|
▓▓▓▓▓ ▓ ▓▓▓ ▓ ▓▓▓▓▓ | | | | | |
▓▓ ▓ ▓▓ ▓▓ ▓ ▓▓ | |___| |___ | |
▓▓▓▓▓▓▓▓▓▓▓▓ ▓▓▓▓▓▓▓▓▓▓▓▓ \____|_____|___|
Scanning path: /var/www/
Scanning path: /home/user/
Files found that match a signature matches are printed in the output as well. There are additionally the --verbose and --debug options that can be used to get further information about what Wordfence CLI is doing under the hood.
Report Formats
The report is a separate output stream generated by Wordfence CLI that will contain a list of the files detected by one of our signatures. Use --output-columns to configure which columns are written to the report. Available columns: filename, signature_id, signature_name, signature_description, matched_text.
- CSV (Comma-Separated Values): Tabular formatted file containing file names, and signature details about what was matched.
- TSV (Tab-Separated Values): Tabular formatted file containing file names, and signature details about what was matched.
- NULL-byte delimited: A NULL-byte delimited list of file paths only (does not contain signature or match data).
Wordfence CLI Subcommands
Wordfence CLI provides a variety of subcommands to support different use cases. The following subcommands are currently available:
- malware-scan (scan files for malware)
- vuln-scan (scan one or more WordPress installations for known vulnerabilities
- db-scan (scan one or more WordPress databases for malicious content)
- remediate (remediate malware by restoring known files)
- count-sites (count the number of WordPress sites at one or more paths)
Updating your Installation
Updating with pip
Use the following to update to the latest release of Wordfence CLI:
pip install --upgrade wordfence
Binaries
The releases page in GitHub will have the most recently available binaries for download:
https://github.com/wordfence/wordfence-cli/releases
The binary files are in the format wordfence_yyyy.tar.gz where yyyy is the CPU architecture. The following example uses AMD64 as the architecture.
We recommend verifying the authenticity of the download prior to extracting the archive. You can do this by following the steps outlined in the installation document prior to following the rest of these updating steps.
Extract the binary:
tar xvzf wordfence_amd64.tar.gz
Verify the binary works correctly on your system:
./wordfence version
You should see output similar to this:
Wordfence CLI 2.0.1
Copy the binary to the path you've installed your existing Wordfence CLI binary.
Docker
If you've followed our installation instructions for Docker, you can cd into the source code directory and run git pull to fetch the latest version. The main branch is kept up-to-date with the most recent stable release.
Manual Installation
Updating a manual/development installation can be done by using git pull in the source code directory. The main branch is kept up-to-date with the most recent stable release.
Site Counting Configuration
Site counting can be configured using either command line arguments, the INI file, or a combination of both.
Command Line Arguments
--read-stdin: Read paths from stdin-s,--path-separator: Path separator when reading from stdin, defaults to null byte--require-path: Require at least one path be provided for scanning--allow-nested: Allow nested WordPress installations--allow-io-errors: Allow counting to continue if IO errors are encountered
INI Options
[COUNT_SITES]
# Read paths from stdin
read_stdin = [on|off]
# Separator string when reading paths from stdin, defaults to null byte
path_separator = <separator>
allow_nested = [on|off]
allow_io_errors = [on|off]
Examples
Count the number of WordPress sites under /var/www
wordfence count-sites /var/www
Database Scan Configuration
Database scanning can be configured using either command line arguments, the INI file, or a combination of both.
Command Line Arguments
-H,--host: Database hostname. Defaults tolocalhost.-P,--port: Database port. Defaults to3306.-u,--user: Database user. Defaults toroot.--password: Provide the database password via the command line. This is insecure and should be avoided in favor of prompting or environment variables.-p,--prompt-for-password: Prompt for the database password on invocation.--password-env: Environment variable containing the database password. Defaults toWFCLI_DB_PASSWORD.-x,--prefix: WordPress database prefix. Defaults towp_.-D,--database-name: Name of the database to scan.-C,--collation: Collation to use when connecting to MySQL. Defaults toutf8mb4_unicode_ci.--read-stdin: Force reading database configuration paths from stdin. When stdin is not a terminal, the command automatically reads paths without specifying this flag.-s,--path-separator: Separator used when reading paths from stdin. Defaults to the null byte (AA==in base64 form).--require-database: Error if no databases are provided. This is automatically enforced when running interactively.-S,--locate-sites: Scan one or more filesystem paths forwp-config.phpfiles and extract database credentials automatically.--allow-nested: Permit nested WordPress installations when locating sites. Enabled by default.--allow-io-errors: Continue locating sites when IO errors occur. Enabled by default.--use-remote-rules: Pull the latest database scanning rules from the Wordfence API. Enabled by default.-R,--rules-file: Path to a JSON rules file to merge into the database rule set. May be provided multiple times.-e,--exclude-rules: Rule IDs to ignore when scanning. Accepts comma-delimited lists and repeated flags.-i,--include-rules: Rule IDs to include when scanning. Accepts comma-delimited lists and repeated flags.--output: Write results to stdout (default when--output-pathis not set).--output-path: Destination file for scan results.--output-columns: Comma-delimited list of columns to include in the output. Available columns:table,rule_id,rule_description,row. Column customization is supported forcsv,tsv,null-delimited, andline-delimitedformats.-m,--output-format: Output format for results. Supported values:human(default),csv,tsv,null-delimited,line-delimited.--output-headers: Include column headers in formats that support them (csv,tsv,null-delimited,line-delimited).
INI Options
[DB_SCAN]
# The name of an environment variable containing the database password to use
password_env = <variable>
# Read paths from stdin
read_stdin = [on|off]
# Separator string when reading paths from stdin, defaults to null byte
path_separator = <separator>
# Controls whether or not output is written to stdout
output = [on|off]
output_path = <path to which to write results>
# Comma-delimited list of columns to include in output (`table`, `rule_id`, `rule_description`, `row`)
output_columns = <columns>
output_format = [human|csv|tsv|null-delimited|line-delimited]
# Whether to include headers in output
output_headers = [on|off]
allow_nested = [on|off]
allow_io_errors = [on|off]
use_remote_rules = [on|off]
rules_file = <path>
# Comma-delimited list of rule IDs
exclude_rules = <rules>
include_rules = <rules>
JSON Configuration
When --locate-sites is not used, each trailing argument should be a JSON file containing a list of database configurations in the following shape:
[
{
"name": "wordpress",
"user": "wordpress",
"password": "example",
"host": "db.example.com",
"port": 3306,
"collation": "utf8mb4_unicode_ci",
"prefix": "wp_"
}
]
Entries may omit port, collation, or prefix; defaults are applied automatically.
When databases are discovered through --locate-sites or provided via JSON files, connection details from those sources override the command-line defaults for each database.
Examples
Scanning a single WordPress database
Scan a WordPress database using explicit connection settings and prompt for the password at runtime.
wordfence db-scan -H db.example.com -P 3306 -u wordpress -D wordpress --prompt-for-password
Automatically locating WordPress installations
Search the supplied directories for wp-config.php, extract the database credentials, and scan each discovered site.
wordfence db-scan -S /var/www/wordpress /srv/wordpress
Scanning databases listed in a JSON file
Provide a JSON file that lists one or more database configurations. Each entry must include name, user, password, and host, with optional port, collation, and prefix values. Multiple JSON files can be supplied.
wordfence db-scan /etc/wordfence/databases.json
Writing database scan results to a CSV
Output scan results to a CSV file with headers and explicitly selected columns.
wordfence db-scan -S /var/www/wordpress --output-format csv --output-columns table,rule_description,row --output-headers --output-path /home/username/db-scan-results.csv
Malware Scan Configuration
Malware scanning can be configured using either command line arguments, the INI file, or a combination of both.
Command Line Arguments
--read-stdin: Read paths from stdin. If not specified, paths will automatically be read from stdin when input is not from a TTY.-s,--file-list-separator: Separator used when listing files via stdin. Defaults to the null byte.--output: Write results to stdout. This is the default behavior when --output-path is not specified.--output-path: Path to which to write results.--output-columns: An ordered, comma-delimited list of columns to include in the output. Available columns:filename,signature_id,signature_name,signature_description,matched_text. Compatible formats: csv, tsv, null-delimited, line-delimited, human.-m,--output-format: Output format used for result data.--output-headers: Include column headers in output. Compatible formats: csv, tsv, null-delimited, line-delimited.-e,--exclude-signatures: Specify rule IDs to exclude from the scan. Can be comma-delimited and/or specified multiple times.-i,--include-signatures: Specify rule IDs to include in the scan. Can be comma-delimited and/or specified multiple times.--images: Include image files in the scan.-a,--include-all-files: Scan all files. By default, only files matching certain extensions are scanned-n,--include-files: Only scan filenames that are exact matches. Can be used multiple times.-x,--exclude-files: Do not scan filenames that are exact matches. Can be used multiple times. Denials take precedence over allows.-N,--include-files-pattern: Python regex allow pattern. Only matching filenames will be scanned.-X,--exclude-files-pattern: Python regex deny pattern. Matching filenames will not be scanned.--allow-io-errors: Allow scanning to continue if IO errors are encountered. Files that cannot be read will be skipped and a warning will be logged.-z,--chunk-size: Size of file chunks that will be scanned. Use a whole number followed by one of the following suffixes: b (byte), k (kibibyte), m (mebibyte). Defaults to 3m.-M,--scanned-content-limit: The maximum amount of data to scan in each file. Content beyond this limit will not be scanned. Defaults to 50 mebibytes. Use a whole number followed by one of the following suffixes: b (byte), k (kibibyte), m (mebibyte).--match-engine: The regex engine to use for malware scanning. Options:pcre,vectorscan(default:pcre)--match-all: If set, all possible signatures will be checked against each scanned file. Otherwise, only the first matching signature will be reported--pcre-backtrack-limit: The regex backtracking limit for signature evaluation--pcre-recursion-limit: The regex recursion limit for signature evaluation-w,--workers: Number of worker processes used to perform scanning. Defaults to 1 worker process.--progress: Display scan progress in the terminal with a curses interface
INI Options
[MALWARE_SCAN]
# Read file paths to scan from stdin
read_stdin = [on|off]
file_list_separator = <separator string, defaults to null byte>
# Controls whether or not output is written to stdout
output = [on|off]
output_path = <path to which to write results>
# Comma-delimited list of columns to include in output (`filename`, `signature_id`, `signature_name`, `signature_description`, `matched_text`)
output_columns = <columns>
output_format = [human|csv|tsv|null-delimited|line-delimited]
# Whether to include headers in output
output_headers = [on|off]
# Comma-delimited list of signature IDs
exclude_signatures = <signatures>
include_signatures = <signatures>
images = [on|off]
include_all_files = [on|off]
# Comma-delimited list of filenames
include_files = <filenames>
exclude_files = <filenames>
# Comma-delimited list of Python regex patterns
include_files_pattern = <patterns>
exclude_files_pattern = <patterns>
allow_io_errors = [on|off]
# Files are scanned in chunks of this size, may use b, k, or m suffix
chunk_size = <size>
# Maximum amount of data to scan for each file, may use b, k, or m suffix
scanned_content_limit = <size>
match_engine = [pcre|vectorscan]
match_all = [on|off]
# Backtrack limit option for PCRE, should be an integer
pcre_backtrack_limit = <limits>
# Number of workers to use
workers = <number>
# Alternate database path when using vectorscan
pattern_database_path = <path>
# Whether or not to compile the vectorscan database locally
compile_local = [on|off]
# Toggle direct IO (avoids filesystem caching)
direct_io = [on|off]
Examples
Scanning a single directory for malware
A basic example of recursively scanning the /var/www directory for malware.
wordfence malware-scan /var/www
Writing malware scan results to a CSV
A basic example of recursively scanning the /var/www directory for malware and writing the results to /home/username/wordfence-cli-scan.csv.
wordfence malware-scan --output-format csv --output-path /home/username/wordfence-cli-scan.csv /var/www
Running Wordfence CLI in a cron
Run Wordfence CLI in a cron job daily to scan /var/www and email the results to example@example.com. The results are also written to /home/username/wordfence-cli-scan.csv as the username user. This would be similar to how a scheduled scan works within the Wordfence plugin.
0 0 * * * username /usr/bin/flock -w 0 /tmp/wordfence-cli-scan.lock /usr/local/bin/wordfence malware-scan --output-format csv --output-path /home/username/wordfence-cli-scan.csv --email example@example.com /var/www 2>&1 /var/log/wordfence/malware-scan.log; /usr/bin/rm /tmp/wordfence-cli-scan.lock
The cronjob uses a lock file at /tmp/wordfence-cli-scan.lock to prevent duplicate scans from running at the same time. Any output and errors are logged to /var/log/wordfence/malware-scan.log. Please update the paths from this example based on the system this is intended to run on.
Piping files from find to Wordfence CLI
Find files under the directory /var/www/ that have changed in the last hour and scan them with Wordfence CLI:
find /var/www/ -cmin -60 -type f -print0 | wordfence malware-scan
We recommend that you use ctime over mtime and atime as changing the ctime of a file requires root access to the file system. mtime and atime can be arbitrarily set by the file owner using the touch command.
Automatically repairing known files belonging to WordPress
Run Wordfence CLI on a WordPress installation under /var/www/wordpress and automatically repair any files infected with malware:
wordfence malware-scan --output-columns filename -m null-delimited /var/www/wordpress | wordfence remediate
Automatically repairing known files, and automatically deleting unknown files
Run Wordfence CLI on a WordPress installation under /var/www/wordpress and automatically repair any files infected with malware. For any additional files found that aren't automatically repaired, delete them:
wordfence malware-scan --output-columns filename -m null-delimited /var/www/wordpress | wordfence remediate --output-columns path -m null-delimited -u | xargs -0 rm
Remediation
Wordfence CLI, as of version 3.0.1, comes with a new subcommand, wordfence remediate, to automatically repair known files belonging to a WordPress installation. Any file part of all versions of WordPress core, as well as all versions of plugins and themes available for download on wordpress.org can be automatically downloaded to restore a file infected with malware.
To see remediate in action, visit the examples page.
Remediate Command Line Arguments
General Options:
-c,--configuration: Path to a configuration INI file to use. (default:~/.config/wordfence/wordfence-cli.ini)-l,--license: Specify the license to use.--version: Display the version of Wordfence CLI.-h,--help: Display help information.--accept-terms: Automatically accept the terms required to invoke the specified command.--read-stdin: Read paths from stdin. If not specified, paths will automatically be read from stdin when input is not from a TTY. (use--no-read-stdinto disable)-s,--path-separator: Separator used to delimit paths when reading from stdin. Defaults to the null byte.
Output Control:
Faster Scanning with Vectorscan
The malware scan currently has 2 separate scan signature engines, libpcre and Vectorscan. While both of these scan engines are highly performant, Vectorscan is software designed to address the specific use-case we have with malware scanning, where we need to run a large number of regular expressions against a stream of data.
Benchmarks for Performance Increase using Vectorscan
Benchmarking has indicated that Vectorscan can be more than 30 times as fast as the exact same scan on the exact same hardware using PCRE.
| Files | Matches | Data | Workers | PCRE Time | Vectorscan Time | Improvement | Library | CPU |
|---|---|---|---|---|---|---|---|---|
| 12,006 | 11,998 | 605.4 MiB | 1 | 388s | 16s | ~25x | Hyperscan 5.2.1 | AMD Ryzen 7 1700 |
| 3,499 | 1 | 54.7 MiB | 4 | 42s | 3s | 14x | Hyperscan 5.2.1 | AMD Ryzen 7 1700 |
| 25905 | 25001 | 1.7 GiB | 32 | 38s | 4s | ~10x | Hyperscan 5.4.0 | AMD Ryzen 9 5950X |
| 25905 | 25001 | 1.7 GiB | 8 | 98s | 3s | ~32x | Hyperscan 5.4.0 | AMD Ryzen 9 5950X |
| 25905 | 25001 | 1.7 GiB | 4 | 191s | 6s | ~32x | Hyperscan 5.4.0 | AMD Ryzen 9 5950X |
| 25905 | 25001 | 1.7 GiB | 1 | 710s | 21s | ~34x | Hyperscan 5.4.0 | AMD Ryzen 9 5950X |
(The above benchmarks were conducted using a free Wordfence CLI license)
Configuring CLI to use Vectorscan
By default, CLI will use libprce for scanning. To configure CLI to use Vectorscan, you can use the following command-line argument:
wordfence malware-scan --match-engine=vectorscan
This can also be set in the INI file:
[MALWARE_SCAN]
match_engine=vectorscan
Installing Vectorscan/Hyperscan
On Debian-based distros, Vectorscan can be installed with apt:
$ sudo apt install libvectorscan5
Vectorscan is a fork of Hyperscan and maintains a compatible API, so installing Hyperscan on Intel-based systems will work as well.
$ sudo apt install libhyperscan5
We do currently support both technologies, but this may change over time if Vectorscan's API diverges from Hyperscan's. We will officially support Vectorscan going forward.
Additional installation instructions can be found in the Vectorscan Wiki.
Downloading/Compiling Vectorscan signatures
When running a supported version of vectorscan on a supported platform, a pre-compiled Vectorscan signature database will be downloaded from the Wordfence servers automatically. This is currently rate limited to 1 request every 12 hours. Ensure that caching is enabled to avoid hitting this rate limit (the database is cached for 24 hours by default).
Alternatively, you may use the --compile-local option to pull the standard signatures from the Wordfence API and compile them to a platform-specific Vectorscan database locally. This will avoid the above rate limit but will take a significant amount of time during the scan.
Known issues
Segfaults on Ubuntu versions 22.04 and 24.04
The Vectorscan package provided by Ubuntu versions 22.04 and 24.04 will produce segfaults when performing malware scanning against certain files on some ARM systems. We've identified that this is an issue specifically with the packaged version. Compiling Vectorscan from scratch does not produce the same segfaults. We've created a ticket on LaunchPad for this issue.
Negligible Performance Improvement over NFS
CLI will oftentimes have to scan large filesystems of relatively small files. NFS is not setup particularly well to serve many small files. Vectorscan can scan these small files fast enough where there can be not much of discernible difference between using libprce and Vectorscan since the scanning processes are largely I/O bound while waiting on NFS to provide the file contents.
We've observed in our own benchmarks that there is not a significant performance increase using Vectorscan over libpcre for filesystems over NFS shares.
Remediation Configuration
Remediation can be configured using either command line arguments, the INI file, or a combination of both.
Command Line Arguments
--read-stdin: Read paths from stdin-s,--path-separator: Path separator when reading from stdin, defaults to null byte--require-path: Require at least one path be provided for scanning--allow-nested: Allow nested WordPress installations--allow-io-errors: Allow counting to continue if IO errors are encountered
INI Options
[COUNT_SITES]
# Read paths from stdin
read_stdin = [on|off]
# Separator string when reading paths from stdin, defaults to null byte
path_separator = <separator>
allow_nested = [on|off]
allow_io_errors = [on|off]
Examples
Restore the original contents of a plugin file
wordfence remediate /var/www/html/wp-content/plugins/hello.php
Restore all files in a theme directory and output the results to a CSV file
wordfence remediate --output-format csv --output-path /tmp/wfcli-remediation-results.csv --output-headers /var/www/html/wp-content/themes/twentytwentythree
Automatically deletect and remediate malware under /var/www/wordpress
wordfence malware-scan --output-columns filename -m null-delimited /var/www/wordpress | wordfence remediate
Vulnerability Scan Configuration
Vulnerability scanning can be configured using either command line arguments, the INI file, or a combination of both.
Command Line Arguments
--read-stdin: Read WordPress base paths from stdin. If not specified, paths will automatically be read from stdin when input is not from a TTY.-s,--path-separator: Separator used to delimit paths when reading from stdin. Defaults to the null byte.-w,--wordpress-path: Path to the root of a WordPress installation to scan for core vulnerabilities.-p,--plugin-directory: Path to a directory containing WordPress plugins to scan for vulnerabilities.-t,--theme-directory: Path to a directory containing WordPress themes to scan for vulnerabilities.-C,--relative-content-path: Alternate path of the wp-content directory relative to the WordPress root.-P,--relative-plugins-path: Alternate path of the wp-content/plugins directory relative to the WordPress root.-M,--relative-mu-plugins-path: Alternate path of the wp-content/mu-plugins directory relative to the WordPress root.--output: Write results to stdout. This is the default behavior when --output-path is not specified.--output-path: Path to which to write results.--output-columns: An ordered, comma-delimited list of columns to include in the output. Available columns:software_type,slug,version,id,title,link,description,cve,cvss_vector,cvss_score,cvss_rating,cwe_id,cwe_name,cwe_description,patched,remediation,published,updated,scanned_path. Compatible formats: csv, tsv, null-delimited, line-delimited.-m,--output-format: Output format used for result data.--output-headers: Include column headers in output. Compatible formats: csv, tsv, null-delimited, line-delimited.-e,--exclude-vulnerability: Vulnerability UUIDs or CVE IDs to exclude from scan results.-i,--include-vulnerability: Vulnerabilitiy UUIDs or CVE IDs to include in scan results.-I,--informational: Include informational vulnerability records in results.-f,--feed: The feed to use for vulnerability information. The production feed provides all available information fields. The scanner feed contains only the minimum fields necessary to conduct a scan and may be a better choice when detailed vulnerability information is not needed.--require-path: When enabled, an error will be issued if at least one path to scan is not specified. This is the default behavior when running in a terminal.
INI Options
[VULN_SCAN]
# Read WordPress paths from stdin
read_stdin = [on|off]
# Separator to use when reading paths from stdin, defaults to null byte
path_separator = <separator>
# Alternate relative path for wp-content
relative_content_path = <path>
# Alternate relative path for wp-content/plugins
relative_plugins_path = <path>
# Alternate relative path for wp-content/mu-plugins
relative_mu_plugins_path = <path>
# Controls whether or not output is written to stdout
output = [on|off]
output_path = <path to which to write results>
# Comma-delimited list of columns to include in output (`software_type`, `slug`, `version`, `id`, `title`, `link`, `description`, `cve`, `cvss_vector`, `cvss_score`, `cvss_rating`, `cwe_id`, `cwe_name`, `cwe_description`, `patched`, `remediation`, `published`, `updated`, `scanned_path`)
output_columns = <columns>
output_format = [human|csv|tsv|null-delimited|line-delimited]
# Whether to include headers in output
output_headers = [on|off]
# Comma-delimited list of vulnerability UUIDs or CVE IDs
exclude_vulnerability = <ids>
include_vulnerability = <ids>
# Toggle informational vulnerabilities
informations = [on|off]
feed = [production|scanner]
allow_nested = [on|off]
allow_io_errors = [on|off]
Examples
Scanning a single WordPress installation for vulnerabilities
A basic example of scanning the /var/www/wordpress directory for vulnerabilities.
wordfence vuln-scan /var/www/wordpress
Writing vulnerability scan results to a CSV
A basic example of scanning the /var/www/wordpress directory for vulnerabilities and writing the results to /home/username/wordfence-cli-vuln-scan.csv.
wordfence vuln-scan --output-format csv --output-path /home/username/wordfence-cli-vuln-scan.csv /var/www/wordpress
Running the vulnerability scan in a cron
Run Wordfence CLI in a cron job daily to scan /var/www/wordpress and write the results to /home/username/wordfence-cli-vuln-scan.csv as the username user. This would be similar to how a scheduled scan works within the Wordfence plugin.
0 0 * * * username /usr/bin/flock -w 0 /tmp/wordfence-cli-vuln-scan.lock /usr/local/bin/wordfence vuln-scan --output-format csv --output-path /home/username/wordfence-cli-vuln-scan.csv /var/www/wordpress 2>&1 /var/log/wordfence/vuln-scan.log; /usr/bin/rm /tmp/wordfence-cli-vuln-scan.lock
The cronjob uses a lock file at /tmp/wordfence-cli-vuln-scan.lock to prevent duplicate vulnerability scans from running at the same time. Any output and errors are logged to /var/log/wordfence/vuln-scan.log. Please update the paths from this example based on the system this is intended to run on.