Phase 05.06 · Leave It As You Found It

Post-Engagement Cleanup

The engagement is not over when you get domain admin. It is over when the environment is handed back exactly as you found it. Every tool you uploaded, every account you created, every persistence mechanism you planted is a loose end — and a test that leaves those loose ends behind has not just done sloppy work, it has manufactured the very breach it was hired to prevent. Cleanup is part of the job. This lesson covers how to track what you touched, remove it completely, and hand back a clean environment without ever crossing the one line that separates a tester from a criminal.

00

The professional obligation

It is tempting to treat the moment you reach domain admin — or whatever the agreed objective was — as the finish line. It is not. Reaching the goal proves the attack path exists; the engagement is only finished when the environment has been returned to its original state. Everything you did to get in and move around left residue, and that residue is now your responsibility.

Think about what you actually leave behind during an engagement: payloads dropped on disk, post-exploitation tools staged in temp directories, accounts you created so you could come back, scheduled tasks and services planted for persistence, configuration files you edited to weaken a control. Each of those is a live weakness that did not exist before you arrived. A test that walks away leaving them in place is not a successful test — it is negligent, and it can become the exact breach it was meant to prevent. A real attacker who finds your forgotten backdoor account inherits all of your access for free.

Cleanup is the job, not an afterthought. The deliverable is not "we got in" — it is "we got in, we proved it, and we left the environment no weaker than we found it." Leaving tools or backdoors behind turns a security service into a liability. Plan and budget cleanup time the same way you plan the attack itself.
Lesson
05.06
Phase
Post-Exploitation
Built from
Your activity log
01

You can only remove what you tracked

Cleanup does not begin at the end of the engagement. It begins on the first day, with a discipline that has nothing to do with attacking: note-taking. You cannot reliably remove an artifact you have forgotten you created, and after days of pivoting through dozens of hosts, you will forget — unless you wrote it down at the moment you did it.

Keep a running activity log and update it as you work, not from memory afterward. Every time you change the state of a target, record it: the host, the timestamp, what you did, and — critically — how to undo it. That means logging every file you upload, every account you create, every service or scheduled task you add, every configuration you edit, and every key you plant. The log is the raw material for everything that follows.

The log is the cleanup checklist. When the engagement ends you do not try to remember what you touched — you turn the activity log into a checklist and walk it line by line. Good note-taking and complete cleanup are the same skill viewed from two ends. Skip the notes and you have no way to prove the environment is clean.
02

What to remove

Your activity log will be specific to the engagement, but the categories of artifact are predictable. Everything you introduced falls into one of a handful of buckets, and each bucket has a known place it lives and a known way to remove it. Walk every category below against your log — if you created it, it comes back out.

ArtifactWhere it livesRemove
Tools & payloadsTemp directories, user profiles, web roots, staging folders — uploaded binaries, scripts, and implants/beacons.Delete every dropped file and kill any running implant process. Verify nothing relaunches on reboot.
Created accountsLocal users, domain accounts, added group memberships — anything you created to gain or keep access.Delete the accounts and undo any group additions. Confirm no orphaned logins remain.
PersistenceRegistry Run keys, scheduled tasks, services, cron jobs, and entries added to ~/.ssh/authorized_keys.Remove each mechanism you planted and confirm it does not survive a restart.
Modified configsEdited config files, weakened policies, disabled defenses, firewall or registry tweaks.Restore the original value from your log or a backup — never leave a control loosened.
Test dataFiles, records, or markers you wrote to prove access or stage an action.Delete anything you authored. Leave the data you only read exactly as it was.

Notice the asymmetry: you remove what you added and restore what you changed, but you do not touch what was already there. The goal is a perfect rollback — the environment ends in the same state it started, no richer and no poorer for your having been in it.

03

Do not cover your tracks

Here is the single most important distinction in this entire lesson, and the one that defines what it means to be a professional rather than a criminal. A real attacker, having done their damage, deletes the logs — clears event records, wipes shell history, scrubs anything that proves they were there — because their goal is to remain unseen. A penetration tester does the exact opposite: you leave the logs intact.

This is not a small stylistic difference. It is the line that separates the two roles entirely. The defender's logs, alerts, and audit records are not your mess to clean — they are the output of the test. They are the evidence that the engagement happened. They are how the blue team measures what they actually detected and what slipped past. If you wipe them to "tidy up," you have destroyed the most valuable product of the whole exercise: an honest record of what the organization's defenses did and did not catch.

Two people, opposite instincts. The criminal erases the defender's record to hide. The tester preserves the defender's record to inform. Clean up your artifacts — your tools, your accounts, your persistence — relentlessly; never erase the defender's evidence. Tampering with logs does not just waste the engagement — it crosses an ethical line and can destroy the trust the whole profession runs on.

Keep the two ideas cleanly separated in your head. Cleanup means removing the artifacts you introduced. Covering tracks means erasing the traces of the activity itself. You do the first and you never do the second. When in doubt, ask: "Am I removing something I added, or am I hiding something I did?" The first is your duty; the second is the thing you were hired to expose in others.

04

Verify and hand back

Walking your activity-log checklist is not the same as proving it worked. Cleanup ends with verification: go back and confirm that each artifact is actually gone, not just that you ran the removal command. Check that deleted accounts no longer authenticate, that dropped files are absent, that scheduled tasks and services do not reappear after a reboot, and that every configuration you touched has been restored to its original value. An artifact you tried to remove but did not is more dangerous than one you forgot, because you have crossed it off the list.

Then hand the environment back deliberately. Deliver two things to the client: a clean environment, and a cleanup summary — a short record stating what you introduced, that you removed it, and the artifacts you intentionally left in place. Because remember, you did leave traces on purpose: the logs, the alerts, the detections. Those are not loose ends — they are precisely the material the defenders now study.

Your traces are the defender's starting point. The logs and alerts you deliberately preserved are exactly what incident response and host forensics analyze to reconstruct what happened. The artifacts you leave on purpose feed directly into the work covered in Host Forensics — the defensive mirror image of everything you did in this phase.

That completes the Post-Exploitation phase. You have learned to escalate, move laterally, establish persistence, harvest credentials and evidence of impact, and — just as importantly — to dismantle all of it and leave cleanly. Next, the track turns outward to the most exposed surface most organizations own: the Web & Database Attacks phase, where the target is the application and the data behind it.