How to Identify and Remove a PHP Backdoor on Your WordPress Site

YetHost – Best Web Hosting: Fast, Reliable & Affordable Solutions - Visit: https://yethost.com

If visitors to your WordPress site are being sent to a different website than the one you built, that is one of the strongest indicators that someone has injected malicious code into your files. The redirect can be selective — triggered only for specific browsers, IP ranges, or hours of the day — which is exactly why it often goes unnoticed for weeks.

Other signals worth taking seriously:

  • Pages load noticeably slower, or unexpected pop-up windows appear
  • Google or Bing displays a “this site may be harmful” warning to searchers
  • Your YetHost control panel’s File Manager shows files you never uploaded
  • A security scanner or your hosting provider has already flagged something
  • Traffic is being funneled to domains you have no relationship with

If any of these describe your situation, the next step is learning to recognize the malicious code itself. The snippet below is a representative PHP webshell dropper — a backdoor that gives an attacker the ability to execute commands on your server. You might have stumbled on it while browsing File Manager, or a scanner may have surfaced it for you. Use the patterns that follow to judge whether a file is dangerous.

Recognising a backdoor in PHP

A file of this kind typically combines several of the traits below:

php

<?php @ini_set('display_errors', '0');
error_reporting(0);
global $zeeta;
if (!$npDcheckClassBgp && !isset($zeeta)) {
    $ea = '_shaesx_'; $ay = 'get_data_ya'; $ae = 'decode';
    $ea = str_replace('_sha', 'bas', $ea);
    // ... builds "base64_decode" from pieces ...
    $pass = "Zgc5c4MXrK42MQ4F8YpQL/+fflvUNPlfnyDNGK/X/wEfeQ==";
Suspicious patternWhy it matters
@ini_set('display_errors', '0') alongside error_reporting(0)Suppresses error output so the attacker’s actions leave no trace in logs
Values assembled at runtime, e.g. str_replace('_sha', 'bas', '_shaesx_')Deliberate obfuscation to slip past signature scanners — this example reconstructs base64_decode
base64_decode paired with a hand-rolled XOR routineEncrypted payload that only the attacker can unlock
file_get_contents or curl pulling from a remote addressBeaconing to an external command-and-control server
preg_match('#gogo(.*)enen#is', ...)Carving a payload out of a response between fixed markers
Writing a dotfile such as .default, .algo, or .cache.phpPlanting a hidden, persistent backdoor
include(...) immediately followed by unlink(...)Running the dropped file and then erasing it to avoid detection
Odd globals like $npDcheckClassBgp and $zeetaLatch variables that stop the script from executing more than once

Places backdoors tend to hide

  • wp-content/uploads/ — legitimate WordPress uploads never include PHP files; any .php here is a red flag
  • wp-content/plugins/ and wp-content/themes/ — watch for files with meaningless or randomized names
  • The WordPress root — particularly wp-config.php and .htaccess
  • Hidden dotfiles — .default, .algo, .cache.php and similar names

If you have located a file matching any of the patterns above, assume the site is compromised and move on to Part 1. Deleting a single file is not enough: the attacker may have planted several backdoors, and whatever allowed them in the first time is probably still open.

YetHost note: If manually inspecting PHP is outside your comfort zone, install a scanner such as Wordfence (free tier) or Deep Malware Cleaner — both will flag the signatures described above. Alternatively, open a support ticket from your YetHost hosting control panel and our team will examine the file on your behalf.

Part 1 — Contain the Compromise

Work through these steps before touching any files. Their purpose is to sever the attacker’s access so they cannot re-enter while you clean.

1.1 Rotate every credential, in sequence

Updating the WordPress admin password alone leaves gaps. Address each layer:

  1. YetHost control panel password — with this, an attacker can reset everything else.
  2. FTP/SFTP credentials — change them and remove any FTP accounts you no longer need.
  3. Database password — then mirror the new value inside wp-config.php.
  4. Every WordPress administrator account — not just the one you use.

YetHost tip: To change your control panel password, hover over your name in the top-right corner of the panel and choose Change Password.

1.2 Regenerate WordPress security keys and salts

In wp-config.php (open it via the control panel’s File Manager), find the “Authentication Unique Keys and Salts” block and replace the whole thing with a fresh set from https://api.wordpress.org/secret-key/1.1/salt/.

Why this matters: every active login session is terminated at once, including any cookies an attacker may have captured.

1.3 Review administrator accounts

Go to WordPress Admin → Users and inspect every Administrator. For accounts you do not recognize:

  • Note the registration date and email address first.
  • Then delete the account or downgrade it to Subscriber.

Part 2 — Stop PHP From Running in the Uploads Directory (Top Priority)

The defining move of this backdoor is placing a PHP file in a web-reachable folder and executing it. If PHP cannot run inside wp-content/uploads/, that entire approach fails. WordPress has no legitimate reason to execute PHP from that directory.

2.1 Open File Manager

In the YetHost control panel, go to Files → File Manager and navigate to your WordPress root.

2.2 Go to the uploads folder

Open wp-content/uploads/.

2.3 Create or edit .htaccess

If the folder has no .htaccess, create one. If it already has one, back it up first, then add:

apache

<FilesMatch "\.(php|phtml|php[0-9]|pht|phar)$">
    Require all denied
</FilesMatch>

Why not php_flag engine off?
That instruction applies only under mod_php. YetHost shared servers run PHP-FPM, where it is silently ignored. The FilesMatch + Require all denied rule is enforced by Apache itself and works with any PHP handler.

2.4 Confirm the rule is active

  1. Place a temporary test.php in the uploads folder containing <?php echo "executed"; ?>
  2. Visit https://yourdomain.com/wp-content/uploads/test.php
  3. You should see: 403 Forbidden
  4. If you see executed instead: open a YetHost support ticket and ask us to verify that AllowOverride allows FilesMatch/Require on your account.
  5. Remove the test file when finished.

Part 3 — Turn Off WordPress’s Built-in File Editors

Should an attacker regain administrator access, WordPress’s plugin and theme editors would let them inject PHP directly — no upload required. Insert this line into wp-config.php, just above the /* That's all, stop editing! */ comment:

php

define( 'DISALLOW_FILE_EDIT', true );

The Appearance Editor and Plugin Editor disappear from the dashboard as a result.

Note: Resist the urge to use DISALLOW_FILE_MODS unless you also want to block plugin/theme installation and automatic updates — doing so slows down security patching. DISALLOW_FILE_EDIT is the safer choice.

Part 4 — Eliminate Remaining Backdoors

The dropper described earlier leaves behind a hidden .default file, but other variants exist. With no SSH access, use the control panel’s File Manager to hunt them down.

4.1 Search the uploads directory for PHP

Inside wp-content/uploads/, look for anything ending in .php, .phtml, or .phar. A healthy uploads directory holds zero PHP files. Download any you find for reference, then remove them from the server.

4.2 Review recently changed files

In public_html/ and wp-content/, sort by Last Modified (newest first) and examine anything touched in the last several days. Focus on:

  • wp-config.php
  • .htaccess
  • The active theme’s functions.php
  • Any PHP file with a strange or random filename

4.3 Deploy a malware scanner

Install a free option such as Wordfence (free tier) or Deep Malware Cleaner. They will scan wp-content and surface the signatures covered earlier — eval(base64_decode(...)), shell_exec, preg_replace with the /e modifier, and stray PHP files in upload directories. Investigate each high-risk result and delete what is confirmed malicious.

Caution: Scanners can flag legitimate code as suspicious. Confirm a file is actually malicious before deleting it, particularly inside active plugins or themes.

Part 5 — Shrink the Attack Surface

5.1 Remove plugins and themes you do not use

Inactive plugins and themes remain executable code on your server and can be exploited even when disabled. Delete anything you are not actively using. Avoid “nulled” or pirated plugins entirely — they are a common delivery vehicle for pre-installed backdoors.

5.2 Patch everything

Bring WordPress core, all active plugins, and all active themes up to their latest versions. Outdated components are the single most common way attackers get onto shared hosting.

Part 6 — What Shared Hosting Allows (and What YetHost Provides)

Shared hosting removes server-level control, so it helps to know where the boundaries are:

RiskYour options
Another account on the same server is compromised and reaches your filesYetHost isolates accounts and applies open_basedir restrictions. If you suspect cross-account contamination, open a ticket and we will investigate.
No web application firewall sits in front of your siteYetHost filters at the server level, but for extra protection we recommend Cloudflare’s free tier at the DNS level to block malicious requests before they reach your origin.
Backups can be stale or already infectedYetHost runs automated account backups, but you should also create manual backups through the control panel and download them locally. Never restore a snapshot taken after the infection date.

Verification Checklist

Confirm each item before treating the site as clean:

  • Control panel, FTP, database, and all WordPress admin passwords rotated
  • WordPress salts regenerated
  • Unrecognized administrator accounts removed
  • .htaccess in wp-content/uploads/ blocks PHP execution (test file returns 403)
  • DISALLOW_FILE_EDIT set to true in wp-config.php
  • No PHP files remain in wp-content/uploads/
  • Malware scanner reports clean
  • Unused plugins and themes deleted
  • WordPress core, plugins, and themes updated
  • Clean backup downloaded locally

What to Do If the Infection Comes Back

If suspicious files reappear after you complete every step, one of two things is true:

  1. A backdoor survived the cleanup, or
  2. The original entry point — most likely an unpatched plugin vulnerability — is still open.

Either way, the safest response is to restore a backup from before the infection date, then immediately re-apply Part 2 and Part 3 before the site goes back online. Once restored, review each plugin’s version history and update log to pinpoint how the attacker got in.

If you need help tracing the entry point, open a support ticket from your YetHost control panel and include the malicious file’s path plus any scanner output. Our team can review server logs for the original request that planted the backdoor.

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top