Skip to content
Tutorials Center
My learning

Topics

Lesson 22 of 31 ยท Exploitation Concepts and Reporting

Exploitation, Privilege Escalation and Post-Exploitation Concepts

Understand how exploitation frameworks are structured, what privilege escalation and post-exploitation mean, and how patching, least privilege and monitoring stop them, with a Python risk checklist.

Earlier lessons found things: open ports, old software, weak settings. Exploitation is the step where a tester shows that a weakness is real by using it in a controlled way. It answers the question every manager eventually asks: "Is this finding actually dangerous, or just theoretical?" In an authorized test the answer is a small, safe proof; in the wrong hands it is a break-in. The difference is permission, which is why Law, Ethics and Authorization comes first in this course.

This lesson stays at the level of concepts and defense. You will learn how exploitation frameworks like Metasploit are organized, what privilege escalation and post-exploitation mean, and, most importantly, which defenses break each stage. There are no working exploits here. The Python stand-in is a risk checklist that scores invented systems, the sort of reasoning that defenders do daily.

The attacker's path, in stages

Initial access A weakness gives a first foothold.
Escalation A small account becomes a powerful one.
Post-exploitation Look around, move, persist.

Every stage is also a place where defenders can stop it.

1 / 2

What an exploit is

A vulnerability is a flaw: a buffer that can overflow, a missing permission check, a default password. An exploit is the technique or code that takes advantage of it. A payload is what runs once the flaw is used, and it can be harmless (print a marker) or harmful. Three words keep the picture straight:

  • vulnerability: the weakness;
  • exploit: the way in;
  • payload: what happens next.

Flaws are cataloged by CVE numbers (see Vulnerability Assessment Workflow). A flaw with a public exploit is a much bigger risk than one without, because the effort needed to use it falls to almost nothing. A zero-day is a flaw the vendor does not yet know about. Defenders cannot patch it, so for zero-days the layers (least privilege, segmentation, monitoring) do the work.

Common classes of flaw include memory-safety bugs in native code, injection in web applications (Injection and Input Validation: Defense), broken authentication, misconfiguration and unpatched software. Misconfiguration and missing updates account for most real incidents; exotic flaws are the minority.

How an exploitation framework is organized

A framework such as Metasploit (included on Kali) packages thousands of known techniques into a consistent structure, so that a tester does not rewrite the same plumbing for each one. Understanding the structure also helps defenders read about it. The main parts:

Part Role
Exploit modules Code for one specific flaw in one product and version
Payloads What to run after success, selectable separately
Auxiliary modules Scanners, version checkers and other non-exploit helpers
Post modules Actions after access, for example collecting information from a host
Encoders and evasion Change how a payload looks so signature-based tools miss it
Console and database A shell to choose modules and set options, and storage of discovered hosts and results

The workflow in the console is conceptually: choose a module, set the options (target address, port), check whether the target appears vulnerable, then run it. The separation of exploit and payload is what makes the framework flexible: the same entry technique can carry different follow-up actions.

A session in the console looks like this (read-only; the address is from the documentation range and the module is only an example of the format):

TEXT
msf6 > search type:auxiliary smb_version
msf6 > use auxiliary/scanner/smb/smb_version
msf6 auxiliary(scanner/smb/smb_version) > show options
msf6 auxiliary(scanner/smb/smb_version) > set RHOSTS 192.0.2.10
msf6 auxiliary(scanner/smb/smb_version) > run

Everything here depends on scope. Setting RHOSTS to an address outside your written authorization is exactly the mistake that turns a test into an offense. Many teams keep the scope list next to the tool and check every address against it before a run (the stand-in in Law, Ethics and Authorization models this).

For defenders, frameworks are a gift as well as a threat: because techniques are public and standardized, security vendors write detections for them. A tester's tools get caught by endpoint protection, which is a good sign for the organization.

Privilege escalation

Most intrusions start with a low-privilege foothold: a web-server user, an ordinary employee account, a service with limited rights. That is rarely enough for an attacker's goals, so the next step is privilege escalation: gaining higher rights.

  • Vertical escalation moves up: from a normal user to administrator or root (Linux) or SYSTEM (Windows).
  • Horizontal escalation moves sideways: using one user's rights to reach another user's data at the same level.

Escalation does not need a clever exploit very often. The usual causes are ordinary mistakes:

  • Outdated software with a known local privilege flaw (patch management).
  • Overly broad sudo rules, such as letting a user run an editor or interpreter as root (an editor can start a shell).
  • Writable files that privileged things use: scripts run by root from a folder anyone can change, or cron jobs that call a program by a relative path.
  • SUID/SGID programs that run with their owner's rights and have a flaw or can be abused as designed.
  • Weak service accounts and passwords reused between systems.
  • Credentials left in files: configuration files, shell history, backups, environment variables.
  • On Windows: unquoted service paths, services running as SYSTEM with a writable binary, and over-permissive group membership.

An authorized tester checks for these on a lab or an in-scope machine, using known enumeration scripts or manual review. A defender can run the same review on their own systems, with the Linux knowledge from Command Line Essentials for Security Work (sudo -l, find / -perm -4000, file permissions). The most useful habit is simply asking: "If this account were taken over, what could it do?"

Post-exploitation

After gaining access, an attacker (or an authorized tester simulating one) typically goes through several activities. Knowing them helps you place detection where it matters:

  1. Situational awareness: who am I, what is this machine, what is on the network? Defenders see unusual commands and a burst of internal connections.
  2. Credential access: looking for passwords, tokens and keys. Defenders see access to credential stores and unusual authentications.
  3. Lateral movement: using stolen credentials or trust relationships to reach other machines. Defenders see logins from unexpected hosts at unexpected times.
  4. Persistence: arranging to come back after a reboot (new accounts, scheduled tasks, startup entries). Defenders see new accounts and changed scheduled jobs.
  5. Collection and exfiltration: gathering data and sending it out. Defenders see large or unusual outbound transfers.
  6. Covering tracks: deleting logs, which is why central log storage matters (Firewalls, IDS and Log Monitoring).

The industry organizes these behaviors in the MITRE ATT&CK knowledge base, a catalog of tactics (the "why", for example Persistence) and techniques (the "how"). Defenders map their alerts and tests to it to find gaps: "we can detect new accounts, but not changed scheduled tasks."

In an authorized penetration test, post-exploitation is done with restraint: prove impact with minimal data (screenshot a file's name, not its contents), avoid anything that could damage systems, record every action, and clean up afterward (The Penetration Test Lifecycle).

Defense that interrupts the chain

You do not need to stop every stage; breaking any link helps.

  • Patch management: inventory what you run, track advisories, patch by risk, and verify. Prioritize internet-facing systems and flaws with known exploitation. Unpatched, publicly known flaws are the easiest wins for attackers.
  • Least privilege: users, services and applications get only the rights they need. Remove local admin rights from daily accounts, scope sudo rules to exact commands, and use separate accounts for administration.
  • Secure configuration: change default credentials, close unused services, harden baselines.
  • Segmentation: separate networks so that a compromise of one workstation does not reach the database servers.
  • Strong authentication: multi-factor authentication limits the value of stolen passwords, and unique passwords stop reuse between systems (Password Storage and Hashing).
  • Detection: endpoint protection, central logging, and alerts on the behaviors above.
  • Response practice: know who does what when an alert fires, and rehearse it.

A stand-in: a privilege-escalation risk checklist

The rules below check invented hosts against the weaknesses listed above and add a weighted score. It is not an exploit scanner and cannot test any real system; it shows how a review turns into a ranked to-do list.

Python Score hosts against a privilege-escalation checklist

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.

The result is a priority order: fix dev-box first, then web-01. Notice that the weights are a judgment, not a measurement; in a real review you adjust them for exposure and for what each host stores.

A stand-in: detecting suspicious post-exploitation behavior

Detection is often just comparing events with what is normal. This stand-in watches invented authentication events and flags two behaviors from the list above: a login from a host a user never used before, and a new account created outside business hours.

Python Flag unusual logins and account creation

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.

Real rules need more context (maybe Alice is on call tonight), which is why alerts feed a person rather than automatically locking accounts. See the tuning notes in Firewalls, IDS and Log Monitoring.

Check your understanding

Quick check ยท 5 questions

of 5 answered You scored / 5 ยท perfect!

  1. 1. What is the difference between an exploit and a payload?

    An exploit is the technique that uses a vulnerability to get in. A payload is the code or action that runs once it succeeds. Frameworks keep them separate so they can be combined.
  2. 2. Which is an example of horizontal privilege escalation?

    Horizontal escalation reaches other accounts at the same level. Vertical escalation moves up to higher rights.
  3. 3. Which control most directly limits the damage when a low-privilege account is taken over?

    If an account holds only the rights it needs and the network is segmented, a stolen account reaches far less.
  4. 4. Why should a penetration tester check each target against the written scope before running a module?

    Permission defines what is legal. One wrong address can turn an authorized test into an offense.
  5. 5. Which is the most common real cause of privilege escalation?

    Misconfiguration and unpatched software account for most incidents, which is good news: they are fixable with routine hygiene.

Summary

  • A vulnerability is the flaw, an exploit is the way to use it, and a payload is what runs afterward. Public exploits make unpatched flaws far riskier.
  • Frameworks like Metasploit organize exploit, payload, auxiliary and post modules behind one console; scope control is the tester's responsibility.
  • Privilege escalation is usually caused by old software, broad sudo, writable files used by privileged tasks, SUID programs and stored secrets.
  • Post-exploitation covers awareness, credentials, lateral movement, persistence, exfiltration and cleaning logs. MITRE ATT&CK catalogs it.
  • Patching, least privilege, secure configuration, segmentation, multi-factor authentication and monitoring each break a link in the chain.
  • The Python examples are defensive stand-ins on invented data; no exploit code is run or taught.

Next: The Penetration Test Lifecycle.