Skip to content
Tutorials Center
My learning

Topics

Lesson 5 of 53 ยท Foundations and Ethics

The Penetration Testing Process

Walk through the penetration testing process from pre-engagement to reporting and retest, compare black, grey and white box tests, and tell pentests from red teams.

A penetration test is not a random hunt for clever tricks. It is a structured project with a beginning, a method and an end product: a report that helps the client become safer. Professional frameworks such as the Penetration Testing Execution Standard (PTES), the OWASP Web Security Testing Guide and NIST's SP 800-115 all describe similar phases. Names vary, but the shape is the same, and learning it keeps you organized, safe and useful.

This lesson walks through the phases, explains the "box" types, separates a pentest from a red team engagement, and ends with a small program that tracks phases and findings the way a real test log does. Real tools mentioned here are read-only; you will meet them in your own lab later.

The life of a test

Pre-engagement Scope, contract, rules.
Recon Learn about the target.
Discovery Find hosts, services, weak spots.
Validation Prove which flaws are real.
1 / 2

Phase 1: Pre-engagement

Everything in Law, Scope and Rules of Engagement happens here. You and the client agree the objectives ("assess our customer portal"), scope, schedule, methods, emergency contacts, how sensitive data is handled, and how results are delivered. A good kickoff also asks about fragile systems (an old controller that crashes when scanned), business events (a product launch week) and success criteria. The signed documents exist before the first packet is sent.

Phase 2: Reconnaissance

Reconnaissance (recon) collects information about the target. Passive recon uses public sources and never touches the target (see Passive Reconnaissance and OSINT). Active recon sends traffic to the target to learn more, such as resolving names or probing hosts, and so must stay inside scope. Recon answers questions like: which domains and IP ranges exist, which technologies are used, who works there, and what do public sources reveal that should not be public?

Phase 3: Scanning and enumeration

Now you map what is reachable: live hosts, open ports, service versions, web paths, user-visible functions. The chapter Reconnaissance and Scanning covers this with a model. In professional work, scanning is carefully rate-limited because aggressive probing can disrupt weak systems, and the output is the raw material for the next step, not a result in itself.

Phase 4: Vulnerability analysis and validation

Automated scanners guess based on versions and patterns, and they produce false positives. This phase decides which findings are real. You review each candidate, test it safely and gather evidence, and discard noise (see Vulnerability Scanning and Triage).

When the engagement allows, validation means exploitation: carefully demonstrating that a weakness can really be used. The professional goal is the minimum proof needed to show impact: reading a harmless test record, not downloading a customer database. Destructive actions, data theft and denial of service are avoided unless the rules of engagement explicitly require them and a rollback plan exists.

Phase 5: Post-exploitation (when in scope)

If a foothold was achieved, testers ask what an attacker could do next: reach other systems, escalate privileges, access sensitive data. This tells the client the business impact of the flaw and whether segmentation, monitoring and credential hygiene work. Many tests deliberately stop earlier ("prove the flaw, do not pivot"). When post-exploitation is allowed, everything created during the test (accounts, files, tools) is recorded so it can be cleaned up completely at the end.

Phase 6: Reporting and debrief

The report is what the client pays for. It contains an executive summary for managers, a technical section with findings (title, severity, affected systems, evidence, reproduction steps, remediation) and appendices. Critical issues are reported immediately, not held for the final document. After delivery, a debrief meeting lets developers ask questions. Writing a Penetration Test Report covers this in depth.

Phase 7: Remediation and retest

Findings only matter if they are fixed. After the client remediates, the tester retests each item and marks it fixed, partially fixed or still open. Retesting is often the cheapest and most valuable part of the project, because it closes the loop.

flowchart LR
    A["Pre-engagement"] --> B["Recon"]
    B --> C["Scanning and<br/>enumeration"]
    C --> D["Analysis and<br/>validation"]
    D --> E["Post-exploitation<br/>(if in scope)"]
    E --> F["Report and<br/>debrief"]
    F --> G["Remediate<br/>and retest"]
    D -.new information.-> B

The flow is a loop in practice: what you find in later phases sends you back to recon.

Black, grey and white box

How much the tester knows at the start changes the test:

Type Starting knowledge Strength Weakness
Black box Almost nothing, like an outside attacker Realistic view from outside Slow; may miss deep flaws
Grey box Some, such as a normal user account or an architecture diagram Good balance of realism and depth Needs some preparation
White box Full: source code, configs, diagrams, admin access Finds the most issues per day Less like a real attacker's view

Many clients choose grey box because real attackers can often get a user account (by phishing or buying credentials), so starting with one is realistic and saves paid hours that would otherwise be spent on a login screen.

Pentest, vulnerability assessment and red team

These words are often confused:

  • A vulnerability assessment runs scanners and reviews results to list weaknesses. It is broad and shallow, and it does not usually prove exploitability.
  • A penetration test adds human skill to validate and chain weaknesses within a defined scope, often with defenders aware of the work.
  • A red team engagement is goal-based ("reach the payroll database"), stealthy, long, usually limited to a few people knowing, and it tests the detection and response of the blue team as much as the technology. It trades breadth for realism.

Choose by question: "what is broken?" is an assessment; "how bad could a breach get through these systems?" is a pentest; "would we notice and stop a real attacker?" is a red team.

Stand-in: tracking phases and findings

Testers keep a running log of what has been done, what was found and what remains. This model enforces a simple rule, that phases are completed in order and a report cannot start while a phase is open, and builds a findings table sorted by severity. It models bookkeeping, not testing.

JS Engagement tracker

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The first call fails on purpose: the guard shows how a checklist keeps a team honest. Real trackers also record timestamps, the exact commands run and the evidence file for each finding, because a client may ask "when did you scan that server?" after an unexplained outage.

Stand-in: reporting severity counts

Executive summaries lead with numbers. This second model turns the findings list into the counts managers read first, plus a sentence generated from them.

JS From findings to an executive line

Press Run (or Ctrl + Enter) to see the console output here.

No output.

The five phases of hacking, including covering tracks

Many textbooks and certification courses describe an attacker's work in five phases. The seven-phase engagement above is a testing process with legal and reporting steps added; the five phases are the attacker's activity model. Knowing both lets you map a test to the language used in other courses and in incident reports.

  1. Reconnaissance. Collect information about the target. Passive recon uses public sources (Passive Reconnaissance); active recon touches the target. Typical tools: WHOIS and DNS lookups, search-engine queries, internet-wide device search.
  2. Scanning and enumeration. Find live hosts, open ports, services, versions and accounts (Port Scanning, Service Enumeration). Typical tools: Nmap, vulnerability scanners, content discovery tools.
  3. Gaining access. Use a weakness to get in: a vulnerable service, a stolen password, a phished user. In an authorized test this is the validation step, done carefully (Metasploit, web testing proxies).
  4. Maintaining access. Make the foothold survive reboots and password changes (Persistence and Lateral Movement). Testers usually demonstrate only what the scope allows and remove everything afterwards.
  5. Covering tracks. Attackers try to hide: deleting or editing logs, clearing shell history, timestamp tampering, using legitimate tools, disabling monitoring and removing dropped files.

In an authorized test, phase 5 is mostly not performed. Tampering with a client's logs destroys the evidence the defenders need, and a tester should never leave a system less auditable than they found it. What testers do is record exactly what they touched so the client can tell test activity from real attacks, and sometimes check (with permission) whether the monitoring would have noticed the attempts.

How log tampering is detected

Because covering tracks is an attack on evidence, defenders design logging so that tampering is hard or visible:

  • Ship logs off the machine in near real time to a central, access-controlled system, so deleting the local copy is too late.
  • Make logs append-only or immutable and protect them with different credentials from the systems that produce them.
  • Alert on the act of tampering itself: a log service stopped, an audit policy changed, a log cleared (operating systems record a specific event when this happens), or a sudden gap in an otherwise steady stream.
  • Verify integrity with hashes or signed log chains.
  • Keep time in sync, so gaps and out-of-order entries stand out.

The stand-in finds gaps and clearing events in an invented log stream, the same checks a monitoring rule performs.

Node.js Detect gaps and clearing in a log stream

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.

The most valuable part of the output is the sequence: failed logins, a success, a policy change and then a cleared log is a story. The incident response lesson shows how to preserve and read it.

Tools by phase, in one table

Phase What happens Examples of tool classes
Reconnaissance collect public information WHOIS, DNS tools, theHarvester, Maltego
Scanning find live hosts, ports, vulnerabilities Nmap, Netdiscover (ARP host discovery on a local network), Nessus
Gaining access prove a flaw can be used Metasploit, Hydra (online password-guessing test, used with permission and lockout awareness), web proxies
Maintaining access show persistence is possible implants, scheduled tasks
Covering tracks what a real attacker would erase log cleaners, timestamp changes

In an authorized test the last phase is mostly a reporting topic: you document which traces an attacker could erase and recommend defenses such as sending logs to a remote append-only store, file-integrity monitoring and alerting when a log is cleared (Windows event 1102 or 104). Backdoor concealment, log-clearing modules and cleaner scripts exist, which is precisely why local logs alone are never trustworthy evidence.

Check your understanding

Quick check ยท 4 questions

of 4 answered You scored / 4 ยท perfect!

  1. 1. Which phase produces the document the client actually keeps and acts on?

    The report, with evidence and remediation advice, is the deliverable. Everything else exists to make it accurate.
  2. 2. Which test type starts with a normal user account and an architecture diagram?

    Grey box gives partial knowledge, which is realistic (attackers can often get accounts) and saves time.
  3. 3. What is the main difference between a pentest and a red team engagement?

    Pentests are broad and time-boxed to find many weaknesses. Red teams pursue a goal and measure whether defenders notice.
  4. 4. Why do testers retest after remediation?

    A finding is only resolved when the fix is verified. Retests catch partial or ineffective fixes.

Summary

  • A pentest is a structured project: pre-engagement, recon, scanning, validation, optional post-exploitation, reporting and retest.
  • Recon can be passive (no contact) or active (inside scope only); scanners need human validation.
  • Prove impact with minimal, non-destructive evidence and clean up everything you create.
  • Black, grey and white box describe starting knowledge, and grey box is a common compromise.
  • Vulnerability assessments list issues, pentests validate and chain them, red teams test detection toward a goal.
  • Reporting and retesting turn findings into real risk reduction.

Next: Building a Safe Home Lab.