Skip to content
Tutorials Center
My learning

Topics

Lesson 39 of 53 ยท Systems and Post-Exploitation Concepts

Persistence, Lateral Movement and Detection

Understand at concept level how attackers stay in and spread across a network, how MITRE ATT&CK maps these steps, and which logs and controls detect them.

Getting in is only the first step of a real intrusion. An attacker who has one compromised machine usually wants to keep access even after a reboot or password change, and then reach the systems that hold the valuable data. These two goals have names: persistence (staying in) and lateral movement (spreading sideways to other systems).

This lesson stays at the concept level and focuses on detection and prevention. It lists no step-by-step intrusion procedures. Defenders benefit from knowing these behaviors because each one leaves traces that good logging can catch. The runnable stand-ins are Python programs that look for suspicious patterns in made-up event data.

After the first foothold

Persistence Survive reboots and password changes.
Credential access Collect keys to more systems.
Lateral movement Hop to other machines.
Objective Reach data, steal it, or disrupt.

Each step creates events. Defenders win by noticing one of them.

1 / 2

Persistence: staying in

An attacker who relies on a single running process loses everything when the machine restarts or the process is found and killed. Persistence mechanisms make the access come back. Described by category rather than by recipe, they include:

  • Startup mechanisms: programs, services or scheduled jobs set to run at boot or login.
  • New accounts or credentials: a hidden or look-alike user, an added SSH key, a created access key in a cloud account.
  • Modified existing components: changed configuration, altered scripts, a replaced legitimate program, or a hidden web page on a server (often called a web shell).
  • Account-level and cloud persistence: extra OAuth app consents, forwarding rules in a mailbox, or backdoor roles.
  • Low-level persistence in boot components or firmware: rare and costly, but very hard to remove.

The common thread for defenders is change. Persistence means something on the system was created or modified, and many of those changes are loggable and auditable: new services, new scheduled tasks, new accounts, new authorized keys, new cloud roles. A baseline of what is supposed to exist makes the difference obvious.

Lateral movement: spreading

Once on one machine, an attacker explores. They learn what the machine is connected to, who is logged in, and where administrators work. They then try to use credentials or trust relationships to reach other systems. Typical ingredients:

  • Stolen or reused credentials: passwords or tokens found on disk or in memory, and passwords shared between accounts or machines.
  • Remote administration channels: legitimate tools such as remote desktop, SSH, remote management and file shares. Attackers use what is already allowed because it blends in. This is called "living off the land".
  • Trust relationships: services that trust each other, flat networks where everything can reach everything, and overly broad administrator groups.
  • Unpatched internal services: systems inside the perimeter often receive less attention than those facing the internet.

This is why the order of the lessons matters: the earlier chapters on segmentation, least privilege and password security are what actually slow an intruder down.

Mapping behavior with MITRE ATT&CK

MITRE ATT&CK is a public knowledge base that organizes observed adversary behavior into tactics (the goal, such as "persistence" or "lateral movement") and techniques (how the goal is reached). Each technique has an ID, a description, real-world examples, and ideas for detection and mitigation.

Why it helps:

  • A shared language: "we see a technique under Persistence" means the same thing to every team.
  • Coverage mapping: list which techniques your logging can detect and which it cannot, then close the gaps. A purple team exercise tests one technique at a time.
  • Better reports: findings and detections are tied to behaviors, not only to tool names that change weekly.

Because technique IDs are numbered and sometimes reorganized, look them up in the current ATT&CK matrix when you need one rather than memorizing numbers.

Logging that catches it

You cannot detect what you do not record. The valuable sources for this stage are:

Source Useful events
Authentication logs Successful and failed logins, source address, logon type, new devices
Process creation logs Which program started which, with the command line
Service, scheduled task and startup changes New or modified items
Account and group changes New users, privilege changes, new SSH keys
Network flow and DNS logs Internal connections that never happened before, rare destinations
Cloud audit logs New access keys, role changes, unusual API calls
Mailbox audit logs Forwarding rules, OAuth consents

Send these to a central system so an attacker who controls one machine cannot erase the only copy, and keep the clocks synchronized so timelines line up (Logging, Monitoring and SIEM Basics covers this in detail).

Detection ideas that work well:

  • A user logging in to many different machines in a short time.
  • A normal account performing administrative actions it never did before.
  • A login at a strange hour or place, followed by account or startup changes.
  • Workstation-to-workstation connections, which are rare in a healthy network where workstations talk to servers.
  • A new scheduled job or service created outside change windows.

Stand-in: spot a suspicious sequence

Single events are often harmless; sequences tell the story. This Python program scans made-up events and flags a user who logs in on three or more hosts within ten minutes, and a new account created soon after a login from an unusual source. It reads a list; nothing real is touched.

Python Stand-in: lateral movement sequence detector

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.

In a real network a backup service account legitimately touches many hosts, so the rule needs an allow-list or a per-account baseline. That tension, between catching real attacks and annoying analysts with false alarms, is the heart of detection work.

Stand-in: compare against a known-good baseline

Because persistence means something changed, a baseline comparison is a simple and strong detector. This program compares a made-up list of scheduled tasks and accounts with the approved list.

Python Stand-in: baseline drift check

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.

Each "NEW" line is a question for a human: was this an approved change? The same method works for firewall rules, cloud roles and installed software.

Prevention and response

  • Segment the network, and block workstation-to-workstation traffic where it is not needed.
  • Use unique local administrator passwords per machine (tools such as a local-admin password manager exist for this) so one stolen password cannot open every door.
  • Keep administrators on separate admin accounts that are used only on hardened machines, so their credentials are not left on ordinary workstations.
  • Require MFA for remote access and administration, and limit who may use remote administration tools.
  • Patch internal systems as carefully as external ones.
  • Prepare an incident response plan so a detection leads to containment rather than confusion; see Incident Response and Digital Forensics Basics. Cleaning one machine is rarely enough: remove every persistence mechanism, rotate credentials the attacker could have seen, and verify the result.

Authorization still applies. Testing lateral movement or persistence on real systems is a high-risk activity that must be explicitly included in the signed scope. Practice these ideas only in your own lab, and always agree how to reverse any change.

Pivoting, data gathering and backdoors

Three further ideas complete the post-exploitation picture. Each is shown from the point of view of what a defender can see, and each is practiced only in a lab or within an explicit scope.

Pivoting

Pivoting means using one compromised machine as a stepping stone to reach systems that the attacker could not reach directly, such as an internal network behind a firewall. A pivot host might sit on two networks (a dual-homed server), or it might simply have rules that allow it to reach internal services. Techniques include forwarding a port through the pivot host, tunneling traffic over an allowed protocol (an SSH tunnel is the classic example), and proxying tools through it so that scans and requests appear to originate from the inside.

flowchart LR
  A["Tester / attacker"] --> B["Pivot host<br/>(web server in DMZ)"]
  B --> C["Internal database"]
  B --> D["Internal file server"]
  A -. "blocked by firewall" .-> C

The firewall blocks direct access, but trusts the pivot host. Segmentation fails when that trust is too broad.

For defenders the lesson is the same as in lateral movement: segmentation must be enforced in both directions. A web server needs to reach one database port, not the whole internal network. Egress filtering, internal firewalls, host-based firewalls and alerts on unusual connections from servers that normally never initiate them (logging and SIEM) all make pivoting harder and noisier.

Data gathering

After access, attackers look for what matters: documents, source code, credentials in configuration files, browser-saved passwords, database contents, mail and keys. In an authorized test the goal is to demonstrate access without collecting real sensitive data: list that a folder is readable, capture a screenshot or a file name, copy a harmless marker file, and redact any evidence. Taking actual customer data into a tester's laptop creates its own breach risk. Agree beforehand what may be touched, and store evidence encrypted.

Defenders limit the damage with least privilege, encrypted data at rest, secrets managers instead of passwords in files, data loss prevention and alerts on unusual bulk reads or transfers.

Backdoors

A backdoor is any hidden way back in that bypasses normal authentication: an extra account, an authorized SSH key, a scheduled task that reconnects, a modified service or a web shell on a server. It differs from a vulnerability because it is planted deliberately. In testing, anything you plant must be documented and removed. In defense, you hunt backdoors by baselining and comparing: accounts, keys, scheduled tasks, services and startup items against a known-good list, plus file integrity monitoring on web roots and system folders.

The stand-in below reads an invented host snapshot and a known-good baseline and lists what has been added, the core of backdoor hunting. It also records an outbound connection that violates a server's normal behavior.

Node.js Find backdoor candidates and odd egress

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 node:readline or process.stdin), it gets the next line from this box.

Every item is only a candidate. A real new account might be an approved change; the point is that nothing on a server should appear without a record explaining it. Cleaning up afterwards follows the playbook in incident response, and for testers, the discipline of removing everything they added is part of the methodology.

Payload generators and persistence mechanisms

Attackers use payload-generation utilities (the Metasploit family includes msfvenom) to produce executables or scripts that "call home" and to wrap them so they survive reboot. Typical persistence places on Windows are Run keys, scheduled tasks, services, WMI subscriptions and startup folders; on Linux they are cron jobs, systemd units, shell profiles and SSH authorized_keys.

For a defender the plan is the same list reversed: inventory those locations (the Sysinternals Autoruns tool does this on Windows), alert on new entries, allow only signed and approved software to run, monitor for new services and scheduled tasks, and rebuild from a clean image if persistence is found. Persistence is only tested during authorized engagements and must be removed afterwards.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Why do attackers establish persistence?

    Persistence makes access survive restarts and partial cleanup, so defenders must find and remove every mechanism.
  2. 2. What does 'living off the land' mean?

    Built-in administration tools blend in with normal activity, so detection relies on context and behavior rather than on spotting a foreign program.
  3. 3. Which control most directly limits lateral movement?

    If systems cannot reach each other and one stolen password opens only one machine, spreading becomes slow and noisy.
  4. 4. What is the main value of MITRE ATT&CK for a defender?

    ATT&CK describes tactics and techniques so teams can check which behaviors they can detect and plan improvements.

Summary

  • Persistence keeps an attacker in; lateral movement spreads the compromise to more systems.
  • Both rely on changes and on legitimate credentials and tools, which means they leave logs.
  • MITRE ATT&CK catalogs adversary tactics and techniques and helps map detection coverage.
  • Valuable logs: authentication, process creation, startup and task changes, account changes, network and DNS, cloud and mailbox audit logs.
  • Sequences (many hosts quickly, new account after odd login) and baseline drift are effective detections; allow-lists tame false positives.
  • Prevent with segmentation, unique admin credentials, separate admin accounts, MFA and patching internal systems.
  • Test these behaviors only with explicit authorization, preferably in your own lab.

Next: Logging, Monitoring and SIEM Basics.