You log in to your WordPress and find an administrator account you never created. Your homepage now carries casino links, betting terms, foreign-language text, and strange characters. Then you move the site to a clean server, import the old database, and watch the spam return.
That happened to our site. The WordPress hacked issue did not stop at one fake user or one damaged page. The attacker had placed SEO spam inside the database, including the homepage and hundreds of saved revisions.
This article shows the exact recovery path we followed: lock down access first, preserve evidence, locate the infected records in MariaDB, restore clean content, and reduce the risk of reinfection.
First-Hour Dos and Don’ts
| Do | Don’t |
|---|---|
| Record suspicious access Capture usernames, application-password details, timestamps, IP information, spam domains, and affected URLs. | Do not delete evidence first Removing records before documenting them can erase clues about the attack. |
| Revoke unauthorized access Disable unknown administrators, application passwords, sessions, and integrations after recording them. | Do not click spam links Do not open links from comments, injected content, or suspicious messages. |
| Create a full backup Preserve the server, files, database, and affected records before cleanup. | Do not run SQL blindly Confirm the database, table prefix, page ID, and revision ID before any update. |
Our WordPress Hack
Our blog displayed casino links, betting keywords, Plinko terms, gambling brands, foreign-language promotional text, and strange Unicode characters.
\u0259
\u00e7
\u015f
We also found an unauthorized administrator and spam across the homepage and many saved revisions.
We created a new AWS Lightsail instance and moved the website. The site looked clean until we imported the old WordPress database.
The spam came straight back.
That result showed us that the infection did not live only in the old server files. The database still carried the malicious content.
Lock the Hacker Out
When you find a WordPress hacked site, secure access before you remove visible spam. Deleting casino links will not help when the attacker can still use an administrator account, application password, active session, plugin, or server backdoor.
1. Check Every Admin
Open Users → All Users and review every account with the Administrator role.
- Look for usernames and email addresses you do not recognize.
- Check for recently created administrators.
- Look for unexpected role changes.
- Record usernames, emails, roles, and timestamps.
- Review
wp_usersandwp_usermetawhen needed.
After you record the evidence, revoke access and remove the account once you confirm that no legitimate service depends on it.
2. Revoke Unknown Access
Open each administrator profile and review Application Passwords.
- Check the credential name.
- Match it to an approved tool.
- Review creation and last-used details.
- Check the last-used IP address when available.
- Revoke anything your team cannot identify or authorize.
3. Do Not Click Spam
Do not click links inside spam comments, injected pages, strange messages, or unknown administrator notes. Save the URL as plain text or capture a screenshot. A malicious link may open phishing, malware, tracking, redirect, or fake-login pages.
4. Reset Every Password
- WordPress administrator passwords
- AWS or hosting passwords
- Database passwords
- SSH and SFTP credentials
- Email and SMTP credentials
- CDN credentials
- API keys
- Plugin and integration credentials
Use a unique password for every account. Rotate credentials again after cleanup.
5. Turn On 2FA
Enable two-factor authentication for WordPress administrators, hosting, AWS, email, CDN, registrar, and password-manager accounts.
We also recommend reviewing these website security warning signs so you can spot weak authentication, strange redirects, malware alerts, and outdated software earlier.
6. End Active Sessions
Refresh the WordPress authentication keys and salts in wp-config.php to force logins again. Terminate unknown SSH sessions, hosting sessions, API connections, plugin integrations, and devices.
Save the Evidence
- Record when you first noticed the attack and include your timezone.
- Capture screenshots of affected pages.
- Save unknown users, roles, and application-password details.
- Record spam keywords, domains, redirects, and foreign-language phrases.
- Note recent plugin, theme, server, and account changes.
- Record Search Console or hosting warnings.
- Document every recovery action.
WordPress also recommends documenting a compromise before cleanup in its official hacked-site recovery guidance.
Back Up Before Cleanup
Run the backup command from the server terminal, not from the WordPress editor, browser, or MariaDB prompt.
Connect to the Server
If you use AWS Lightsail, open your instance and choose Connect using SSH. Other hosts may provide a browser terminal, SSH credentials, or a hosting console.
Open your WordPress wp-config.php file and locate:
define('DB_NAME', 'your_database_name');
define('DB_USER', 'your_database_user');
define('DB_PASSWORD', 'your_database_password');
$table_prefix = 'wp_';
Write down the values for DB_NAME, DB_USER, and the table prefix. Keep the database password private.
Create the Database Export
mysqldump -u DATABASE_USER -p DATABASE_NAME > wordpress-backup.sql
Replace:
DATABASE_USERwith the value fromDB_USERDATABASE_NAMEwith the value fromDB_NAME
MariaDB will ask for the database password. Enter the value from DB_PASSWORD. The terminal may not show characters while you type. That is normal.
Confirm the Backup Worked
ls -lh wordpress-backup.sql
The output should show the file name and a size greater than zero.
- The backup file exists
- The file size is greater than zero
- You saved a server snapshot or file backup
- You confirmed the correct database name and table prefix
- The command returns an access error
- The backup file is empty
- You cannot confirm the database details
- You are working on the wrong server or environment
We created:
- An AWS Lightsail snapshot
- A full copy of the website files
- A complete MariaDB export
- A copy of the affected page record
- Screenshots of suspicious accounts
- A list of spam keywords and domains
Why the Hack Returned
Moving the website to a clean server removed the old server environment, but it did not clean the imported data. When we imported the old database, WordPress brought back the infected homepage and revisions.
How SEO Spam Works
SEO spam happens when an attacker injects unauthorized keywords, links, pages, or redirects into a trusted website.
- Spam-link injection
- Casino spam
- Search spam
- Japanese keyword spam
- Pharmaceutical spam
- Search-engine poisoning
Why Attackers Add Spam
- Place gambling links on a trusted domain
- Use the website’s authority
- Improve another site’s rankings
- Create spam pages for search engines
- Hide links inside legitimate content
- Redirect visitors
- Generate affiliate revenue
- Damage rankings and reputation
How They May Get In
- Outdated plugins
- Vulnerable themes
- Stolen administrator passwords
- Malicious or nulled plugins
- Compromised SSH credentials
- Infected backups
- Weak hosting passwords
- Unpatched WordPress
- Unauthorized application passwords
- Compromised integrations
- Exposed database credentials
These possibilities do not prove the original entry point. Use logs and evidence before you assign blame.
Find Spam in MariaDB
Before You Search
Collect exact indicators from the hacked page first:
- Casino or betting terms
- Unknown domains
- Foreign-language phrases
- Redirect URLs
- Spam brand names
- Suspicious HTML or script fragments
Start with one or two specific indicators. Very broad words may return legitimate content.
Step 1: Open MariaDB
sudo mariadb
When MariaDB opens successfully, the prompt usually changes to something similar to:
MariaDB [(none)]>
Step 2: Select the Database
Use the database name from DB_NAME in wp-config.php.
USE DATABASE_NAME;
Replace DATABASE_NAME with the real database name. MariaDB should respond with:
Database changed
DB_NAME.
Step 3: Confirm WordPress Tables
SHOW TABLES;
Confirm that the list contains tables ending in:
_posts_postmeta_options_users_usermeta_comments
In wp-config.php, confirm the line:
$table_prefix = 'wp_';
Your prefix may look different, such as abc_. Replace every wp_ in the examples with your actual prefix.
Step 4: Search for Spam
SELECT ID, post_title, post_type, post_status
FROM wp_posts
WHERE post_content LIKE '%spam-keyword%'
OR post_content LIKE '%casino%'
OR post_content LIKE '%plinko%';
Replace the example terms with indicators from your site. For example:
WHERE post_content LIKE '%unknown-domain.com%'
OR post_content LIKE '%betting-brand%'
OR post_content LIKE '%casino%';
| Column | What It Means |
|---|---|
| ID | The database record number |
| post_title | The WordPress page or post title |
| post_type | Page, post, revision, attachment, or cache record |
| post_status | Published, draft, trash, or inherited revision |
Step 5: Sort the Results
SELECT post_type, post_status, COUNT(*) AS total
FROM wp_posts
WHERE post_content LIKE '%spam-keyword%'
OR post_content LIKE '%casino%'
OR post_content LIKE '%plinko%'
GROUP BY post_type, post_status;
You may see:
page publish
post trash
revision inherit
oembed_cache
A large number of infected revisions may mean WordPress repeatedly saved the compromised page.
Step 6: Identify the Homepage
In WordPress, open Settings → Reading and check the page selected under Your homepage displays.
You can also check the homepage ID in MariaDB:
SELECT option_name, option_value
FROM wp_options
WHERE option_name IN ('show_on_front', 'page_on_front');
If show_on_front equals page, the value in page_on_front is the homepage page ID.
Step 7: Find the Live Page
SELECT ID, post_title, post_name
FROM wp_posts
WHERE post_type = 'page'
AND post_status = 'publish'
AND (
post_content LIKE '%spam-keyword%'
OR post_content LIKE '%casino%'
OR post_content LIKE '%plinko%'
);
Match the returned title or ID with the homepage or affected page, then record it as:
POST_ID
Step 8: Inspect Revisions
SELECT ID, post_date, post_title
FROM wp_posts
WHERE post_type = 'revision'
AND post_parent = POST_ID
ORDER BY post_date DESC
LIMIT 20;
Then label revisions using the known spam terms:
SELECT ID, post_date,
CASE
WHEN post_content LIKE '%spam-keyword%'
OR post_content LIKE '%casino%'
OR post_content LIKE '%plinko%'
THEN 'INFECTED'
ELSE 'NO KNOWN SPAM FOUND'
END AS revision_status
FROM wp_posts
WHERE post_type = 'revision'
AND post_parent = POST_ID
ORDER BY post_date DESC;
Step 9: Inspect a Candidate Revision
SELECT ID, post_date
FROM wp_posts
WHERE post_type = 'revision'
AND post_parent = POST_ID
AND post_content NOT LIKE '%spam-keyword%'
AND post_content NOT LIKE '%casino%'
AND post_content NOT LIKE '%plinko%'
ORDER BY post_date DESC
LIMIT 5;
Record the newest candidate as:
REVISION_ID
Inspect the first 1,000 characters:
SELECT LEFT(post_content, 1000)
FROM wp_posts
WHERE ID = REVISION_ID;
For a full inspection:
SELECT post_content
FROM wp_posts
WHERE ID = REVISION_ID;
Compare the revision with a clean backup, archive, original document, staging copy, or version-control record.
Step 10: Back Up the Page Record
CREATE TABLE wp_posts_backup_page AS
SELECT *
FROM wp_posts
WHERE ID = POST_ID;
Confirm the backup:
SELECT ID, post_title
FROM wp_posts_backup_page;
Use a unique backup table name when wp_posts_backup_page already exists.
Step 11: Restore the Clean Revision
UPDATE wp_posts AS page
JOIN wp_posts AS revision
ON revision.ID = REVISION_ID
SET page.post_content = revision.post_content
WHERE page.ID = POST_ID;
MariaDB should report one changed row.
Step 12: Verify the Known Spam Is Gone
SELECT ID, post_title
FROM wp_posts
WHERE ID = POST_ID
AND (
post_content LIKE '%spam-keyword%'
OR post_content LIKE '%casino%'
OR post_content LIKE '%plinko%'
);
If MariaDB returns no rows, the restored page no longer contains those known terms. This does not prove that the entire site is clean.
- Open it in a private browser window.
- Check the page source.
- Test desktop and mobile.
- Confirm that no redirect appears.
- Clear WordPress, server, CDN, and browser caches.
- Check again while logged out.
Step 13: Exit MariaDB
EXIT;
This returns you to the normal SSH terminal.
Check Where Else It Hides
Restoring the page removes visible spam only from that record. Search other WordPress locations before you treat the site as clean.
Inspect Post Metadata
SELECT post_id, meta_key
FROM wp_postmeta
WHERE meta_value LIKE '%spam-keyword%';
Record the post_id and meta_key. Match the post_id with the related page before you edit anything.
Search WordPress Options
SELECT option_name
FROM wp_options
WHERE option_value LIKE '%spam-keyword%';
Record each returned option_name. WordPress options may contain widget data, theme settings, plugin settings, URLs, scheduled data, or cache values.
Review Spam Comments
SELECT comment_ID, comment_post_ID
FROM wp_comments
WHERE comment_content LIKE '%spam-keyword%';
Record the comment_ID, then review it in WordPress Dashboard → Comments. Do not open the submitted URL.
Expand the Search
Create a search list from the evidence:
- Every spam keyword
- Every unknown domain
- Every redirect destination
- Every foreign-language phrase
- Every suspicious brand
- Every encoded string
- Every unusual script fragment
Search relevant plugin tables when the infection involves a page builder, SEO plugin, cache plugin, redirect plugin, or custom content system.
- You verified the restored page
- You searched metadata, options, and comments
- You recorded suspicious results
- You preserved rollback copies
Why Deleting Users Failed
Malicious access or content may remain inside posts, pages, revisions, metadata, options, widgets, menus, comments, plugin tables, application passwords, active sessions, PHP files, cron jobs, scheduled tasks, caches, and server processes.
A Subscriber normally cannot edit published pages through standard permissions. The attacker may also have gained administrator access, changed a role, used an API credential, exploited a plugin, modified the database, compromised hosting, or installed a backdoor.
What SEO Spam Damages
Rankings Can Drop
Search engines may index spam instead of legitimate pages.
Visitors Lose Trust
Casino links, scams, adult content, or redirects can damage your reputation.
Google May Warn Users
Browsers and search engines may label the site hacked or unsafe.
Redirects Stay Hidden
Malware may react to device, location, browser, referral source, or login status.
The Spam Can Return
A backdoor, scheduled task, credential, or vulnerable plugin can recreate it.
Hosting Costs Rise
Spam records and background jobs can increase database and server load.
Remove Every Backdoor
Rotate Credentials Again
Rotate WordPress, hosting, AWS, database, SSH, SFTP, SMTP, CDN, API, application, and plugin credentials after cleanup.
Replace WordPress Core
Use a clean official copy. Review .htaccess, index.php, wp-config.php, and theme PHP files.
Reinstall Plugins and Themes
Use trusted vendor copies. Remove unused, abandoned, nulled, pirated, or unknown software.
Audit Every User
Review administrators, wp_users, wp_usermeta, roles, sessions, and application passwords again.
Update the Full Stack
Update WordPress, plugins, themes, PHP, MariaDB, Ubuntu, and server packages. Updates close known weaknesses but do not remove existing backdoors.
sudo apt update && sudo apt upgrade -y
This command updates Ubuntu packages. It does not update WordPress, plugins, or themes, and it does not remove malware. Restart services when required, then confirm that the website still works.
Scan the Uploads Folder
.php
.phtml
.phar
Record paths and timestamps, back up suspicious files, compare them with known legitimate files, and review nearby server activity.
Inspect Scheduled Tasks
Review WordPress cron, Ubuntu cron, plugin schedules, AWS automation, server timers, and unknown background processes.
Check Search Console
Look for unknown URLs, gambling queries, foreign-language terms, sudden index growth, security warnings, manual actions, unexpected sitemaps, ownership changes, and ranking drops. Request validation only after cleanup.
Stop the Next Attack
Protect Access
- Enable 2FA.
- Use unique passwords.
- Limit administrators.
- Audit application passwords.
- Restrict SSH.
- Use SFTP.
Keep Software Clean
- Update the full stack.
- Use trusted vendors.
- Remove unused software.
- Avoid nulled or pirated files.
Protect the Server
- Use a web application firewall.
- Apply least-privilege permissions.
- Disable PHP execution in uploads when appropriate.
- Create and test off-server backups.
Watch for Changes
- Monitor WordPress and server logs.
- Track file changes.
- Scan the database for spam terms and domains.
- Review users and roles.
- Moderate comments safely.
- Monitor Search Console.
- Check old databases before importing them.
Recovery at a Glance
| Phase | Main Goal | What We Checked |
|---|---|---|
| 1. Contain | Stop ongoing access | Administrators, application passwords, sessions, credentials, and 2FA |
| 2. Recover | Remove visible SEO spam | Database records, published page, revisions, metadata, options, and comments |
| 3. Harden | Reduce reinfection risk | Core files, plugins, themes, cron jobs, uploads, logs, and Search Console |
What Finally Worked
- We checked administrators.
- We recorded suspicious details.
- We revoked unauthorized application passwords.
- We avoided opening spam links.
- We changed credentials and enabled stronger authentication.
- We ended sessions.
- We backed up the server, files, and database.
- We searched
wp_posts. - We found the infected live page.
- We inspected revisions.
- We verified and restored a clean revision.
- We searched other tables.
- We reviewed files, plugins, users, and scheduled tasks.
- We rotated credentials again.
- We checked Search Console and monitored for reinfection.
The visible casino links only showed the symptom. The real recovery started when we stopped treating the homepage as the whole problem and traced the WordPress SEO spam into the database.
At Mockcertified, we now treat visible spam as a warning of a wider compromise. Recovery only ends after you remove unauthorized access, inspect persistence points, and close the weakness that let the attacker in.
For hands-on learning across cloud, cybersecurity, AI, and professional certifications, explore our Mockcertified practice tests.
WordPress Hack FAQs
Can spam survive a server migration?
Yes. Our spam returned after we imported the old database into a new AWS Lightsail instance.
Is deleting suspicious users enough?
No. Check application passwords, sessions, database records, files, plugin tables, scheduled tasks, and server access.
Can an application password still work?
Yes. Review and revoke application passwords directly from each user profile.
Should I delete every revision?
No. A revision may contain the last clean copy of a page.
Does restoring a revision remove the hack?
No. It repairs content but does not remove backdoors, vulnerable software, stolen credentials, malicious files, or reinfection tasks.
Can SEO spam hurt rankings?
Yes. Search engines may index spam pages, show irrelevant queries, reduce trust, or display warnings.
Should I rebuild the website?
A clean rebuild may offer the safest path when the attack affects many files, users, plugins, themes, or server components. Do not bring infected data into the new environment.



