WP Front Door

Signs a WordPress site has been hacked

The checker reads the page as a visitor and again as Googlebot, looks for the patterns spam injections leave, and asks Google's Safe Browsing list. A match is a lead to follow, not a verdict.

Written by . Updated . One of the signs of a hack guides.

What the checker looks at

One page, from outside, logged out. It compares that page with a second copy fetched with Googlebot's user agent, reads the HTML for the patterns spam injections leave behind, and checks Google's Safe Browsing list when this server has a key for it. Without the key, the report links to Google's Transparency Report for the site instead.

  • cloaking: the Googlebot copy has 3 or more extra pharmacy, casino or loan terms, 200 or more extra Japanese characters, or links to 5 or more other sites that the visitor's copy lacks (the links count only when the visitor's copy has real text). Or Googlebot ends up on a different site whose page carries that spam; a different site without it is only noted, since big sites send crawlers to regional editions.
  • hidden-links: 3 or more links to other sites inside blocks styled display:none, visibility:hidden, a position or indent of -100px or more, a zero font size, or a zero height with hidden overflow. Links to social networks, WordPress.org and similar everyday sites are not counted, and neither are links in hidden menus, dialogs, cookie panels, tabs or carts unless they carry spam words. One hidden link with spam words is enough.
  • spam-terms: 3 or more links to other sites that use pharmacy, casino or loan words, or a pharmacy word in the page title or description.
  • japanese-spam: 200 or more Japanese kana characters on a page whose lang attribute names another language.
  • obfuscated-script: an inline script that runs eval() on decoded text, a packed eval(function(p,a,c,k,e,...)), Function() or document.write() fed decoded text, a String.fromCharCode() call with 40 or more numbers, atob() of a string over 1,000 characters, 200 or more hex escapes, or 30 or more _0x names.
  • offsite-redirect: a meta refresh or a short inline script that sends the browser to another site, a script that checks the referrer for a search engine before changing the address, or an address that ends up on a different site.
  • blocklist and listed-script: Google Safe Browsing lists the site, or a script the page loads from another site, for malware, phishing, unwanted software or harmful apps.

Why a pattern is not a verdict

Every pattern has innocent causes. A casino review site uses casino words. Mobile menus hide links. Some licence checks and ad scripts are obfuscated. A prerendering service gives crawlers a different copy on purpose. So the report says "worth a look" and shows what it saw. Only a Safe Browsing listing counts as a problem, because that is Google's own list.

It works the other way too: a clean report does not prove a site is clean. Malware can sit in files and the database without touching this page. It can show itself only to visitors who arrive from a search, only on phones, or only to Google's real addresses, which this checker cannot pretend to be.

Confirm it yourself

Fetch the page as Googlebot and as a browser, and compare the two:

Shell
curl -sL -A "Googlebot" https://example.com/ > as-googlebot.html
curl -sL -A "Mozilla/5.0" https://example.com/ > as-browser.html
diff as-browser.html as-googlebot.html | head -50

Then search Google for site:example.com and look for titles in Japanese, or about pills, casinos or loans, that you did not write. In Search Console, the Security issues report lists hacked content Google has found, and the Pages report shows URLs you never made.

Find where it comes from

Injected spam and redirects live in a few places. Start with recently changed files and PHP where it does not belong:

Shell
# PHP files changed in the last 7 days, outside the uploads folder
find /path/to/site -name '*.php' -mtime -7 -not -path '*/uploads/*'
# The uploads folder should hold no PHP at all
find /path/to/site/wp-content/uploads -name '*.php'

Then the database: posts, options and widget settings that carry <script, eval( or the domains the report named, and the siteurl and home options. With WP-CLI:

Shell
wp db search 'eval(' --all-tables
wp option get siteurl
wp option get home

Check .htaccess as well, for rewrite rules that send search engines or visitors somewhere else.

If the site is hacked

Clean the whole site, not only the page: replace core, theme and plugin files with fresh copies, remove what was added to the database, change every password and secret key, and close the way in, which is often an outdated plugin. If Google flagged the site, ask for a review in Search Console once it is clean.

Check the fix

Rerun the check and repeat the curl comparison. A few days later, search site:example.com again. Spam pages leave Google's index slowly; the Removals tool in Search Console hides the worst ones sooner.

More detail in the full guide to fixing a hacked WordPress site on hamzaahmadaslam.com.

Check a site for this

A domain or a full address. Only public pages are fetched, the way a browser would.