How sites get hacked

How websites get hacked — and how to tell

Most business sites are not broken into by a clever genius. They are found by automated bots looking for the same handful of mistakes. Here is what each one looks like, in plain language, with a safe example.

Exposed secretsCritical

The .env file left in the open

Many apps keep their passwords and keys in a file called .env. If that file sits in the public web folder, anyone can simply download it — no hacking needed.

What it looks like

How it plays out

An attacker scanning thousands of sites requests /.env on each one. On yours it returns the database password in plain text. Minutes later they are logged into your database copying customer records.

The fix

Keep .env outside the public folder and block dotfiles in the web server. If it was ever exposed, change every password and key in it.

Exposed filesCritical

Forgotten backups and database dumps

Before making a change, people often save a copy — wp-config.php.bak, backup.zip, database.sql — right on the live server. These copies are downloadable by anyone who guesses the name, and bots guess thousands of names.

What it looks like

How it plays out

A database dump holds every user record and password hash on the site. Once downloaded, the attacker cracks weak passwords offline at their leisure, then logs in as a real administrator.

The fix

Never store backups in the web folder. Keep them somewhere that is not served to the public, and delete stray .bak / .old / .zip files.

MisconfigurationHigh

Directory listing — browsing your files like a folder

When a folder has no index page and listing is left on, the server shows a clickable list of everything inside it. Visitors can wander through uploads, invoices and old scripts that were never linked anywhere.

What it looks like

How it plays out

A customer uploaded their ID for verification. Because the uploads folder lists openly, anyone who finds the folder can download every document in it — a personal-data breach under data-protection law (GDPR, PDPA and similar).

The fix

Turn off directory listing: "Options -Indexes" on Apache/cPanel, or "autoindex off;" on nginx.

Outdated softwareHigh

An out-of-date WordPress, Joomla or plugin

When a flaw is found in WordPress, Joomla or a plugin, it is published — and the fix with it. Bots immediately start hunting for sites still running the old version, because the exploit is now public.

What it looks like

How it plays out

Outdated plugins are the single most common way WordPress sites are hacked. A bot finds a vulnerable slider plugin, uploads a backdoor through it, and now controls the whole site.

The fix

Update core, plugins and themes, and turn on auto-updates. Remove anything you no longer use — deactivated plugins can still be exploited.

InjectionCritical

SQL injection — turning a form into a database command

If a site drops whatever you type straight into its database query, a crafted value can change the meaning of that query — letting an attacker read or delete data they should never see.

What it looks like

How it plays out

The site shows a database error the moment a quote is added to a link — the tell-tale sign. From there an attacker rewrites the query to dump the users table. This is behind a large share of real data breaches.

The fix

Use parameterised queries / prepared statements everywhere, so input is always treated as data, never as part of the command. Hide database errors in production.

InjectionHigh

Cross-site scripting — your page running an attacker’s script

If a site echoes your input back into the page without encoding it, an attacker can craft a link that makes your own site run their JavaScript in a visitor’s browser.

What it looks like

How it plays out

An attacker emails your customer a link to your real site with a crafted search term. Because the site does not encode it, the script runs, copies the customer’s logged-in session, and sends it to the attacker.

The fix

Encode all user input when writing it into a page, using your framework’s output-escaping. Add a Content-Security-Policy as a second layer.

EncryptionHigh

No HTTPS — traffic anyone can read

Without HTTPS, everything between your visitor and the site travels as plain text. Anyone sharing the same Wi-Fi can read passwords and form data, or quietly change the page.

What it looks like

How it plays out

A staff member logs into the admin panel from a café. Because the site is http://, someone on the same network captures the username and password in the clear.

The fix

Install a free TLS certificate (Let’s Encrypt / cPanel AutoSSL) and redirect all http:// traffic to https://.

Email spoofingHigh

Missing SPF/DMARC — anyone can email “as” you

If your domain has no SPF and DMARC records, mail servers cannot tell a real email from your company apart from a forged one. Fraudsters send fake invoices that appear to come from you.

What it looks like

How it plays out

A supplier receives an email that looks exactly like it came from your finance team, asking them to pay a new bank account. Nothing flagged it, because your domain never told their mail server how to spot a forgery.

The fix

Publish an SPF record ending in -all, and a DMARC record at _dmarc.yourdomain starting at p=none, then tighten to p=quarantine and p=reject.

See which of these apply to your site

Verify your domain, then get a report that checks for every problem on this page.

The examples here are illustrations on a made-up site. Never try these techniques on a website you do not own or have permission to test.