How WordPress sites get hacked

Attacks on WordPress are mostly automated. Bots scan the web for sites running a plugin version with a known hole, or try passwords against login forms, and act on whatever answers. Very few attacks on a small business’s site are personal. That shapes what security work matters:

  • Plugins and themes with known holes. Most published WordPress vulnerabilities are in plugins and themes, not in core. Once a hole is public, bots often start looking for it within days.
  • Stolen and reused passwords. An administrator who uses the same password elsewhere, or saved it in a browser on an infected laptop, hands over the site without any hole at all.
  • Abandoned plugins. A plugin whose developer has stopped will never get a fix. WordPress.org closes plugins with unresolved security issues, but they stay installed on sites until someone removes them.
  • Pirated (“nulled”) plugins, which often ship with a backdoor already in them.
  • File managers and code snippet plugins, which give anyone who reaches wp-admin the server’s files and code.
  • Neighbors. Several sites in one hosting account can often read each other’s files, so one forgotten old copy of a site can infect the rest.

Security plugins and services are built around these doors. The rest of this guide is the work behind them, in the order that matters for client sites.

WordPress security best practices, in order

If you only do some of these, do them from the top:

  1. Fix serious holes the same day. Match every plugin and theme version against a vulnerability feed daily, and update when a fix exists. A hole anyone can reach without logging in, with a high severity score, cannot wait for the weekly window.
  2. Require two-step login for administrators. It defeats most stolen and reused passwords.
  3. Remove what is not used. Inactive plugins and themes can still be attacked. Delete them.
  4. Replace abandoned and closed plugins. No release in two years, or closed on WordPress.org: find an alternative.
  5. Give people the lowest role that works. An editor does not need to be an administrator, and a shared “admin” login is a risk nobody can trace.
  6. Harden the basics, and check from outside that each setting really works.
  7. Run a firewall that loads before WordPress, with rules for the holes on your sites, for the time between a hole becoming known and the fix reaching the site.
  8. Scan files and the database daily, and watch for new administrators and new PHP files.
  9. Keep backups away from the server, and test a restore.
  10. Know what to do when it happens anyway, before it happens.

Patching: the race after a hole is published

When a vulnerability is published, it comes with a severity (a CVSS score from 0 to 10), the versions affected and the version that fixes it. Two details decide how fast you move:

  • Who can reach it. “Unauthenticated” means any visitor; “Subscriber+” or “Customer+” means anyone who can make an account, which on most shops is anyone. Those are as urgent as unauthenticated holes. “Administrator+” holes matter much less.
  • Whether a fix exists. If it does, update. If it does not, or the update cannot download (a premium plugin without an active license on that domain), you need another way to cover the gap: a virtual patch in a firewall, closing the plugin’s exposed entry points to visitors, or switching the plugin off.

Updating safely matters here too: a security fix that breaks the checkout is still a broken checkout. The WordPress updates guide covers how to update without breaking sites, and virtual patching covers what a firewall rule can and cannot do for an unpatched hole. The WAF explainer covers firewalls in general.

Logins and people

  • Two-step login for every administrator, and ideally every account that can publish. An authenticator app is strongest; a code by email is better than nothing and needs no setup.
  • Breached passwords refused. Passwords that appear in known data breaches are the first ones tried. A check against breach data at password change and login catches them.
  • Login limits. Lock an address out after a few failed logins, using the visitor’s real address, not one from a header an attacker can set.
  • XML-RPC off unless something needs it. xmlrpc.php lets a bot try many passwords in one request.
  • Application passwords off if nothing uses them.
  • Hidden administrators. Malware often creates an administrator and hides it from the Users screen. Compare the administrators in the database with the ones wp-admin shows.
  • One login, many sites, minutes apart. If the same login signs in on several client sites within minutes from different addresses, it is a tool with a stolen password, not a person.

Hardening, and how to check it from outside

Hardening is a set of small settings that close easy doors. The catch: a setting switched on is not always in effect. A rule in .htaccess does nothing on a server that ignores .htaccess (nginx does), and a page cache can serve headers from before the change. So check each one the way an attacker would, from outside:

Setting How to set it How to check it
No file editor in wp-admin define( 'DISALLOW_FILE_EDIT', true ); in wp-config.php Appearance has no Theme File Editor
XML-RPC blocked Server rule or plugin A POST to /xmlrpc.php is refused
User list hidden Block ?author=N and the REST users route for visitors /?author=1 does not redirect to an author page; /wp-json/wp/v2/users does not list users
No PHP in uploads Deny PHP in wp-content/uploads A PHP file placed there does not run
Sensitive files blocked Deny debug.log, .git, .env, readme.html, database dumps Each answers 403 or 404
No folder listings Options -Indexes on Apache /wp-content/uploads/ shows no file list
Security headers X-Content-Type-Options, Referrer-Policy, X-Frame-Options, HSTS The headers are on fresh and cached pages

From a terminal, for an example site:

curl -sI https://harbourbakery.example/ | grep -i -E "strict-transport|x-content-type|x-frame|referrer"
curl -s -o /dev/null -w "%{http_code}\n" https://harbourbakery.example/wp-content/debug.log
curl -s -o /dev/null -w "%{http_code}\n" https://harbourbakery.example/.git/HEAD
curl -s https://harbourbakery.example/wp-json/wp/v2/users

WordPress’s own hardening guide has the background on each. Leave out what breaks sites without tuning, such as a strict Content-Security-Policy, until you can test it per site. Hardening has more on checking from outside.

Firewalls: in the cloud or on the site

A web application firewall reads each request and refuses the ones that match known attacks. It can run in two places:

  • In the cloud, in front of the server: traffic passes through the provider first. It stops floods before they cost your server anything, but it can be bypassed if the server’s own address is known, and it sees requests without knowing which plugins the site runs.
  • On the site, loading before WordPress: it sees each request as WordPress will, can tell a logged-in editor from an anonymous visitor, and can carry rules for the exact plugins and versions the site runs.

What to look for in either: rules for the holes on your sites, a learning period so real customers are not blocked on day one, a blocklist that learns from attacks on all your sites at once, and a log you can read. A firewall does not replace updates, and it cannot stop someone logging in with a stolen password. The firewall describes one that loads first and learns before it blocks.

Malware scans and file integrity

Scanning has two halves:

  • Integrity. WordPress.org publishes checksums for every core release and for plugins hosted there. Comparing files with them finds changed and added files exactly: wp core verify-checksums and wp plugin verify-checksums --all do it from WP-CLI. PHP files in wp-content/uploads, in hidden folders, or in WordPress’s own folders where WordPress ships none, are findings on their own.
  • Signatures. Files that cannot be verified, such as premium plugins, custom themes, must-use plugins and wp-config.php, have to be read for patterns of malicious code: decoded code run with eval, web shells, card skimmers in checkout scripts. Options and posts in the database need reading too, because injected scripts often live there.

Scan daily, and again at once after anything critical: a new administrator, a plugin installed by hand, a changed site address. Quarantine rather than delete, so a false alarm can be put back. A scanner that reads only plugin files will miss malware in the database or outside the WordPress folder. See the malware scanner, and for a site that is already infected, how to remove malware from WordPress.

Shops and sites that take payments

A WooCommerce site holds customers’ names, addresses and order histories, and its checkout is where card skimmers are planted. Card details usually go straight to the payment provider, but a script injected into the checkout page can read them as the customer types. Extra care for these sites:

  • Watch the checkout page’s scripts. Note which outside hosts the checkout loads scripts from. A new host, or an inline script that reads card fields and sends data somewhere, is an alarm.
  • Watch the payment methods. A new payment method switched on, or an existing one whose code now comes from a different plugin, is how some skimmers take over a real gateway.
  • Fewer administrators. Shop managers can run the store without being administrators.
  • Two-step login for every account that can change the site, including shop managers.
  • Check the checkout after every update, not only the home page: add to cart, go to checkout, see the payment form load.
  • Keep the store’s plugins current, especially payment gateways and anything that touches the cart.

Card handling rules come from the card networks and the payment provider, and they depend on how the store takes payments. Ask the provider what applies, and do not promise a client their store is “compliant” because it runs a firewall.

When a site is hacked anyway

  1. Take a copy of the site as it is, for evidence, before you change anything.
  2. Log everyone out, reset every administrator’s password, and lock code changes.
  3. Find the way in: an outdated plugin, a stolen login, a neighbor in the same hosting account.
  4. Clean: replace core and plugins with clean copies, remove unknown files, check the database and wp-config.php, check scheduled tasks for anything that puts malware back.
  5. Close the way in, then watch the site closely for the next weeks.
  6. Tell the client what happened, what you did and what changes.

The step-by-step version is what to do when a WordPress site has been hacked.

What to tell clients about security

Never promise a site cannot be hacked. Show what you do instead: the holes found and fixed this month, the attacks the firewall blocked, the failed logins stopped, the scans run and their results, and the protection checks that pass. A number with a plain sentence (“1,204 attacks blocked this month, most of them bots trying known plugin holes”, for an example site) makes security work visible without turning it into fear. What goes in a report is in client reports.

How Keptstone secures client sites

Keptstone runs its own security layer on each site through its connector, and checks it from outside.

In both plans (Care, $2 a site a month):

  • Vulnerability alerts for every plugin and theme on every site, with what covers each hole until it is fixed, and safe updates that apply the fix.
  • Two-step login for client administrators, with codes by email so nothing needs setting up, authenticator apps and backup codes; breached passwords refused; login lockouts.
  • Hardening: file editor off, XML-RPC blocked, user lists hidden, no PHP in uploads, sensitive files blocked, no folder listings, security headers, HSTS raised step by step. Every switch is tested from the site itself, the way an attacker would see it, and scored. See hardening and two-step login.
  • A code lock that stops plugin and theme zips being uploaded from wp-admin, and an administrator guard that undoes an administrator made by anything but a signed-in administrator, WP-CLI or Keptstone.

On Care + Protect + Speed ($4 a site a month):

  • A firewall that loads before other plugins, learns for 14 days before it blocks, and shares a blocklist across your agency’s sites.
  • Patches for the holes found on your sites: a handful of hand-written rules, not a large database. A plugin with a High or Critical hole that nothing covers has its AJAX and REST entry points closed to logged-out visitors until a fix arrives.
  • Daily malware scans with Keptstone’s own engine, a file watch every 15 minutes, and a checkout watch for new payment methods and checkout scripts. See vulnerability alerts and the malware scanner.
  • Repair tools: restore a changed WordPress file from WordPress.org, reinstall a changed plugin with a restore point first, quarantine an unknown file (it can be put back). Database and server findings show the code to fix by hand.

These are malware scanning and repair tools, not a done-for-you malware removal service. See pricing.

Questions

Is WordPress secure?

WordPress core has a security team and ships fixes quickly, and minor releases install themselves by default. Most risk comes from the plugins and themes added to it, the passwords people use and how the site is kept. A well-kept WordPress site is as safe as any other platform; a neglected one is an easy target.

Do I need a security plugin if my host has a firewall?

A host's firewall stops a lot of generic traffic, but it usually does not know which plugins a site runs or which of their holes are open. Two-step login, hardening, vulnerability alerts and file scans are still needed on the site itself. Check what the host covers before you add anything.

How do most WordPress sites get hacked?

Mostly through plugins or themes with a published vulnerability that were not updated in time, and through administrator passwords that were reused, guessed or stolen. Abandoned and pirated plugins, and file managers left installed, come next.

Does a web application firewall replace updates?

No. A firewall can block known ways of reaching a hole, which buys time until a fix is installed, but the vulnerable code is still on the site. Update to the fixed version as soon as one exists.

Can Keptstone clean a hacked site for me?

Keptstone provides malware scanning and repair tools on its higher plan: restoring changed WordPress files from WordPress.org, reinstalling changed plugins, quarantining unknown files. It is not a done-for-you malware removal service, so a badly compromised site still needs a person to investigate and clean it.