Skip to content
Tutorials Center
My learning

Topics

Lesson 30 of 37 ยท Defence and Detection

Hardening Against Exploitation

A practical hardening guide: patch management, attack-surface reduction, exploit mitigations like ASLR, least privilege and configuration baselines you can script.

Every Metasploit module encodes someone else's discovery of a weakness. Almost all of them stop working on a system that is patched, minimal and configured sensibly. That makes hardening the highest-value defence, far more effective than any detection tool that only tells you after the fact.

This lesson is a checklist-driven tour: patching, attack-surface reduction, built-in exploit mitigations, privilege limits and baselines, with Python stand-ins that audit configuration data.

Patch management

Most exploited vulnerabilities have fixes available for months. A healthy process has:

  • An inventory of what is installed, with versions.
  • A way to learn about new advisories (vendor feeds, the CVE and CISA Known Exploited Vulnerabilities lists).
  • Prioritisation: internet-facing and actively exploited issues first.
  • Deadlines by severity, and a tested rollback.
  • Verification: scan after patching to confirm the fix applied.
Python Check patch deadlines

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Reduce the attack surface

If a service is not running, it cannot be exploited. Walk through each host and ask what is truly needed.

  • Remove unused software and disable unused services.
  • Close ports at the host and network firewall; allow only what the role needs.
  • Do not expose management interfaces (RDP, SSH, databases, admin consoles) to the internet; put them behind a VPN or a bastion with MFA.
  • Remove default accounts, sample files and debug endpoints.

Built-in exploit mitigations

Modern platforms include defences that make memory-corruption exploits harder. You do not have to write them, only keep them on and avoid building software without them.

Mitigation What it does
ASLR Randomises memory addresses so exploits cannot hard-code them
DEP / NX Marks data memory as non-executable
Stack canaries Detect stack overwrites before a function returns
CFG / CET / shadow stacks Restrict where control flow may jump
Sandboxing Confines a compromised process to few permissions
Memory-safe languages Remove whole bug classes

Least privilege

Assume an attacker will get a foothold, and make the foothold useless.

  • Run services under dedicated, low-privilege accounts.
  • Separate daily-use accounts from administrator accounts.
  • Use per-host unique local admin passwords (managed by a tool such as LAPS on Windows).
  • Segment networks so a single host cannot reach everything (Pivoting and Routing Concepts).

Configuration baselines you can script

A baseline is the approved configuration. Comparing real hosts to it finds drift automatically.

Python Compare hosts with a baseline

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Industry benchmarks such as the CIS Benchmarks and DISA STIGs provide ready-made baselines for operating systems and applications. Tools like OpenSCAP and Lynis check them.

Web application hardening

Web apps account for many breaches.

  • Validate input and encode output; use parameterised queries.
  • Keep frameworks and dependencies updated, and scan them for known vulnerabilities.
  • Turn off verbose error pages and directory listing.
  • Deploy a web application firewall as an extra layer, not a replacement for fixing code.
Python Check HTTP security headers

Press Run (or Ctrl + Enter) to see the result here.

Program input ยท what you'd type while the program runs

Type the answers before you press Run, one per line. Each time the program reads a line (with input()), it gets the next line from this box.

Verify with your own tools

Hardening is only real once tested. Run your own scans and an authorized assessment periodically, and compare results with the previous run. Findings that reappear show a process gap, not a technical one.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which reduces exploitation most reliably?

    Patched, minimal systems have little left for a module to exploit.
  2. 2. What does ASLR do?

    Address space layout randomisation makes memory-corruption exploits less reliable.
  3. 3. What is a configuration baseline?

    Baselines let you detect configuration drift automatically.
  4. 4. Should management interfaces face the internet?

    Exposed admin interfaces are a favourite target; restrict and protect them.

Summary

  • Patch quickly, prioritise internet-facing and actively exploited issues.
  • Remove what you do not need; close and restrict ports.
  • Keep platform mitigations (ASLR, DEP, sandboxing) enabled.
  • Apply least privilege and segment the network.
  • Use baselines and scripts to detect drift; verify with your own authorized scans.

Next: Logging and Incident Response