There's a version of getting hacked where your site looks completely fine. You log in, everything is where it should be, pages load normally, and content is unchanged. But when you Google your own organization's name, the search results show your domain selling Viagra.

That's the WordPress pharma hack. On a site nobody is watching, it can run for weeks or months before anyone notices.

The WordPress pharma hack is an SEO spam injection attack where attackers compromise a legitimate website and use cloaking to show pharmaceutical product listings to search engines while displaying normal content to human visitors. The site owner sees nothing wrong. Google sees a pharmacy.

The goal isn't to damage your site or steal your data. It's to hijack your domain's search authority to rank for drug keywords like Viagra, Cialis, and Xanax. You might hear this called a WordPress viagra hack when the injected content focuses specifically on erectile dysfunction drugs, but it's the same underlying attack.

The pharma hack is one of the oldest and most persistent types of WordPress attacks. The attackers are running a business: affiliate programs pay well, and by parasitizing hundreds of legitimate websites, they build a network of pages that rank for lucrative keywords.

The scale is real. Sucuri's SiteCheck Malware Trends Report 2024 found SEO spam on 422,741 websites, 38.4% of the 1,176,701 infected sites it detected that year. WordPress is the main target: in Sucuri's 2023 Hacked Website report, it accounted for 95.5% of detected infections.

"You don't have to be on anyone's threat list. You don't have to be a target. You don't have to be controversial. Your website can fall victim to a security attack even if you've never done anything controversial at all."

How the WordPress Pharma Hack Hides From You

The defining feature of this attack is cloaking, showing different content to search engine crawlers than to human visitors. That's what makes it so difficult to detect on your own.

When Googlebot crawls your pages, the malicious code detects the crawler's user agent and serves spam: keyword-stuffed pages, product listings, and links to illicit pharmacy or casino sites. Your page titles in search results change to things like "Buy Viagra Online, [Your Organization Name]."

When you visit the site as a logged-in administrator, the code detects that too and serves the normal, clean website. Some variants also check how visitors arrived. If someone clicks through from a Google search result, they get redirected to a spam site. If they type your URL directly, they see the real site.

This redirect behavior often co-occurs with pharma hack infections, and the two attacks share the same entry points and cleanup requirements.

The cloaking isn't a rough edge in the attack. It's a deliberate design choice. The attackers want the infection to persist quietly for as long as possible, generating revenue from your domain authority while you have no idea anything is wrong.

What This Looks Like on a Real Site

I used to say we'd never had a pharma or redirect attack on a site we host. That stopped being true this August.

A nonprofit we host had its homepage swapped for a gambling affiliate page, but only for Google. Browsers got the real site. So did SEO tools, uptime monitors, and malware scanners, because the malware carried a list of them and showed each one the clean page. The only reason anyone saw it is that the CDN had cached Google's version and served it to real visitors.

It wasn't a plugin exploit, and it didn't come through the server. A rogue administrator account was created inside one of the site's own administrators' logged-in sessions. Days later, that account was used to install file managers and the cloak. From the outside, it looked like a legitimate user doing legitimate work, which is exactly why a firewall had nothing to block.

The cloak was live for about 17 hours. We had the site clean 21 minutes after the ticket came in. Google re-crawled the clean homepage about 90 minutes later, and the site's search performance shows no measurable harm.

Our first pass also missed something: a second file manager. We found it the next day by working from the attacker's addresses in the access logs, and that's now how we check every cleanup. The site also moved onto two-factor logins, which we now add for clients who want them.

So here's what I can say honestly. None of our servers has been breached, and no infection has come in through them. The one cloaked spam case on a site we host came in through an administrator's own session. What I can't say anymore is that it can't happen to a site we host. Nobody honest can.

Pharma, Japanese, Casino: One SEO Spam Attack

Gambling spam, like the case above, is today's common version of the same attack. Pharma was the classic. The mechanics haven't changed. Only the keywords have.

The pharma hack also has a closely related variant that has surpassed it in volume: the WordPress Japanese keyword hack. Same cloaking, same entry points, same cleanup requirements. But instead of drug keywords, it injects Japanese-language text promoting counterfeit luxury goods, electronics, or gambling sites.

The Japanese keyword hack tends to be more aggressive in one specific way: it creates hundreds or thousands of new pages rather than modifying existing ones. These doorway pages exist solely for search engine indexing. Site owners often discover the infection when Google Search Console shows a sudden spike in indexed pages, or when they see Japanese characters in their search results.

A line graph with a steep upward spike in indexed pages

Sucuri's 2024 SiteCheck report counted 117,393 Japanese SEO spam detections, 79,817 gambling spam detections, and hidden spam content on 114,318 sites. A year earlier, its 2023 report found Japanese SEO spam on 10.07% of infected sites, about double the 5.04% carrying pharma doorway pages. My guess is that Japanese spam's page-generation approach simply produces more indexable content per infected site.

The important thing to understand is that these aren't separate problems. The WordPress pharma hack, Japanese keyword hack, casino spam, and generic SEO spam injection are all variants of the same attack pattern. The entry points, cloaking techniques, and cleanup process are the same. The only difference is which keywords the attacker is trying to rank for.

How Attackers Get In

The pharma hack isn't a single exploit. It's an outcome that follows from any successful compromise of your WordPress installation. Understanding how attackers get in matters because it determines what you need to fix after cleanup. Remove the malware but leave the entry point open, and the attackers walk right back in. On one site we were called in to help with (not one we host), the owner deleted the rogue admin accounts himself, and a new one appeared 45 minutes later.

Outdated Plugins

This is the most common entry point. According to Patchstack's State of WordPress Security in 2026 (Patchstack sells WordPress security, so read it as vendor research), 11,334 new vulnerabilities were reported in the WordPress ecosystem in 2025, up 42% on the year before. 91% were in plugins, 9% in themes, and only 6 in WordPress core, all of them low priority. Core isn't immune, though: this July a critical core flaw let attackers take over unpatched sites without logging in, which is why core updates matter as much as plugin updates. We cover the full landscape in our guide to how WordPress sites get hacked.

Attackers run automated scanners to find WordPress sites with vulnerable plugin versions, match known exploits against those versions, and deploy payloads. No human involvement required. Patchstack found that about half of high-impact vulnerabilities were exploited within 24 hours. A bot found your outdated contact form plugin, and now Google thinks you sell Cialis. Compromised WordPress plugins make this even worse: when a trusted plugin is weaponized at the source, the malware arrives through your normal update channel.

Compromised Credentials and Sessions

Weak or reused passwords remain a reliable way in. Brute-force attacks, credential stuffing from data breaches, and shared credentials all give attackers the access they need to install spam infrastructure. Often, attackers first use user enumeration to discover valid usernames before launching credential attacks. And as our own case shows, an attacker doesn't always need the password at all if they can ride an administrator's logged-in session.

Nulled Plugins and Themes

Pirated ("nulled") premium plugins and themes are one of the most reliable infection vectors. Attackers crack premium plugin licenses and distribute them on "free download" sites, often pre-loaded with backdoors. Site owners install malware voluntarily, thinking they got a deal on a $50 plugin.

Server-Level Vulnerabilities

On shared hosting environments, one infected account can provide lateral access to other sites on the same server. This is a risk factor entirely outside the site owner's control, and it's one of the reasons hosting quality matters for security.

How to Check If Your Site Is Affected

Because the WordPress pharma hack is designed to be invisible when you browse your own site, detection means deliberately looking at it the way Google does. It's also worth understanding what a security plugin can and can't find before you trust one to tell you you're clean.

Detection Methods Overview

Method What It Finds Limitations
Google site: search Indexed spam pages and titles Only shows what Google has already found
URL Inspection, live test The exact HTML Google gets from your page right now Requires Search Console access; one URL at a time
Search Console reports Security issues, spam queries, indexed spam URLs Requires verified ownership
Remote scan (Sucuri SiteCheck) Known malware signatures, blocklist status Cannot scan server files; cloaks can hide from it

Search Your Own Domain

The simplest check is a Google search using the site: operator:

  • site:yourdomain.com viagra
  • site:yourdomain.com cialis
  • site:yourdomain.com casino

If results appear, your site has been compromised. You can also search site:yourdomain.com and scroll through the results looking for altered titles or descriptions. Check your subdomains too: spam on shop. or old. counts against the same domain. Many site owners first discover the hack when a customer or colleague sends them a screenshot of the search results.

See What Google Sees

To see a page the way Google sees it, open Google Search Console, paste the URL into URL Inspection, click Test Live URL, then View Tested Page. If the HTML there has drug names or casino links you don't see in your browser, you're looking at the cloak. Google retired the old cache: trick in 2024, so this is now the reliable way.

Then test it like a visitor arriving from Google. Log out, open a private window, or better, use a phone on mobile data, search for your organization, and click through from the result. Referrer-based cloaking only shows itself to people who arrive that way.

Check Google Search Console

If your site is connected to Google Search Console, look at several areas:

  • Security Issues report: Google may list "Hacked: Content injection," "Hacked: Code injection," or "Hacked: URL injection" (see Google's Security Issues help page). A clean report doesn't mean a clean site. Google doesn't flag every infection.
  • Search Performance report: Filter by query and look for impressions on drug or gambling keywords you never targeted.
  • Indexing reports: Check for sudden increases in indexed page count, especially pages you didn't create. This is a telltale sign of the Japanese keyword hack variant.
  • Users and Permissions: The Japanese keyword hack sometimes makes the attacker a verified owner of your Search Console property, using an HTML verification file or an .htaccess rule that fakes one (Google's guide to the Japanese keyword hack covers this). Remove any owner you don't recognize, then delete the file or rule, or they'll simply verify again.

Run a Remote Scan

Sucuri's free SiteCheck tool can detect spam in your site's HTML output. It checks for known malware signatures, blocklist status, and SEO spam. (Sucuri's free tools and its paid service are different things.) Keep in mind that remote scanners only check what's visible in the page output. They can't detect file-level infections or database-stored payloads. And a good cloak recognizes scanners and shows them the clean site, which is exactly what the malware in our case did. A clean remote scan doesn't guarantee a clean site.

Why the WordPress Pharma Hack Is Hard to Clean

The WordPress pharma hack uses a split architecture that makes cleanup significantly harder than most malware. The infection lives in several places at once: modified files on the server and injected content in the database. Remove the files without cleaning the database, or vice versa, and the infection rebuilds itself from the pieces you missed.

File-Level Infections

Attackers modify core WordPress files like index.php, wp-config.php, and wp-blog-header.php by appending include statements that load malicious code. They also plant new files designed to look legitimate: names like wp-page.php, cache.php, or class-wp-config.php that blend in with real WordPress files.

Other favorite hiding spots: PHP files in the uploads directory, must-use plugins in wp-content/mu-plugins (they load on every request and don't appear in the normal plugin list), a .user.ini file that quietly loads malware before WordPress starts, backdoors using eval() and base64_decode(), and .htaccess rules that serve different content based on user agent. The site in our case had three separate delivery mechanisms, including a .user.ini file, a patched wp-blog-header.php, and a must-use plugin, plus five webshells.

Database Infections

Malicious code gets stored in the wp_options table as serialized data that executes on every page load. In some cases, attackers use SQL injection through vulnerable plugins to write directly to these tables without needing file access. Spam content is injected into existing posts and hidden with CSS, such as display: none or off-screen positioning. New posts and pages may be created with spam content set to publish. Attackers also add their own administrator accounts: Sucuri's 2023 report found malicious admin users in 55.2% of the infected databases it cleaned.

The obfuscation is deliberate: encoded multiple times, split across tables, assembled at runtime from character codes.

The Reinfection Cycle

This is the core frustration with pharma hack recovery, and the problem that one-time cleanups often fail to solve. The cycle looks like this:

  1. Site owner discovers the hack
  2. Someone runs a scanner or does a manual cleanup
  3. The site appears clean
  4. The malware comes back

This happens because the cleanup missed a backdoor, an obfuscated file, a database entry, or a rogue account. Or the original vulnerability that let attackers in was never closed. Sucuri's 2023 report found at least one backdoor on 49.21% of the compromised sites it cleaned. A single missed backdoor, sometimes just one line of PHP hidden in a file you'd never think to check, is enough for the entire infection to regenerate.

"Infections are self-replicating. They compromise both files and the database. To think you're going to clean it up manually is a gamble."

This is why I don't recommend DIY remediation. The attack surface within a compromised site is too large for file-by-file eyeballing, and even professionals miss things on a first pass, as we did. When a site we manage is hit, we clean it ourselves, in house, and we verify the result against the access logs rather than trusting a single scan.

"Don't trust yourself to do an eyeball scan. You'll miss pieces hidden in the database or buried in files."

Layers of tangled code on a computer screen

What Professional Cleanup Involves

A thorough pharma hack cleanup is a multi-step process. Understanding what's involved helps you evaluate whether a cleanup is actually thorough or just scratching the surface.

Full backup before any changes. Before touching anything, take a complete backup of the infected site, both files and database. Even though the site is compromised, you need it as evidence and a reference point.

Work from the logs. The access logs show which addresses logged in, which files they requested, and what they uploaded. Start there, then check the disk. That's how we found the second file manager in our case.

Core file replacement. All files in /wp-admin/ and /wp-includes/ are replaced with clean copies from the official WordPress repository. Root-level core files are replaced. wp-config.php is manually inspected since it contains your site's configuration and can't simply be overwritten.

Plugin and theme reinstallation. All plugins are deleted and reinstalled from their sources. You can't trust existing plugin files on a compromised site. Inactive themes are removed entirely.

Check the hiding spots. Must-use plugins, .user.ini files, PHP files in uploads, cron jobs and scheduled events.

Database cleaning. The wp_options, wp_posts, and wp_postmeta tables are searched for encoded payloads, spam terms, hidden content, and unauthorized data. The wp_users table is checked for fake admin accounts created by the attacker.

.htaccess restoration. The existing file is deleted and regenerated. Subdirectories are checked for additional .htaccess files that shouldn't exist.

Credential and session reset. All passwords are changed: WordPress admin accounts, database users, FTP/SFTP, and hosting control panel. WordPress security salts are regenerated, which logs everyone out and invalidates any stolen session cookies.

Update everything. WordPress core, all plugins, and all themes are updated to their latest versions. Anything not actively in use is removed. This step closes the vulnerability that allowed the compromise in the first place.

Purge every cache. Clear the site cache and the CDN. In our case the CDN had cached Google's spam version of the homepage, and it would have kept serving that page until the cache was purged.

If you'd rather not do this yourself, our hacked site cleanup and ongoing protection covers both the cleanup and keeping the entry points closed afterward.

Recovering Your Search Results

Cleaning the infection from your site is only half the battle. You also need Google to see the site is clean and drop the spam from your search results.

If Google has listed a problem in Search Console's Security Issues report, fix everything first, then click Request Review. Explain what happened, what you did to fix it, and what you've done to prevent it from happening again. Google says reviews can take from a few days to a few weeks.

If Google never flagged your site, there's nothing to request. Clean the site, then use URL Inspection to request indexing of your main pages and resubmit your sitemap.

For Japanese keyword hack infections that created hundreds of doorway pages, the lasting fix is making sure every spam URL returns a 404 or 410 once the site is clean, so Google drops them when it recrawls. The Removals tool in Search Console can hide URLs from results faster, but only temporarily, for about six months.

One important caution: don't request a review until you're confident the cleanup is complete. Google warns that a request submitted before the problem is fixed can slow down the next review, and repeated failures can get a site treated as a repeat offender. An incomplete cleanup that leaves a backdoor means the infection returns, and you'll be in a worse position with Google than before.

How long recovery takes depends mostly on how long the spam was live and whether your site was blocklisted. In our case, a cloak caught within a day left no visible mark. Infections that run for months take longer. Sucuri says blocklisted sites can lose nearly 95% of their organic traffic while the warning is up, which is the strongest argument for catching this early.

How We Keep It From Happening

The entry points for the WordPress pharma hack are well understood: outdated plugins, weak credentials, and server-level gaps. Closing them isn't complicated, but it does require consistent, ongoing attention. Here's what we actually run across the 200+ sites we host.

Weekly updates, tested on a copy first. Every week we run plugin, theme, and core updates on a copy of each site, compare it visually with the live site, and only then update the live site. In the last three months that's more than 4,600 updates across 138 sites. When an update changed how a page looked, it waited for a person to review it instead of going live, 30 times. That closes most of the outdated-software door pharma hacks walk through. More on how this works in our WordPress maintenance service.

Server-level malware scanning. Imunify360 runs on every one of our servers, outside of WordPress. On the night we last checked, its overnight scan covered every site we host and found zero infected files. Server-level scanning matters because a compromised WordPress plugin can disable WordPress-level security tools; the application can't turn off something running outside it. We explain the difference in security plugins vs. server-level protection.

A firewall in front of every site. Every production site we host sits behind Cloudflare's Enterprise firewall, which stops known exploit patterns before they reach WordPress. In one three-day stretch this November it blocked more than 330,000 requests aimed at our sites. A firewall can't see everything, though. It can't tell an attacker from a real user who is already logged in, which is why it's one layer and not the plan.

Concentric protective barriers around a web server

Hiding usernames. Every site we host runs our own must-use plugin that blocks the lookups attackers use to find valid usernames. We add two-factor authentication and a login challenge on request.

Here's the fundamental difference between our approach and what most pharma hack articles recommend. The standard advice is a checklist: update your plugins, use strong passwords, install a security plugin. That's accurate as far as it goes.

But a checklist only works if someone consistently works through it, week after week. The sites that get hit with pharma hacks usually aren't sites where the owner decided to skip security. They're sites where the checklist wasn't completed that month, quarter, or year. And no checklist makes a site immune, which is why fast, thorough cleanup is part of the job, not an afterthought.

"It's not a wait-and-see game where you clean up afterwards. It's a multi-layer approach to keeping it from happening in the first place."

What to Do If Your Site Has Been Compromised

If you've discovered drug or casino spam in your search results, here's the short version of what to do next:

  1. Confirm the infection with the site: search, URL Inspection's live test, and the Search Console checks described above.
  2. Don't attempt a partial cleanup. A surface-level scan that misses a single backdoor means the infection comes back.
  3. Get a thorough cleanup that covers files, the database, rogue accounts, and every hiding spot, verified against the access logs.
  4. Close the entry point. Update all plugins, themes, and WordPress core. Change all passwords and log everyone out. Remove anything you're not actively using. A professional security audit can find the gaps you don't know about.
  5. Purge your caches and CDN, then request a review from Google only if it flagged the site, and only after the cleanup is complete.
  6. Put ongoing maintenance in place so the entry points stay closed.

Before any of that starts, the first hour decides how much harder the cleanup gets: our guide to WordPress malware removal covers what to copy, what to switch off and what not to delete.

If you're looking for ongoing security management or need help recovering from an active infection, our WordPress security services page explains what's included. For a broader view of how attacks like the WordPress pharma hack fit into the bigger picture, see our guide to WordPress security threats.

FAQ

How do I know if my WordPress site has a pharma hack?

The tricky part is that you won't see it by browsing your own site. The malware is designed to hide from logged-in users. The quickest check is to search Google for site:yourdomain.com viagra, site:yourdomain.com cialis, or site:yourdomain.com casino. If results come up, you have a problem. You can also look at Google Search Console for security issues, unexpected impressions on drug or gambling keywords, or a sudden spike in indexed pages you didn't create.

How do I see what Google sees on my site?

Use URL Inspection in Google Search Console. Paste in the page URL, click Test Live URL, then View Tested Page and look at the HTML. If it contains spam you don't see in your browser, the page is cloaked. The old cache: search operator no longer works; Google retired it in 2024.

Can a security plugin or scanner find a pharma hack?

Sometimes. Scanners catch known malware signatures, but a good cloak recognizes them and shows them the clean site. The infection on the site we host showed clean pages to SEO tools, uptime monitors, and scanners, and spam only to Google. That's why the site: search and URL Inspection matter more than a clean scan result.

Can I clean a pharma hack myself?

You can try, but the odds aren't great. Pharma hacks split the infection between your files and your database, and they plant multiple backdoors and rogue accounts so the infection can rebuild itself from pieces you missed. Even our own first pass on a real case missed a file manager, which we caught the next day by working from the access logs. A thorough cleanup starts from the logs, replaces core and plugins from clean sources, and checks every hiding spot.

Will Google remove the spam results after I clean the site?

Yes, once it recrawls the pages. Make sure every spam URL returns a 404 or 410 after cleanup, then use URL Inspection to request indexing of your main pages. The Removals tool in Search Console hides URLs faster, but only temporarily, for about six months, so it doesn't replace the 404s.

Do I need to file a review request if Google never flagged my site?

No. A review request is only for problems listed in Search Console's Security Issues report. If nothing is listed there, clean the site, purge your caches, and ask Google to recrawl your main pages.

How long does it take to recover search rankings after a pharma hack?

It depends on how long the spam was live and whether Google flagged the site. If Google listed a security issue, fix everything, then request a review; Google says that takes a few days to a few weeks. On one site we host, a cloak caught within a day left no measurable mark on search results, and Google had the clean page about 90 minutes after cleanup. Infections that run for months take longer, and some lost backlinks may never come back.

Why does the pharma hack target small sites?

Because the attackers don't care about your content. They care about your domain authority. Even a small site that has been around for a few years has built up enough trust with Google to help rank spam keywords. The bots that deploy these attacks are automated and scan the internet looking for any WordPress site with a known vulnerability. Your site's size, audience, or topic are irrelevant to them.

What's the difference between a pharma hack, a Japanese keyword hack, and casino spam?

They're variants of the same attack. The pharma hack injects drug spam into your existing pages. The Japanese keyword hack creates hundreds or thousands of new pages in Japanese promoting counterfeit goods or gambling sites. Casino and gambling spam is the common flavor today. The entry points, cloaking techniques, and cleanup process are the same for all of them. The only real difference is which keywords the attacker is trying to rank for.