WordPress wp-config.php Hack: Suspicious Code and Safe Cleanup Steps

Inspecting and safely cleaning a hacked WordPress wp-config.php file

A WordPress wp-config.php hack is serious because this file loads before most themes and plugins. One injected include, remote loader, or encoded block can run on every request, recreate deleted malware, or expose database credentials even while the homepage still appears normal.

If you find suspicious code, do not delete the whole file or replace it blindly. Preserve the current copy, identify the settings your site genuinely needs, compare the structure with a clean reference, and treat the discovery as evidence of a wider compromise.

RyoheiYokoyama

I’m Ryohei Yokoyama, founder of SiteFixNow. I’ve worked as an IT engineer for over 20 years and have handled many WordPress recovery, malware removal, hacked site repair, and security cleanup cases. In this guide, I’ll show you how to inspect and recover wp-config.php without destroying legitimate configuration.

What you’ll learn
  • What to preserve before editing a hacked configuration file
  • How to distinguish normal WordPress settings from suspicious persistence code
  • How to clean or rebuild wp-config.php without breaking database access
  • Which secrets, access points, and nearby files to check after recovery
On This Page

WordPress wp-config.php hack response starts by preserving evidence

Secure evidence copy of a suspicious WordPress configuration file before cleanup

The safest first action is to copy the current wp-config.php, record its path, owner, permissions, size, and modification time, and preserve a complete file-and-database backup. A suspicious file is not a backup you should deploy, but it may show how persistence was established.

Preserve before changing anything
  • The current wp-config.php under a clearly marked infected-evidence filename
  • A complete database export and a copy of the whole document root
  • Hosting malware reports, access logs, error logs, and recent file timestamps
  • A list of legitimate administrators, SFTP users, database users, and control-panel accounts

Store evidence outside public_html, htdocs, or any web-accessible backup directory. If you need help choosing a clean recovery point, follow the safe order in the guide to safe WordPress backup restore after a hack.

WordPress wp-config.php hack checks must separate normal settings from malware

Comparing suspicious WordPress configuration code with a clean reference file

Unfamiliar code is not automatically malicious. Managed hosts, caching systems, reverse proxies, security tools, multisite networks, and deployment platforms may add legitimate constants or includes. The correct test is whether the line is expected, documented, and traceable to a trusted component.

Usually legitimate when expected
  • DB_NAME, DB_USER, DB_PASSWORD, and DB_HOST
  • Authentication keys, salts, and $table_prefix
  • WP_DEBUG, memory, cache, SSL, proxy, or environment constants you can explain
  • The final require_once ABSPATH . 'wp-settings.php'; loader

Warning signs include long encoded strings, error suppression around an unknown loader, remote URLs, paths into uploads or temporary folders, code that writes new PHP files, and conditionals that run only for certain visitors. A legitimate include should point to a file you recognize and can inspect.

Investigate unexpected uses of:
eval or assert with decoded input
base64_decode, gzinflate, or long escaped strings
includes under uploads, tmp, cache, or hidden folders
remote requests or code that writes executable files

Do not delete every function-name match. Compare its source, path, context, timestamp, and deployment history. The broader WordPress file infection cleanup guide explains how this file relates to plugins, themes, and uploads.

WordPress wp-config.php hack cleanup is safer when you rebuild deliberately

If the suspicious addition is small and clearly isolated, you may remove only that block from a working copy, validate the PHP syntax, and test the result in staging. If the file contains many unknown edits, rebuilding from the current WordPress wp-config-sample.php is usually easier to audit.

Safe rebuild order
  1. Start from the sample matching the installed WordPress version.
  2. Copy the database constants and exact table prefix from evidence.
  3. Generate fresh salts instead of reusing potentially exposed ones.
  4. Validate syntax, upload atomically, and test in staging or maintenance mode.
php -l wp-config.php.clean
chmod 600 wp-config.php.clean

# Rename in one operation only after backup and validation:
mv wp-config.php wp-config.php.infected-evidence
mv wp-config.php.clean wp-config.php

Never paste your database password, salts, or the full wp-config.php file into a public forum, malware scanner, or AI prompt.

WordPress wp-config.php hack recovery requires new secrets and a closed entry point

Rotating WordPress security keys and closing the attack path after wp-config cleanup

Assume secrets in a compromised wp-config.php may have been read. Rotate the WordPress authentication keys and salts so existing sessions are invalidated, change the database user password, update the rebuilt file, and reset credentials for hosting, SFTP, SSH, administrators, and deployment services.

Close the compromise, not only the file
  • Update WordPress core, plugins, and themes from trusted sources
  • Remove abandoned components and review every administrator account
  • Check the database, uploads, must-use plugins, .user.ini, prepend directives, cron jobs, and neighboring sites for persistence
  • Enable logging and monitor changes to critical configuration files

If you cannot explain how the attacker changed the file, the incident is not fully resolved. Follow the wider files, database, and backdoor checks, then use the hardening steps to secure WordPress after malware removal.

WordPress wp-config.php hack cleanup must be verified before normal traffic returns

A clean-looking file is only one checkpoint. Test the front end, wp-admin, forms, scheduled jobs, email, checkout, APIs, and a private-browser visit from another device. Watch PHP errors and access logs while those requests run.

Verification checklist
  • PHP syntax is valid and the site connects to the intended database
  • Front end, dashboard, forms, jobs, and business functions work normally
  • No unexpected redirect, remote request, new file, or unknown user appears
  • Critical file hashes remain stable through normal traffic and scheduled tasks
  • Backups created after recovery are stored safely and tested separately

Keep the evidence archive outside public directories. Record what changed, which credentials were rotated, and why the final file is trusted so an infected copy is not restored later.

Frequently asked questions about a WordPress wp-config.php hack

Can I delete wp-config.php and let WordPress recreate it?

No. WordPress may start a setup flow, but it cannot safely reconstruct all site-specific values, host directives, salts, or custom constants. Preserve the file and rebuild deliberately from a clean sample when necessary.

Does base64_decode always mean wp-config.php is hacked?

No single function proves malware by itself. An unexpected encoded block in this file is a strong warning, but judge it by source, purpose, path, surrounding code, and comparison with a trusted configuration.

Why did suspicious code return after I removed it?

A remaining backdoor, scheduled task, prepend directive, compromised account, vulnerable component, or infected neighboring site may be rewriting the file. Repeated injection means the persistence path still needs investigation.

WordPress wp-config.php hack cleanup summary

A safe WordPress wp-config.php hack cleanup begins with evidence and a full backup, continues with a careful comparison of legitimate settings and suspicious code, and ends with a verified rebuild, secret rotation, entry-point investigation, and monitoring. Removing one strange line is not enough when the wider site may still contain a backdoor.

If You Can’t Secure or Recover Your WordPress Site Yourself

Ryohei Yokoyama, founder of Site Fix Now — WordPress site recovery, repair, defacement, malware removal and site hijacking specialist. Recovery in as little as 30 minutes.

If your website shows malware warnings, redirects to strange pages, or you are not sure whether it is secure,
SiteFixNow can help clean, repair, and recover your WordPress site.

Common problems we can help with
  • Your WordPress site may be infected with malware.
  • Security warnings appear in Google or browser results.
  • You found unknown admin users or suspicious files.
  • The site redirects to spam or unknown websites.
  • You need urgent WordPress hacked site repair.

We help with WordPress malware removal, hacked site repair, security cleanup, and recovery support.

Why ask for help early?
  • Reduce visitor risk and SEO damage.
  • Find hidden malware and backdoors, not only visible symptoms.
  • Recover the site safely without unnecessary data loss.

About the Author

Hello, I’m Ryohei Yokoyama, an IT engineer with over 20 years of experience.

I have received more than 776 reviews for WordPress recovery,
website repair, and online courses.

Many clients have shared comments such as:

“They restored my site so quickly!”
“They handled it the same day, which was a huge help!”

I am proud to have received a very high rating of 4.9 out of 5.0.

I have also published more than 30 books on WordPress, SEO, Microsoft Office, and related topics,
with multiple titles reaching No. 1 in sales rankings.

In addition, I have created more than 3,000 services, systems, and websites.

Through this experience, I have helped many people overcome technical problems, frustrations, and challenges.
Based on that practical perspective,
I explain complex topics in a clear and easy-to-understand way.

On This Page