Hacked websites often become targets for SEO spam attacks, where thousands of spam pages get indexed by Google, damaging search rankings and credibility. Recently, we faced a case where a WordPress site had been compromised, leading to 242,000 Japanese spam pages appearing in Google Search results.

In this guide, we will walk through:

Step 1: Cleaning Up the Malware

1.1 Scan for Malware

Use security plugins like Wordfence and Sucuri to scan and detect malicious files.

Perform a manual review of key files like index.php, .htaccess, and wp-config.php to check for suspicious modifications.

1.2 Check for Unauthorized Admin Users

Go to WordPress Dashboard → Users and remove any unfamiliar admin accounts. Change all admin passwords immediately.

1.3 Update Everything

Update WordPress Core, Plugins, and Themes to their latest versions. Remove unused and outdated plugins/themes that might have security vulnerabilities.

1.4 Restore Critical Files

Check .htaccess and wp-config.php for any unauthorized modifications and restore them to their default settings.

Step 2: Extracting Indexed Spam URLs

2.1 Using URL Extractor

Search site:yourdomain.com on Google to see indexed pages.

Use Infy Scroll to auto-load all pages and extract all URLs using URL Extractor.

Then Use the following Python script to filter spam URLs:

import pandas as pd
csv_file = "urls.csv"
df = pd.read_csv(csv_file)
site_url = "https://domain.com"
filtered_urls = df[df['URL'].str.startswith(site_url)]
filtered_urls.to_csv("filtered_urls.csv", index=False)
print("Filtered URLs saved successfully!")

2.2 Google Search Analytics API

For a larger dataset, use the Google Search Analytics API to extract up to 25,000 URLs:

Step 2.2.1: Open the Search Analytics API

Step 2.2.2: Expand to Full-Screen Mode

Step 3: Set Up Your Request

Paste this JSON into the “Request Body” field:

{
  "startDate": "2023-01-01",
  "endDate": "2025-02-19",
  "dimensions": ["QUERY", "PAGE"],
  "rowLimit": 25000
}

Step 4: Authorize & Execute the Request

Step 5: Copy & Convert JSON Data to CSV


2.3 Google Search Console

Navigate to Indexing > Pages > View data about indexed pages in Google Search Console and export all indexed pages manually.

Step 3: Removing the URLs from Google

3.1 Submitting a Clean Sitemap

Create a new sitemap.xml containing only valid URLs and submit it in Google Search Console under Sitemaps.

3.2 Bulk URL Removal

Use Google Console Bulk URL Remover to submit all spam URLs at once.

3.3 Waiting for Google to Remove 404 Pages

Since the spam pages now return 404 errors, Google will deindex them automatically.

Step 4: Securing the Site from Future Attacks

Final Results: Mission Accomplished!

Key Takeaways

Need Help?

If you need professional assistance with WordPress security, SEO cleanups, or large-scale URL removals, feel free to contact 3Zero Digital. We specialize in restoring hacked websites and securing them for the future!

Leave a Reply

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