TExcelTAD
Home › Ethical Hacking & Penetration Testing Methodology › Evidence Collection and Cleanup

Evidence Collection and Cleanup

Two things outlive every engagement: the evidence that supports the report, and the traces the testers left on the client's systems. Evidence that can't be trusted (unclear origin, edited, full of secrets) weakens every finding; traces that nobody removes (a test account, an uploaded file, a scheduled task) become exactly the weaknesses the next attacker uses. This lesson treats both as engineering problems: collect evidence with timestamps and integrity, redact it before it travels, and keep an artefact log so that cleanup is a checklist, not a memory exercise.

Evidence that holds up

Good evidence for a finding is:

  • attributable: which tester, from which source address, against which target, with which tool and command;
  • timestamped in UTC, so it can be matched with the client's logs;
  • minimal: enough to prove the finding and nothing more (data minimisation);
  • redacted before it leaves the evidence store: session tokens, passwords, personal data and card numbers masked;
  • integrity-protected: a hash manifest made when the evidence is collected, so later edits are visible;
  • stored encrypted in the engagement's evidence store, with access limited to the team, and deleted on the agreed date.

This is lighter than forensic chain of custody (the subject of Malware Analysis, Digital Forensics & Incident Response), but it borrows the same ideas: record who handled what, when, and prove it wasn't changed.

Redact, hash, verify

The session below prepares evidence for two findings: an HTTP response that leaked another customer's invoice, and the share listing from the SMB lesson. It redacts the session cookie, the e-mail address and the card number (a standard test card number), checks that no long tokens or card-like numbers remain, writes a SHA-256 manifest, and shows that a later change is detected. Everything is lab data in your sandbox.

bash · try it yourself
mkdir -p evidence/F-03 evidence/F-06
cat > evidence/F-03/response.txt <<'T'
2026-12-03T10:42:07Z GET /api/invoices/1002 (token of test user lab-a)
HTTP/1.1 200 OK
Set-Cookie: session=9f2c4e1ab7d3405e8c11f00d2b6a77e1; Secure; HttpOnly
{"id": 1002, "customer": "Lab B", "email": "lab.b@lab.test", "card": "4111111111111111", "total": 42.50}
T
cat > evidence/F-06/listing.txt <<'T'
2026-12-02T10:14:00Z \\files01.lab.test\Scans listed as lab\pt-user: 214 files, not opened
T
redact() {
  sed -E -e 's/(session=)[0-9a-f]{8,}/\1<REDACTED>/g' \
         -e 's/"email": "([a-z])[^@"]*@/"email": "\1***@/g' \
         -e 's/[0-9]{12}([0-9]{4})/************\1/g' "$1"
}
for f in evidence/*/*.txt; do redact "$f" > "$f.red" && mv "$f.red" "$f"; done
cat evidence/F-03/response.txt
grep -rElq '[0-9a-f]{32}|[0-9]{16}' evidence && echo 'secrets left!' || echo 'secrets left: none'
(cd evidence && find . -type f | sort | xargs sha256sum) > MANIFEST.sha256
cut -c1-16,65- MANIFEST.sha256
echo "== later: is the evidence unchanged?"
(cd evidence && sha256sum -c --quiet ../MANIFEST.sha256) && echo "manifest OK"
echo "tampered" >> evidence/F-06/listing.txt
(cd evidence && sha256sum -c --quiet ../MANIFEST.sha256 2>&1) || true
2026-12-03T10:42:07Z GET /api/invoices/1002 (token of test user lab-a)
HTTP/1.1 200 OK
Set-Cookie: session=<REDACTED>; Secure; HttpOnly
{"id": 1002, "customer": "Lab B", "email": "l***@lab.test", "card": "************1111", "total": 42.50}
secrets left: none
3a3073e1fafb875f  ./F-03/response.txt
4da14faad77eea7e  ./F-06/listing.txt
== later: is the evidence unchanged?
manifest OK
./F-06/listing.txt: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

The response still proves the finding (test user lab-a received invoice 1002 belonging to someone else) without containing a usable session token, a full e-mail address or a card number. The manifest catches the one-line change to the listing: if a finding is ever disputed, the hashes show that the evidence is what was collected on the day. In practice the manifest itself is signed or stored separately (in the ticket, or e-mailed to the client lead at the end of each day).

Tracking artefacts for cleanup

Every action that leaves something on a client system goes into an artefact log at the moment it happens: uploaded files, created accounts, changed settings (only if the RoE allowed them), marker files, tools started. At the end, each entry needs a cleanup confirmation, by the tester or by the client's administrator. The log below is synthetic; the check prints what is still open.

python · try it yourself
artefacts = [  # (id, host, what, created UTC, cleanup by)
    ("A-1", "www",     "uploaded test file /var/www/uploads/pt-check-7f3a.txt (upload finding)", "12-03 10:05", "tester"),
    ("A-2", "shop",    "test accounts lab-a, lab-b (provided by client)",                          "12-01 08:00", "client"),
    ("A-3", "jenkins", "loaded console page only, nothing created",                              "12-03 14:20", "none"),
    ("A-4", "files01", "marker file read C:\\pentest\\flag.txt (placed by client)",               "12-02 09:00", "client"),
    ("A-5", "www",     "temporary SSH key for the agreed assumed-breach start point",           "12-01 08:30", "client"),
]
confirmed = {"A-1": ("12-05 16:10", "tester, file deleted, listing checked"),
             "A-4": ("12-06 09:00", "client admin")}

open_items = []
for aid, host, what, created, owner in artefacts:
    if owner == "none":
        status = "nothing to clean"
    elif aid in confirmed:
        when, who = confirmed[aid]
        status = f"cleaned {when} ({who})"
    else:
        status = f"OPEN, owner: {owner}"
        open_items.append(aid)
    print(f"{aid} {host:<8} {status:<45} {what}")
print()
print("cleanup complete" if not open_items else f"report cannot be finalised: open artefacts {', '.join(open_items)}")
A-1 www      cleaned 12-05 16:10 (tester, file deleted, listing checked) uploaded test file /var/www/uploads/pt-check-7f3a.txt (upload finding)
A-2 shop     OPEN, owner: client                           test accounts lab-a, lab-b (provided by client)
A-3 jenkins  nothing to clean                              loaded console page only, nothing created
A-4 files01  cleaned 12-06 09:00 (client admin)            marker file read C:\pentest\flag.txt (placed by client)
A-5 www      OPEN, owner: client                           temporary SSH key for the agreed assumed-breach start point

report cannot be finalised: open artefacts A-2, A-5

Two artefacts are still open. The client provided both the test accounts and the SSH key used as the assumed-breach starting point, so the client must remove them, and the final report lists them in a "cleanup" section with the open status until they are confirmed. A forgotten test account with a known password is one of the most common findings of the next year's test.

Cleanup and data deletion at the end

  • On the client's systems: remove everything in the artefact log that the testers own; hand the client a list of what they own (accounts, keys, firewall exceptions for the testers' addresses); confirm in writing.
  • Tooling: stop listeners, sessions and scans; check that nothing is still running from the testers' hosts.
  • Evidence: after the agreed retention period (often 30 to 90 days after the final report, or after the retest), delete the evidence store and send the client a deletion confirmation. Keep only what the contract allows (usually the report itself).

How missing cleanup is detected

The client's own checks find leftovers: accounts with "test" or "pentest" in the name that are still enabled, files in upload directories with tester-style names, firewall rules for the testers' addresses months later. The retest is a natural point to check the cleanup section too.

How it is prevented

Artefact log entries written at the time (not reconstructed from memory), a cleanup section in the report template that can't be closed while items are open, firewall exceptions and test accounts created with an expiry date from the start, and evidence stores with automatic deletion dates.

Pitfalls

  • Unredacted evidence in e-mail. Reports and evidence are forwarded widely; redact before anything leaves the store.
  • Screenshots with more than intended: other browser tabs, notifications, the tester's own credentials.
  • "Nothing to clean" without saying so. Record it explicitly (A-3), so nobody wonders later.
  • Deleting evidence before the retest. Keep it until the retest is done, then delete as agreed.

Practice

  1. Add a rule to redact() that masks Authorization: Bearer <token> headers. Test it on a line of your own.
  2. The client asks you to keep all evidence "forever, just in case". What do you answer?
Answers
  1. Add -e 's/(Authorization: Bearer )[A-Za-z0-9._-]+/\1<REDACTED>/g' to the sed command; echo 'Authorization: Bearer eyJhbGciOi.x.y' | redact /dev/stdin should print Authorization: Bearer <REDACTED>.
  2. That keeping personal data and security-sensitive material without a purpose increases the risk for both parties and may conflict with data-protection law; propose keeping the final report (which contains only redacted evidence) and deleting raw evidence after the retest, as the contract says, with a written confirmation.

Test yourself

Why make a hash manifest of the evidence when it is collected?

  1. To compress it
  2. So any later change is detectable and the evidence can be shown to be what was collected
  3. To encrypt it
  4. Because scanners require it

What should an HTTP response in a finding's evidence NOT contain?

  1. The status line
  2. A usable session token, full personal data or card numbers
  3. The timestamp
  4. The request path

When can the report's cleanup section be closed?

  1. When the testers leave
  2. When every artefact in the log has a cleanup confirmation or is marked 'nothing to clean'
  3. Never
  4. After the invoice is paid

Which leftover from a penetration test is a classic finding in the next year's test?

  1. A PDF report
  2. A test account with a known password that was never disabled
  3. A closed firewall port
  4. A deleted log