Skip to content
hina-kura49Public

About

WordPress のサイトに仕込まれた Web シェル・裏口・改ざんを探す CLI(読むだけ・PHP は実行しない)/ Find web shells, backdoors and tampering in WordPress installs

Topics

Resources

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Repository files navigation

WPware logo

WPware

Find what was planted in your WordPress, without running a single line of it.

CI Release License: MIT OR Apache-2.0 Rust

Product page · Download · Usage · English · 日本語

WPware is a single-binary scanner for web shells, backdoors and tampering in WordPress sites. Point it at a WordPress folder. It checks every file against the official wordpress.org checksums, runs YARA rules over the rest, and statically unwraps layered obfuscation, so you can see what the hidden code actually does.

wpware scan finds a web shell hidden in an .ico file and unwraps three layers of obfuscation

WPware only reads. It never writes, moves or deletes a file, and it never runs PHP. Reports come in English (--lang en) or Japanese (the default), and as JSON or SARIF for tools.

Download

Pick the file for your computer. These links always point to the newest release.

OS File
Linux (x86_64) wpware-linux-x86_64.tar.gz
Linux (arm64) wpware-linux-aarch64.tar.gz
macOS (Apple silicon) wpware-macos-aarch64.tar.gz
macOS (Intel) wpware-macos-x86_64.tar.gz
Windows (x86_64) wpware-windows-x86_64.zip
Checksums SHA256SUMS

On Linux or a server, one line downloads it, checks it and installs it:

f=wpware-linux-x86_64.tar.gz; u=https://github.com/hina-kura49/wpware/releases/latest/download
curl -fsSLO "$u/$f" && curl -fsSL "$u/SHA256SUMS" | grep " $f\$" | sha256sum -c - \
  && tar -xzf "$f" wpware && sudo install wpware /usr/local/bin/

On macOS, use wpware-macos-aarch64.tar.gz (or -x86_64) and shasum -a 256 -c - instead of sha256sum -c -. On Windows, unzip the file and run wpware.exe from PowerShell.

With Rust 1.95 or later you can also build it yourself:

cargo install --locked --git https://github.com/hina-kura49/wpware wpware

All releases are on the Releases page.

Usage

# Scan a site (the folder that contains wp-includes/)
wpware scan /var/www/html --lang en

# Only show high and critical findings
wpware scan /var/www/html --lang en --show high

# Use the exit code in scripts: 0 clean · 2 low/medium · 3 high · 4 critical
wpware scan /var/www/html --fail-on high || echo "look at this site"

Each finding tells you which file, why it is suspicious, and what to do next. When the code was hidden, the report shows the decoded payload too. See Reference for every option.

When you'll use it

  • A client says their site redirects to a spam page. Copy the site (or SSH in) and run wpware scan. Within a minute you see which core files were changed, the .htaccess rule that only redirects visitors from search engines, and the decoded backdoor in uploads that put it there.
  • A plugin you use just had a vulnerability disclosed. You updated it, but were you hit before that? A scan shows files that do not match the official release of that plugin, and PHP files that should not exist, so you know whether to start incident response or move on.
  • A nightly check on your server. Run it from cron with --fail-on high. It exits non-zero only when something serious appears, so you get an email on the night a web shell is planted and silence on every other night.
  • Findings in GitHub code scanning. If your site lives in a Git repository, the GitHub Action writes SARIF and uploads it, so new findings show up under Security → Code scanning on every push.

Why WPware

When a WordPress site is compromised, the first question is "which files did they touch?". The usual answers are a plugin that runs inside the infected site, a PHP script you upload to the server, or a commercial service. WPware takes a different approach:

Read-only, by design WPware never writes, moves or deletes files, and it never executes PHP. Obfuscation is unwrapped with pure string transformations reimplemented in Rust.
Checksums first Every file that matches the official wordpress.org checksum is set aside. What remains is what changed. That is why WPware stays quiet on a clean site. A scan of stock WordPress 7.1.5 (ja) with five popular plugins found 0 false positives in 19,621 files.
Shows the payload WPware does not just say "obfuscated code". It undoes base64_decode → gzinflate → str_rot13 → … and prints the decoded code: system($_POST['c']);.
Fits automation It is one static binary with no PHP, Python or database needed. Exit codes reflect severity, SARIF output works with GitHub code scanning, and a ready-made GitHub Action is included.
Permissive license MIT or Apache-2.0. The detection rules were written from scratch for this project.

What it detects

ID Severity What
core.modified high A WordPress core file differs from the official one.
core.unknown_file high A file in wp-admin/, wp-includes/ or the root wp-* files that is not part of WordPress.
core.missing info An official core file is missing.
plugin.modified high A wordpress.org plugin file differs from the release with the same version.
plugin.unknown_file medium A PHP file that is not part of that plugin release.
yara.eval_of_decoded_string critical eval / assert / create_function applied to a decoded string.
yara.request_to_command critical Request data passed straight into system, exec, passthru, shell_exec, popen or proc_open.
yara.request_to_eval critical Request data passed straight into eval or assert.
yara.request_as_function_name critical Request data used as a function name: $_GET['f']($_GET['a']).
yara.auth_bypass_backdoor critical Request-triggered wp_set_auth_cookie, or creation of an administrator account.
yara.preg_replace_eval_modifier critical preg_replace with the /e modifier.
yara.variable_function_from_request high Request data stored in a variable that is then called as a function.
yara.decode_chain high Two or more decoders nested together.
yara.file_manager_shell high Request-controlled file writes or upload moves.
yara.php_in_image high PHP code inside a PNG, JPEG, GIF or ICO file.
yara.known_shell_marker high Strings that public write-ups associate with well-known web shells.
yara.char_obfuscated_function medium Function names assembled with chr() calls or \x escapes.
location.php_in_uploads high A PHP file under wp-content/uploads.
location.php_code_in_uploads high A non-PHP file under uploads that contains PHP code.
location.php_disguised_as_image high A file with an image extension whose content is PHP.
location.lookalike_name high A name that imitates a core file, such as wp-c0nfig.php.
location.double_extension medium A double extension, such as shell.php.jpg.
location.mu_plugin low A file in mu-plugins. These always run and cannot be disabled from the dashboard.
config.image_as_php critical AddHandler / AddType / SetHandler that runs image files as PHP.
config.auto_prepend_file high auto_prepend_file / auto_append_file in .htaccess, .user.ini or php.ini.
config.conditional_redirect high A redirect to another site that only applies to search-engine referrers or mobile user agents.
heuristic.obfuscation low–medium High entropy, very long lines or long unbroken strings.
deobf.layers medium–critical Hidden code that the deobfuscator could unwrap.

Reference

wpware scan [OPTIONS] <PATH>
Option Description
--json JSON output: the full report, including skipped files and notes.
--sarif SARIF 2.1.0 output for GitHub code scanning and other SARIF viewers.
-o, --output <FILE> Write the report to a file instead of stdout.
--offline Never use the network. Only cached checksums are used, and anything without one is listed as unverified.
--no-checksums Skip the integrity stage.
--cache-dir <DIR> Checksum cache. The default is $XDG_CACHE_HOME/wpware, ~/Library/Caches/wpware on macOS, or %LOCALAPPDATA%\wpware on Windows.
--rules <FILE> Load extra YARA rules. Can be repeated. Their matches show up as yara.userN.<rule>.
--max-size <BYTES> Skip files larger than this (default 16 MiB). Skipped files are listed in the report.
--fail-on <LEVEL> Lowest severity that makes the exit code non-zero (default low).
--show <LEVEL> Lowest severity printed in the text report (default low).
--ignore-file <FILE> Silence reviewed findings listed in a TOML file. See Ignoring reviewed findings.
--emit-ignore Print an ignore-file template for the current findings instead of the report.
--lang <ja|en> Language of titles, reasons and next steps, in every output format (default ja).

Exit codes

Code Meaning
0 Nothing at or above --fail-on was found.
1 Error, such as a missing folder or invalid rules.
2 The worst finding is low or medium.
3 The worst finding is high.
4 The worst finding is critical.

JSON output

{
  "rule_id": "yara.eval_of_decoded_string",
  "category": "signature",
  "severity": "critical",
  "path": "wp-content/uploads/2024/01/cache.ico",
  "line": 1,
  "title": "Decoded string executed as code",
  "reason": "A decoded string (base64_decode, gzinflate, str_rot13, ...) is passed to eval…",
  "next_step": "Likely a web shell or backdoor. Before deleting anything, …",
  "deobfuscated": {
    "layers": ["str_rot13", "gzinflate", "base64_decode"],
    "sink": "eval",
    "excerpt": "system($_POST['c']);"
  }
}

Ignoring reviewed findings

Some findings are expected on a given site, for example a file your hosting provider puts in mu-plugins. Once you have checked such a finding, list it in an ignore file so that only new problems show up:

wpware scan /var/www/html --emit-ignore > wpware-ignore.toml   # template for current findings
$EDITOR wpware-ignore.toml                                       # keep only what you reviewed, fill in reasons
wpware scan /var/www/html --ignore-file wpware-ignore.toml
[[ignore]]
rule = "location.mu_plugin"                    # rule ID, or "*"
path = "wp-content/mu-plugins/hosting-*.php"   # glob: *, **, ?
sha256 = "9f86d081884c7d65…"                   # optional, recommended
reason = "Installed by the hosting provider"    # required
  • An entry applies only when every field it sets matches.
  • With sha256, the entry stops applying as soon as the file changes, so a reviewed file that gets tampered with later shows up again. --emit-ignore pins it for you.
  • Silenced findings are not lost. The text report shows how many there were, and --json lists them under suppressed.
  • Keep the ignore file outside the site. WPware never loads one from the scanned folder on its own, and it warns if you pass one that lives there, because an attacker who can write to the site could use it to hide their files.

Nightly cron

# Mail the report only when something at "high" or above shows up
0 3 * * *  wpware scan /var/www/html --lang en --fail-on high > /tmp/wpware.txt 2>&1 || mail -s "WPware: check $(hostname)" you@example.com < /tmp/wpware.txt

GitHub Action

If your site lives in a Git repository, findings can appear under Security → Code scanning:

name: WPware
on: [push, workflow_dispatch]
permissions:
  contents: read
  security-events: write
jobs:
  scan:
    runs-on: ubuntu-latest
    steps:
      - uses: actions/checkout@v4
      - uses: hina-kura49/wpware@v1
        with:
          path: public_html   # folder that contains wp-includes/
          fail-on: high       # info | low | medium | high | critical
          args: --lang en

The action downloads the release binary, checks it against SHA256SUMS, writes wpware.sarif, and uploads it to code scanning. Set upload-sarif: "false" to skip the upload. @v1 always runs the newest 1.x release; pin @v1.0.0 to stay on one version.

Servers without internet access

Run one scan on a machine with internet access, then copy its cache directory to the server and add --offline:

wpware scan ./copy-of-site --cache-dir ./wpware-cache      # online machine
wpware scan /var/www/html --cache-dir ./wpware-cache --offline   # server

Safety model

  • No writes. Files are only opened for reading. If quarantine is ever added, it will be a separate command.
  • No execution. PHP is never executed or included. Each decoder is a small Rust function with output size and depth limits.
  • Stays inside the folder. Symbolic links are never followed. They are listed as skipped. Every read re-checks that the path is a regular file.
  • Bounded. There is a per-file size cap, a YARA scan timeout, and limits on decoding depth and output size.
  • Minimal network access. Only api.wordpress.org and downloads.wordpress.org are contacted, and only for checksums. Versions and slugs are validated before they are put into a URL or a cache path.
  • Clean sources. The rules were written only from public information. No samples or customer data from real incident-response cases were used.
  • No live malware in the repo. Test samples are harmless synthetic strings built at test time.

Limitations

"Nothing found" does not mean "clean". In particular, WPware does not see:

  • The database. Injected <script> tags in posts or options, and rogue administrator accounts, live in MySQL, not in files.
  • Plugins and themes outside wordpress.org. Premium plugins and themes cannot be verified against checksums, although their content is still scanned. wordpress.org has no checksum API for themes.
  • Obfuscation that needs runtime state. For example, code that builds function names from variables across several files.
  • Anything outside the scanned folder. Other sites on the same server, cron jobs, and the OS itself.

If you think a site has been compromised, take a full backup and keep the access logs before you clean anything. Then ask a professional if you can.

FAQ

WPware flagged a file. Should I delete it?

Not yet. First take a full backup, including the database and the access logs, and write down the file's timestamps. They tell you when the intruder got in. Then compare the file with the official version, or look at the decoded payload in the report. Deleting a web shell without fixing the hole it came through usually means it comes back.

I'm getting a false positive.

Signature rules intentionally err on the side of reporting. Open an issue with the rule ID and a harmless, minimal snippet that triggers it. Please do not attach the real file. Generated files that only return an array, such as translation *.l10n.php files, are already excluded from the heuristics.

Does WPware upload my files anywhere?

No. The only outgoing requests are checksum lookups to wordpress.org. They contain the WordPress version, the locale, and the slugs and versions of your plugins. Use --offline to send nothing at all.

Why is Japanese the default language?

WPware is aimed first at small businesses in Japan whose WordPress site has been compromised. They need a report they can read and act on. Add --lang en for English. Identifiers such as rule_id and severity are the same in both languages, so tooling does not depend on the language.

For developers

How it works

flowchart LR
    A[Walk the folder<br/>no symlinks · size cap] --> B{Official<br/>checksum?}
    B -- matches --> OK[Set aside<br/>as official]
    B -- differs / unknown --> C[Location checks<br/>uploads · .htaccess · names]
    C --> D[YARA-X rules]
    D --> E[Heuristics<br/>entropy · long lines]
    E --> F[Unwrap obfuscation<br/>no execution]
    F -->|decoded code| D
    F --> R[Report<br/>text · JSON · SARIF]
Loading
  1. Integrity. WPware reads the version and locale from wp-includes/version.php, as plain text, and fetches the matching checksums from api.wordpress.org. Plugins hosted on wordpress.org are verified against the checksums for their exact version. Checksums are cached on disk, so later scans can run with --offline.
  2. Location. It checks where files live and what they are named: PHP in uploads, images that contain PHP, .htaccess tricks, mu-plugins, names that imitate core files.
  3. Signatures. YARA-X rules look for the shapes web shells take. The rules are built into the binary. Add your own with --rules.
  4. Heuristics. It looks for statistical signs of packed code: very long lines, high entropy, and long runs with no word break.
  5. Deobfuscation. Calls such as base64_decode('…') on string literals are evaluated in Rust, layer by layer. The decoded text goes through the rules again, so the report can say what the hidden code does.

Build from source

Rust 1.95 or later:

cargo install --locked --git https://github.com/hina-kura49/wpware wpware
# or, from a clone
cargo build --release --locked -p wpware

Contributing

Issues and pull requests are welcome, especially new detection rules. Each rule should come with:

  1. a link to the public write-up it is based on,
  2. a harmless synthetic test case, and
  3. a check that it stays quiet on a clean WordPress install.
cargo test --workspace
cargo clippy --workspace --all-targets -- -D warnings
cargo deny check

To regenerate the demo GIFs, run vhs docs/demo-en.tape and vhs docs/demo-ja.tape. See the comments in the tape files for the setup they expect.

Prior art

WPware borrows ideas, not code, from these projects:

Project License Idea
wp-cli/checksum-command MIT Checksum verification flow and which files are in scope
php-malware-finder LGPL-3.0 Following the chain from user input, through a decoder, to a dangerous sink
linux-malware-detect GPL-2.0 Staged detection, cheapest checks first
NeoPI CC BY-SA 3.0 Entropy and longest-word statistics for packed code
PHP-Antimalware-Scanner GPL-3.0 A rule ID, severity and explanation for every pattern; SARIF output
wordfence-cli GPL-3.0 Keeping progress output separate from results

The detection engine is YARA-X (BSD-3-Clause), used as a library.

Roadmap

  • Plugin and theme vulnerability lookup by (slug, version), using an open data source
  • A separate, explicit quarantine command that moves files and records hashes

Security

Found a vulnerability in WPware itself? Please report it privately. See SECURITY.md.

License

Licensed under either of

at your option. Bundled third-party licenses are listed in THIRD-PARTY-LICENSES.md.

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in WPware, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

Author

Made by kura · Portfolio · GitHub · X · Instagram · Facebook

About

WordPress のサイトに仕込まれた Web シェル・裏口・改ざんを探す CLI(読むだけ・PHP は実行しない)/ Find web shells, backdoors and tampering in WordPress installs

Topics

Resources

Security policy

Stars

4 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages