Detecting SEO Spam & Malicious Script Injections in Custom Websites Before Google Penalizes Your Domain

Imagine searching for your own business and finding your website ranking for casino games, cheap medicines or payday loans — pages you never wrote. Or a customer calls to say your site redirected their phone to a gambling page, while on your laptop everything looks normal. That is SEO spam and script injection: content put on your site without your permission, to borrow your domain's reputation in Google and send your visitors somewhere else.
Google defines hacked content as any content placed on your site without your permission because of a security vulnerability. A site with hacked content can be demoted in results, labelled with a warning, or shown a browser interstitial before visitors can even reach it. A manual action can remove some or all of your pages from results. The damage is not the hack itself; it is the weeks of lost traffic and trust while you clean up.
Start with the two reports that tell you the truth
Before you touch a single file, open Google Search Console and look at the two reports under "Security & Manual Actions". The Manual Actions report shows problems found by human reviewers: user-generated spam, unnatural links, thin content, cloaking and sneaky redirects. If there is a manual action, the report names the type and the affected pages — fix them first, then choose Request Review. The Security Issues report flags hacked content, malware and pages that trick visitors.
Next, search Google for your own site — site:yourdomain.com — and look at the titles. Pages you did not create are a warning sign, and foreign-language titles are the classic signature of a Japanese-keyword hack, where attackers inject thousands of spam URLs. Try the same search with words you would never publish: site:yourdomain.com casino, then pharmacy, then loan. If results appear for pages you never wrote, the site is already serving spam to Google — often through cloaking, where Googlebot sees the spam pages while a logged-in human sees the normal homepage.
The detection checklist
Work through these checks in order — the first three take ten minutes and catch most infections.
- Search Console: check Security Issues and Manual Actions, and note the sample URLs Google lists.
- Site search: run
site:yourdomain.complus casino, pharmacy and loan variants. - Cloaking check: compare the URL Inspection view with what your browser shows — different content means cloaking.
- New pages: check the Pages report for indexed URLs you do not recognise.
- Traffic: look for visits from countries you do not serve, or impressions for unrelated queries.
- Mobile redirects: open the site on a phone on mobile data — many injections redirect only mobile visitors.
- Page source: view source on the homepage and search for
display:noneand unknown domains. - Files: list files modified in the last 30 days and look for anything you did not change.
- Database: search content tables for
<script,iframeandeval(. - Outbound links: crawl your own site and list every external link — a gambling or pharma link is not a coincidence.

Where injections hide
Attackers hide their code where nobody looks. The table lists the hiding spots we check first — the injection is usually small, a few lines placed where a normal update would not disturb it.
| Hiding spot | What it looks like | Why it works |
|---|---|---|
| Theme or template files | Extra script tag in a header include | Loads on every page |
| .htaccess / server config | Rewrite rules sending Googlebot elsewhere | Runs before the site code; invisible in the CMS |
| Database content tables | Script tags inside posts | Survives file restores |
| Hidden pages and sitemaps | Thousands of generated pages and a spam sitemap | Feeds Google the spam directly |
| Third-party widgets | A compromised chat, analytics or ad script | You trusted the provider |
| Comment and form spam | Links stuffed into comments | Uses your own features against you |
If you have server access, search the site's files for the words attackers use most:
grep -r "eval(\|base64_decode" /var/www/html --include="*.php" -i
grep -r "casino\|viagra\|payday" /var/www/html --include="*.php" -i
find /var/www/html -type f -mtime -30 -name "*.php" | sort
Those three commands look for obfuscated code, decoded payloads, spam keywords and recently modified PHP files. None proves an infection on its own — eval( appears in legitimate code too — but a match in a file you did not write, or a file modified on a date nobody deployed, is evidence worth following. Also check the server's access logs around the first suspicious modification. The entry point is usually an unpatched plugin, an old theme, or a file-upload form that accepted more than images.
Monitoring habits that catch the next one early
Detection is not a one-time audit; it is a habit. The September 2026 spam update — rolled out from 24 September, taking up to two weeks — was a reminder that Google keeps raising the cost of spam on your domain, including spam that visitors or attackers put there. Keep Search Console email alerts switched on, so a security issue reaches your inbox the day Google finds it. Run the site: search once a week; it takes two minutes. Watch the indexed-page count — a jump of hundreds of pages overnight is not growth, it is an injection. And if your site has comments, forums or user profiles, moderate them or close them: Google holds you responsible for what visitors post.
For custom-built sites like the ones we build — plain HTML, CSS and JavaScript, with no plugin ecosystem to keep patched — the attack surface is smaller, but the habits still matter: the server, the forms and any third-party script can still be the way in. If your site runs on a CMS, keep everything updated and remove unused plugins — an unused plugin is a door nobody is watching.
Cleanup: in the right order, or not at all
Cleaning up in the wrong order is the most common mistake after a hack, because it feels like progress while the infection quietly returns. The order that works is: first, back up the infected site as evidence, then close the hole — update everything, change every password, and remove the flaw that let the attacker in. Only then remove the injected content: the files, the database rows, the hidden pages and the spam sitemap.
After the content is gone, check that Google can see the clean version: use the URL Inspection tool on a few former spam URLs and a few important real URLs, and confirm the spam returns a 404 or a 410. Do not disavow backlinks as a first move — most of this damage is on-site spam and cloaking, not a mystery backlink profile. Then use Request Review in the matching Search Console report and explain what went wrong, what you changed and the result. Google says reviews can take several days or weeks. If Google still sees spam URLs after a review, the infection is probably not gone; fix the site again before another request. A spam update, by contrast, is automated and has no review to request.
When to ask a developer
Some of this you can do yourself: the Search Console checks, the site: searches, the weekly habits. Call a developer when the infection is confirmed and you cannot find the entry point, when the same spam returns after you cleaned it, or when the database is involved. A developer will trace the access logs to the entry point and remove the backdoor rather than only the visible spam.
What to do next
Run the ten-minute version today: open the Security Issues and Manual Actions reports, and search site:yourdomain.com with the casino, pharmacy and loan variants. If all three come back clean, set the weekly habit. If anything appears, screenshot it and get help — the evidence matters for the review. We handle this under website security and malware removal and website bug fix and repair, and our SEO services (fixed quote after audit) cover ranking recovery. Get an instant estimate or send us the suspicious URL on WhatsApp.