Practice library / Penetration testing, first steps
Workbook · Easy · 3 hours
Introduction to Penetration Testing
What pentesting is, legal context, scope, phases, and methodology.
On this page 5 sections
Before you start
Penetration testing proves which weaknesses in a live system a real attacker could abuse. The craft rests on written authorisation, careful scope, a repeatable method and a report that a developer can act on. This workbook explains the shape of an engagement from first contact to retest, so each tool you later learn fits into a known place. The chapters cover black, grey and white box tests, the rules of engagement, and the six phases from reconnaissance through reporting. They also show why a vulnerability scan, a pentest and a red team solve different problems. Read it before you open any tool, because the paperwork and the plan decide whether the technical work is a profession or a crime. The companion lab Nmap Scanning is a good first active exercise once the plan is in place.
What You'll Learn
- Define penetration testing and say how it differs from a vulnerability scan and a red team
- Choose between black box, grey box and white box, and between internal and external tests
- Explain why written authorisation is the line between a test and a crime
- Write a scope statement and the rules of engagement for a test
- Name the phases of an engagement and the output of each phase
- Write a finding that a developer can fix and a manager can rank
About This Workbook
A penetration test (pentest) is an authorised, planned attempt to break into a system, to find the weaknesses before a real attacker does. The key word is authorised. The technique can be the same as a criminal's. The permission, the plan and the report are what make it a profession.
This workbook teaches the process and not the tools. You learn what the work is, which rules protect you and your client, how an engagement flows, and how you report. You practise the tools in the labs. A good first lab is Nmap Scanning. For the same material in more depth, read The Penetration Testing Process and Pre-Engagement & Setting Up after this one.
Throughout the workbook, the client is the organisation that pays for the test. The tester is you. The target is the system in scope. All examples use private addresses (10.0.0.0/8), example.com and the made-up company Example Corp.
Run every technique in this course only on systems that you own, on a lab VM that you control, or on a public practice target (for example DVWA, Metasploitable, hack.me or HackMyVM). Never run it against a third party without written permission.
Chapter 1 — What Is a Pentest?
Objectives
- Define a penetration test, a vulnerability assessment and a red-team exercise
- Name the goals of a test and the output the client receives
- Choose black, grey or white box for a given need
- Explain the difference between an internal and an external test
Explanation
What a pentest is. A pentest answers one question: "If a motivated attacker tried this, how far could they get?" A tester finds weaknesses, then proves that they matter by using them in a safe and agreed way. The proof is what separates a pentest from a list of possible problems.
What a pentest is not. Three nearby activities have different goals.
| Activity | Question | Depth | Typical length |
|---|---|---|---|
| Vulnerability scan | Which known weaknesses exist? | Wide, automatic, no proof | Hours |
| Penetration test | Which weaknesses can be used, and what do they give? | Deep, manual, with proof | 1 to 3 weeks |
| Red-team exercise | Can the defenders detect and stop a real attack? | Goal-based, stealthy, tests people and process | Weeks to months |
A scan is the cheapest and runs often. A pentest adds a human who thinks, joins small weaknesses together and says what the result means for the business. A red team goes further: only a few people at the client know about it, and the test measures the defenders, not only the systems.
Why organisations pay for it.
- To find weaknesses that scanners cannot find, such as a broken business rule or a chain of three small mistakes.
- To meet a rule or a contract. Standards such as PCI DSS require regular testing.
- To rank work. A tester can show that one "medium" finding is the real way to the database.
- To test the defenders: did anyone see the test?
Goals. A good test has a goal that the client can state in one sentence: "Show whether an outsider can read customer records," or "Show whether a stolen laptop gives access to the domain." Without a goal, the test finds a long list of small items and nobody knows if the result is good or bad.
Box types. The box says how much the tester knows at the start.
| Type | Tester starts with | Good for | Weak point |
|---|---|---|---|
| Black box | Only the company name or a domain | Seeing what an outsider sees | Time goes on discovery; deep flaws stay hidden |
| Grey box | Some knowledge: a normal user account, a network diagram | Most tests; best value for the time | Needs the client to prepare accounts |
| White box | Full access: source code, configuration, admin view | Finding the most flaws in the least time | Less like a real outsider |
Position. External testing starts from the internet and checks what a stranger can reach: web sites, mail, VPN, exposed services. Internal testing starts inside the network, for example from a plugged-in laptop or a normal staff account. It answers "what if an attacker is already in?" or "what can a bad insider do?" Most real intrusions need both views, because the attacker enters from outside and then moves inside.
Target types. The scope can be a network, a web application, a mobile app, a wireless network, a cloud account, or people (social engineering). Each type needs different skills. Say clearly which type the test covers.
Worked example
Example Corp runs an online shop. Three people ask for a test with three different needs.
| Request | Right choice | Reason |
|---|---|---|
| The CEO: "Can someone from the internet steal our customer list?" | External, black box on the shop domain | The question is about an outsider with no knowledge |
| The developer lead: "We ship a new checkout next week." | Web application, grey box with two test user accounts | Testers need to log in to test what a customer can do to another customer |
| The auditor: "Prove that staff laptops cannot reach the payment network." | Internal, grey box from a staff VLAN | The question is about what is reachable from inside |
The three tests use the same skills. They differ in start point, scope and report.
Practice questions
- Your client wants a list of all missing patches on 5,000 servers by Friday. Which activity fits, a scan or a pentest?
- A client says: "We want a pentest, but do not tell the security team." Which activity does the client really describe?
- Why can grey box give a better result than black box in a one-week test?
- Give one question that only an internal test can answer.
Answers
- A vulnerability scan. It is wide, fast and automatic. A manual pentest of 5,000 servers in a week is not possible.
- A red-team exercise (or at least a test of detection). The goal is to see if the defenders notice, so few people may know.
- In a short test, a black-box tester spends days on discovery. With a user account the tester goes straight to the logic where the real flaws are.
- For example: "If one workstation is infected, can the attacker reach the domain controller?" An outside view cannot see the internal network.
Chapter 2 — Rules of Engagement
Objectives
- Explain why written authorisation is required
- Name the legal risks and the documents that reduce them
- Write a scope statement with "in" and "out" items
- List the rules of engagement and the emergency contacts
Explanation
Authorisation is the line. Accessing a computer system without permission is a crime in almost every country. Examples are the Computer Fraud and Abuse Act in the United States, the Computer Misuse Act in the United Kingdom, and Article 6 (and related articles) of the Budapest Convention that many countries follow. A good intention does not remove the offence. Only valid permission does. You must have it in writing, before the first packet is sent.
This workbook is not legal advice. Laws differ by country and by contract. A professional tester reads the local law and asks a lawyer when a case is unclear.
The signer must own the target. The person who signs must have the authority over the systems. This is easy to miss in two cases:
- Cloud and hosting. The client owns the account, but the provider owns the hardware. Read the provider's testing policy first. Many providers allow tests on your own resources without a request, with limits (for example, no denial-of-service).
- Third parties. A payment provider, a CDN or a software-as-a-service tool that the client uses is not the client's system. The client cannot give you permission for it. Mark it out of scope.
The documents. A standard engagement has four documents.
| Document | What it says |
|---|---|
| NDA (non-disclosure agreement) | You keep everything that you see secret |
| Contract or statement of work (SOW) | What is delivered, when, at what price, and who is liable |
| Authorisation letter | A signed permission for named testers to test named targets in a named period. You carry it as proof of permission |
| Rules of engagement (ROE) | How the test is done: limits, times, contacts |
Scope. The scope says what you may test. It has an "in" list and an "out" list. Write exact items, not general words. "The network" is not a scope. "The range 10.20.0.0/24" is.
Rules of engagement (ROE). The ROE answers the practical questions before they become incidents.
- Time window. When may you test? Can you scan during business hours, or only at night?
- Allowed methods. Are exploits allowed? Password guessing? Social engineering? Denial of service is nearly always forbidden.
- Limits. Maximum scan speed. No data copied out of the network (or only a small proof). No changes to real production data.
- Data handling. Where you store results, how long, and how you delete them. Personal data of customers must stay inside the client's control.
- Contacts. A named person at the client who is reachable 24 hours, and a stop word.
- Notification. Who at the client knows about the test? Who must not know?
Communication during the test. Agree two rules. First: if you find something critical (for example, a server that is already compromised by someone else, or customer data open on the internet), you stop and call the contact at once. You do not wait for the report. Second: if the client sees damage, the client can say the stop word and you stop right away.
Worked example
Example Corp hires a tester to check its online shop. This is the scope and ROE page of the SOW.
ENGAGEMENT: Example Corp shop, external grey-box test
Authorised by: A. Client, CTO (owner of all systems below)
Testers: tester-1, tester-2 Period: 2026-12-01 to 2026-12-12
IN SCOPE
shop.example.com (web application, 2 test accounts supplied)
api.example.com (REST API, same accounts)
203.0.113.0/28 (shop web servers; documentation range used here)
OUT OF SCOPE
pay.example-psp.net (payment provider: third party)
mail.example.com (mail service)
Any social engineering, any denial of service
RULES
Hours: 08:00-20:00 UTC on weekdays. Max 50 requests/second.
No real customer data to leave the network; screenshots with data masked.
Stop and call +00 000 000 000 (24 h) on any critical finding.
Stop word: "RED". Say it and all testing stops within one minute.Look at what the page does. It names who gave permission, it lists exact targets, it states limits as numbers, and it gives a way to stop. If a question comes later ("Why did you test the mail server?"), the answer is on the page.
What to do when the scan finds something outside the scope. Suppose a port scan of an in-scope range shows an unexpected host at 203.0.113.25, which is not on the list. You do not test it. You write it down and ask the client.
nmap -sn 203.0.113.0/28Starting Nmap 7.94 ( https://nmap.org ) at 2026-12-01 09:12 UTC
Nmap scan report for 203.0.113.3
Host is up (0.012s latency).
Nmap scan report for 203.0.113.5
Host is up (0.011s latency).
Nmap done: 16 IP addresses (2 hosts up) in 1.84 secondsBoth hosts are inside the signed range, so the tester continues. A host outside 203.0.113.0/28 would stay untouched until the client confirms in writing that it is in scope.
Practice questions
- A friend says, "Test my company's website, I am sure my boss will not mind." Do you have authorisation?
- A client's web shop uses a hosted payment page at a provider. The client says: "Test everything, including the payment page." What do you do?
- Name three items that belong in the rules of engagement.
- During the test you find an unknown web shell on the server, left by someone else. What do you do?
Answers
- No. A friend is not the authority, and "I am sure" is not a signature. You need written permission from a person who has authority over the systems.
- Do not test the payment page. It belongs to a third party, and the client cannot give permission for it. Mark it out of scope, or ask the provider for its own written permission.
- Any three of: the time window, the allowed methods, rate limits, data handling, emergency contacts, the stop word, who is notified.
- Stop and call the emergency contact at once. A web shell means that a real attacker may already be inside. The client must start incident response, and you keep your notes as evidence.
Chapter 3 — The Lifecycle
Objectives
- Name the phases of an engagement and the output of each
- Keep evidence in a way that another person can repeat
- Write a finding with impact, proof and a fix
- Explain the purpose of a retest
Explanation
Frameworks such as PTES (Penetration Testing Execution Standard), the NIST SP 800-115 guide and OSSTMM use different words, but the flow is the same. This workbook uses six phases.
| # | Phase | Question | Output |
|---|---|---|---|
| 1 | Pre-engagement | What, why, and may I? | Signed scope, ROE, schedule |
| 2 | Reconnaissance | What is there? | List of hosts, services, people, technologies |
| 3 | Enumeration and analysis | Which weaknesses exist? | List of candidate weaknesses, ranked |
| 4 | Exploitation | Which weaknesses can I use, safely? | Proof for each one (a screenshot, a file name, a command output) |
| 5 | Post-exploitation | What can I reach from here? | The real impact; evidence of access; clean-up list |
| 6 | Reporting and retest | What must the client do? | Report, briefing, retest result |
Reconnaissance. You collect facts. Passive recon uses public sources and does not touch the target: search engines, certificate logs, DNS records. Active recon sends traffic to the target, for example a port scan, and therefore must be inside the scope and the time window. See OSINT Reconnaissance for the passive side.
Enumeration. You turn the list of live hosts into a list of services, versions and weaknesses. You find what runs on each port, which software version it is, and which settings are weak.
Exploitation. You use a weakness to prove that it is real. Use the least force that proves the point. To show that a login can be bypassed, log in and take a screenshot of the admin page. Do not delete data, and do not keep access longer than you need.
Post-exploitation. Here you answer the question of impact. If you control a web server, can you reach the database? Can you reach other networks? The answer to this question sets the severity of the finding. Everything that you create (accounts, files, tools) goes on a clean-up list, and you remove it at the end.
Evidence handling. Take notes while you work, not afterwards. For each action write the time (in UTC), the target, the command and the result. Your notes must be good enough that another tester can repeat your steps and get the same result.
mkdir -p ~/engagement/example-shop/{scans,notes,evidence}
script -a ~/engagement/example-shop/notes/session-$(date +%F).logScript started, output log file is '/home/tester/engagement/example-shop/notes/session-2026-12-01.log'.The script command records everything that you type and see until you enter exit. Store the notes, the scans and the evidence in separate folders, as above. Keep client data encrypted, and delete it at the end as the ROE says.
For scans, save the raw output with a name that includes the date. -oA writes all three Nmap formats at once.
nmap -sV -oA ~/engagement/example-shop/scans/shop-2026-12-01 203.0.113.0/28
ls ~/engagement/example-shop/scans/shop-2026-12-01.gnmap shop-2026-12-01.nmap shop-2026-12-01.xmlReporting. The report is the product. A client does not buy "access". A client buys the knowledge of what to fix. A good report has these parts:
- Executive summary (one page, no jargon): what was done, what the overall risk is, the three most important actions.
- Scope and method: what was tested, when, and how, so the client can see what was not tested.
- Findings: one section for each weakness (below).
- Appendices: raw output, a list of tools, the clean-up list.
A finding. Each finding has the same fields.
| Field | Content |
|---|---|
| Title | A short, exact name: "Admin login accepts the default password" |
| Severity | Critical, High, Medium, Low or Info, with the reason. CVSS can give the number, but the business impact decides |
| Affected | The exact host, URL or file |
| Description | What is wrong, in two or three sentences |
| Evidence | The steps to repeat it, and a screenshot or output |
| Impact | What an attacker gets, in business terms |
| Recommendation | The specific fix, and a second option if the first one is hard |
Retest. After the client fixes the findings, the tester checks again. The retest turns "we think it is fixed" into "it is fixed". A finding gets one of three states: fixed, partly fixed or not fixed. Plan the retest in the contract, because it needs time and the original evidence.
Worked example
This is one finding from the Example Corp test. It shows the level of detail that a developer needs.
FINDING 03: Order API exposes other customers' orders (IDOR)
Severity: High (customer data; needs only a normal account)
Affected: GET https://api.example.com/v1/orders/{id}
Description
The API returns an order when the order id is valid. It does not check that the
order belongs to the logged-in user.
Evidence (2026-12-03 10:41 UTC, account test-user-1)
$ curl -s -H "Authorization: Bearer $TOKEN1" https://api.example.com/v1/orders/1001
{"id":1001,"owner":"test-user-1","total":"42.00"}
$ curl -s -H "Authorization: Bearer $TOKEN1" https://api.example.com/v1/orders/1002
{"id":1002,"owner":"test-user-2","total":"87.50"} <-- owned by another account
Impact
Any customer can read all orders by counting ids: names, addresses and totals.
Recommendation
Check the owner on every request on the server side. Use random ids as a second layer.
Add an automated test that requests an order of another user and expects 403.The finding names the exact URL, shows the requests that prove it, uses test accounts that the client created, and gives a fix that the developer can do on the same day. It does not include a real customer's data. It also says why the finding is High and not Critical: the attacker needs an account.
After the fix, the retest repeats the same two requests. If the second returns 403 Forbidden, the finding is marked fixed in the report.
Practice questions
- In which phase do you send the first packet to the target, and what must be true before it?
- What is the difference between passive and active reconnaissance?
- Why do you remove every account and file that you created, and where do you record them?
- A report says: "The server is vulnerable. Please patch." Name two things that are missing.
- Why does a report include a list of what was not tested?
Answers
- Active reconnaissance (phase 2). Before it, the scope and the authorisation must be signed, and the target must be in scope and inside the time window.
- Passive recon uses public sources and never touches the target (search engines, certificate logs). Active recon sends traffic to the target (for example a port scan), so it needs authorisation.
- Left-over accounts and files are a new weakness that you caused, and a real attacker can use them. Record them on the clean-up list as you create them, and give the list to the client.
- For example: which server and which vulnerability, the evidence, the impact, the severity, and the exact version or fix to apply.
- A "clean" report can give a false sense of security. The client must know the limits of the test: what was out of scope, what time was available and which methods were not allowed.
Final Exercise — Plan a Test on Paper
Use what you learned. Write the plan on paper. Do not touch any system.
- Choose a fictional company with one web shop, one office network and one cloud account. Write its name.
- Write the goal of the test as one sentence.
- Choose black, grey or white box, and internal or external. Write one reason.
- Write a scope with at least three "in" items and two "out" items. Use exact ranges and names.
- Write five rules of engagement, each with a number or a name (time, rate, contact, stop word, data rule).
- List the six phases and, for each one, the one thing that you hand over at the end.
- Write one finding in the format of Chapter 3, using an invented weakness.
What a good answer contains
The goal is a single sentence that a manager understands. The scope lists exact items (for example shop.example.com, 10.20.0.0/24) and names third parties as out of scope. The rules have numbers: hours, requests per second, a phone number, a stop word. The finding has all seven fields, and the fix is specific.
Keep going. Next read The Penetration Testing Process and Pre-Engagement & Setting Up. Then practise the first active phase in the lab Nmap Scanning, on your own lab VM only.
Sign in to track progress and send feedback.