Revoke unauthorized Google Search Console owners and verification tokens first, then purge backdoors with WP-CLI and SQL and return 410 Gone for spam URLs.
Diagnose and Clean the Japanese Keyword Hack on WordPress
Remove rogue Search Console owners, purge injected wp_posts and backdoors with WP-CLI, serve 410 Gone headers, and recover from WordPress SEO spam.
// The short answer
In this guide · 7 sections
- 01Confirming the Infection and How Cloaking Works
- 02Isolate the Server and Grab an Offline Backup
- 03Kick Out Rogue Owners and Delete Verification Tokens
- 04Hunt Down and Wipe Out the Malware
- 05Delete Rogue Sitemaps and Serve 410 Gone Headers
- 06Patch the Entry Point and Reset All Passwords
- 07Ask Google for a Security Review
Cleaning up the Japanese keyword hack on WordPress means treating your site like an active crime scene, the attacker isn't just dropping spam files, they're actively using your Search Console properties to get those spam pages indexed. Before you even touch the database or start deleting files, your absolute first move has to be kicking them out of Search Console. If you skip that, the malicious pages will just keep regenerating.
- What You'll Need: SSH/Terminal access, WP-CLI, and a MySQL/MariaDB prompt. - Where It Hits:
.htaccessrouting,wp_postsinjections, and rogue sitemaps. - How It Sticks Around: Hidden HTML verification files, compromised admin users, and backdoor PHP scripts hiding in/wp-content/uploads/. - The Cleanup Phase: Serving410 Goneheaders on the spam URLs so Google drops them from search results faster.
Confirming the Infection and How Cloaking Works
Attackers use a trick called cloaking to show these spam pages only to Googlebot and people clicking through from search results. That's why if you visit one of the suspicious URLs directly in your browser, you'll probably just see a normal page or a standard 404 error.
Spot Indexed Spam with Search Operators
Run a quick site-specific search on Google to dig up the injected URLs that are hidden from your regular site navigation. Just search for your domain paired with a few common Japanese counterfeit terms:
site:yourdomain.com 激安 | site:yourdomain.com コピー | site:yourdomain.com 偽物
If you see Japanese characters showing up alongside your domain in the results, you've definitely got an infection on your hands.
Catch Hidden Payloads in Search Console
To get around the cloaking and see what Google's crawler is actually seeing, head into Google Search Console, drop one of those sketchy URLs into the URL Inspection tool, and hit View Crawled Page. Take a look at the HTML tab. If the page looks totally fine in your regular browser, yet the inspected HTML is packed with Japanese text and affiliate links, your server is actively cloaking the payload for Googlebot (much like how AI crawler and Googlebot verification separates real search bots from spoofed requests).

Isolate the Server and Grab an Offline Backup
Before you start changing database tables or deleting files, take a snapshot of the site as it stands right now. Even though it's infected, having a backup gives you a safety net in case you accidentally delete a legitimate config file during the cleanup.
SSH into your server and package up both your site files and your database:
# Archive the web root
tar -czvf /tmp/compromised_site_backup.tar.gz /var/www/html/
# Dump the database
mysqldump -u root -p your_database_name > /tmp/compromised_db_backup.sqlDownload both of those files to your local computer, and make sure to delete them from your public server afterward.
Kick Out Rogue Owners and Delete Verification Tokens
In this specific type of hack, the most urgent step is cutting off the attacker's ability to mess with your Google indexing queue.
Remove Unrecognized Search Console Owners
- Open up Google Search Console. 2. Go to Settings > Users and permissions. 3. Look for any unfamiliar Gmail addresses listed with "Owner" status. 4. Click the three dots next to their name and hit Remove access.
Wipe Out Rogue HTML and DNS Verification Records
Removing them in the dashboard won't stick if their verification token is still sitting on your server, they'll just re-verify themselves. Attackers usually claim ownership by dropping an HTML verification file in your web root or sneaking a TXT record into your DNS.
Check the files in your web root for anything matching the google{string}.html pattern:
ls -la /var/www/html/ | grep "google.*\.html"If you see any verification files you didn't put there, delete them right away:
rm /var/www/html/google1234567890abcdef.htmlNext, log into your domain registrar, open your DNS zone file, and remove any google-site-verification TXT records you don't recognize.
Hunt Down and Wipe Out the Malware
Once the attacker is locked out of Search Console, it's safe to start scrubbing the infected files and database entries.
Reinstall WordPress Core and Plugins via WP-CLI
Don't waste time trying to manually spot altered core files, just overwrite the entire WordPress core using WP-CLI. That'll cleanly wipe out any backdoors tucked inside native WordPress folders.
# Navigate to your WordPress root
cd /var/www/html/
# Verify WordPress checksums to see what was modified
wp core verify-checksums
# Force download and overwrite core files (does not touch wp-content or wp-config.php)
wp core download --skip-content --force
# Reinstall all active plugins to overwrite infected plugin files
wp plugin install $(wp plugin list --field=name) --forceAfter that, take a look inside /wp-content/uploads/. Nothing should be in there except media files like JPGs, PNGs, and PDFs. Run a quick search to find and delete any rogue PHP files hiding in your uploads folder:
find /var/www/html/wp-content/uploads/ -type f -name "*.php"Check Your .htaccess and Server Block Rules
Hackers love using rewrite rules to spin up dynamic spam pages on the fly or redirect search traffic.
Pop open your .htaccess file (or your Nginx server block) and scan for weird RewriteRule lines pointing to strange PHP scripts or intercepting search engine bots.
cat /var/www/html/.htaccessIf you see scrambled, obfuscated code or rules you didn't write, wipe the file and let WordPress generate a fresh, default routing setup:
rm .htaccess
wp rewrite flush --hardScrub wp_options and wp_posts Using SQL
The Japanese keyword hack typically floods your database with thousands of auto-generated posts, and it'll sometimes tamper with your site URLs or active plugins inside the options table.
Jump into your MySQL prompt to clean house:
-- Check for newly created admin users
SELECT * FROM wp_users ORDER BY user_registered DESC LIMIT 5;
-- Delete any rogue admin users (replace 999 with the actual ID)
DELETE FROM wp_users WHERE ID = 999;
DELETE FROM wp_usermeta WHERE user_id = 999;
-- Identify injected Japanese posts by searching for specific unicode ranges
SELECT ID, post_title, post_date FROM wp_posts
WHERE post_title REGEXP '[\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{4E00}-\x{9FAF}]';
-- If the query above strictly returns spam, delete them
DELETE FROM wp_posts
WHERE post_title REGEXP '[\x{3040}-\x{309F}\x{30A0}-\x{30FF}\x{4E00}-\x{9FAF}]';Delete Rogue Sitemaps and Serve 410 Gone Headers
Scan your web root for fake sitemaps (like sitemap_japan.xml or unauthorized edits to sitemap_index.xml) and delete them.
Since the attacker probably generated thousands of junk URLs (something like /news/12/super-copy), letting them return a regular 404 Not Found takes forever to clear out. Instead, serve a 410 Gone HTTP status code, that tells Google the pages are permanently dead so it drops them from search results much faster.
If all the spam URLs sit under a specific fake folder (like /products/dx7g3h/), drop this rule right at the top of your clean .htaccess file:
RewriteEngine On
# Replace 'products' with the fake directory the attacker used
RewriteRule ^products/.*$ - [G,L]If you're running Nginx, add this block to your server config instead:
location ~ ^/products/ {
return 410;
}Patch the Entry Point and Reset All Passwords
They got in through a security hole somewhere, usually an out-of-date plugin, a weak admin password, or compromised FTP credentials.
- Update every single theme and plugin to its latest version. 2. Force password resets for every remaining administrator and editor on the site. 3. Kick out any lingering logged-in sessions by scrambling the security salts in your
wp-config.phpfile via WP-CLI:
wp config shuffle-saltsAsk Google for a Security Review
Once the site is clean, the entry points are locked down, and those spam URLs are returning 410 errors, head back into Google Search Console.
Go to Security & Manual Actions > Security issues. If there's an active warning banner, click Request Review. Spell out clearly in the notes that you've removed the unauthorized owners, wiped the injected database rows, cleaned up .htaccess, and rotated all your credentials.
Quick answers
Frequently asked questions
Why do the Japanese spam pages return a normal page or 404 error when I visit them directly?
What you're running into is server-side cloaking, where the malware only shows the spam payload to search engine crawlers and people clicking through from search results. When you type the URL in directly, the script hides everything so you won't notice the breach right away, which is why you'll want to use the URL Inspection tool in Google Search Console to see the actual HTML Google is crawling.
Why does the Japanese keyword hack keep coming back after I delete the malicious files?
Repeat infections almost always happen because the attacker still has verified ownership in your Google Search Console or left a hidden backdoor sitting in your database or uploads folder. Before you start wiping files, make sure you kick out any unauthorized Search Console owners, remove their HTML or DNS verification tokens, and rotate your wp-config.php security salts.
Should I restore a pre-infection backup or clean the WordPress site manually?
Rolling back to a clean backup is definitely the faster route, as long as you have a verified snapshot from before the breach happened and you patch the vulnerable plugin or theme right after restoring. However, if your backups are already compromised or restoring one would wipe out recent database transactions, you'll need to roll up your sleeves and do a manual cleanup with WP-CLI and SQL queries.
How can I verify that WordPress core files have not been modified by the attacker?
Just head into your WordPress root directory and run wp core verify-checksums using WP-CLI to check your local files against the official WordPress.org hashes. It'll flag any altered or unexpected files right away, letting you overwrite them cleanly with wp core download --skip-content --force.
Why should I return a 410 Gone status instead of a 404 Not Found for the spam URLs?
Serving a 410 Gone HTTP status lets Googlebot know those spam pages are permanently gone and need to be pulled from the search index right away. If you leave them as a standard 404 Not Found, Google will keep coming back to recrawl the dead links for weeks, which slows down your organic search recovery.
Where do attackers hide verification tokens for Google Search Console?
Most attackers verify ownership either by dropping an HTML file starting with google followed by random characters into your web root, or by sneaking a google-site-verification TXT record into your domain's DNS zone. Sometimes they'll even inject a dynamic rewrite rule straight into your .htaccess file to fake that verification HTML file on the fly.
How long does Google take to remove the hacked Japanese pages from search results?
How fast those pages drop out of the index really comes down to your site's crawl budget and whether your server is sending 410 Gone headers for the spam directories. After you submit a review request under Security & Manual Actions in Search Console, Google usually wraps up the security review in a few days, though clearing everything out of the search results completely can still take several weeks.
Something wrong or out of date?
Tools change fast. Tell the editor what no longer works.