Penetration Testing Explained: Phases, Methods and the Law
What is penetration testing?
Penetration testing is an authorised, simulated attack on a system, network or application to find weaknesses and show their real impact before criminals do. A tester works within an agreed written scope, gathers information, finds and exploits vulnerabilities, and documents every step. The result is a report that explains what was compromised, how, and how to fix it.
Why organisations commission penetration tests
A vulnerability assessment lists known weaknesses. A penetration test goes further: it shows whether those weaknesses can be chained into a real breach, such as moving from a low-privilege web account to the database. That evidence helps leaders understand risk and prioritise fixes.
- Validate that security controls work as designed, not only on paper.
- Test a new application or network before it goes live.
- Meet audit or contractual requirements that call for independent testing.
- Practise detection: the defenders learn whether they noticed the test.
Key terms
- Rules of engagement (RoE): the written limits of the test, including targets, times, techniques and contacts.
- Exploit: code or a technique that uses a vulnerability to gain access or cause an effect.
- Privilege escalation: moving from limited rights to higher rights, such as root or domain administrator.
- Pivoting: using a compromised host to reach systems that were not directly reachable.
The phases of a penetration test
- Scoping and written authorisation: agree targets, exclusions, testing windows, permitted techniques, emergency contacts and data handling. Get signed permission from someone with the authority to grant it, and confirm that third-party hosting or cloud providers allow testing.
- Reconnaissance: gather information passively (public DNS records, certificate transparency logs, job adverts, code repositories) and then actively (interacting with in-scope hosts).
- Scanning and enumeration: identify live hosts, open ports, service versions, users, shares and web endpoints.
- Exploitation: attempt to use selected vulnerabilities to gain access, choosing the least disruptive method and stopping if a system becomes unstable.
- Post-exploitation: assess impact by escalating privileges, accessing agreed sensitive data or pivoting, then remove any tools, accounts or files you created.
- Reporting: document findings, evidence, risk ratings and fixes, and offer a re-test once fixes are in place.
# Recon and enumeration examples (in-scope lab targets only)
dig +short example-lab.test A
nmap -sV -sC -p- -oA full-tcp 10.10.10.5
whatweb http://10.10.10.5/
gobuster dir -u http://10.10.10.5/ -w /usr/share/wordlists/dirb/common.txt Black box, grey box and white box testing
| Type | What the tester knows | Strength | Trade-off |
|---|---|---|---|
| Black box | Little or nothing beyond the target name or range | Closest to an outside attacker | Time goes on discovery; deep flaws may be missed |
| Grey box | Partial information, such as a user account or architecture overview | Balances realism and coverage | Needs clear agreement on what is shared |
| White box | Full access to source code, configurations and documentation | Most thorough coverage | Less realistic as an attack simulation |
Tests are also described by target: external network, internal network, web application, mobile, wireless, cloud and social engineering. A red team exercise is broader and goal-based, testing the organisation's detection and response as well as its technical controls.
Methodologies: PTES and the OWASP WSTG
A methodology keeps testing consistent and repeatable. The Penetration Testing Execution Standard (PTES) describes seven stages: pre-engagement interactions, intelligence gathering, threat modelling, vulnerability analysis, exploitation, post-exploitation and reporting. The OWASP Web Security Testing Guide (WSTG) provides detailed, numbered test cases for web applications, covering areas such as configuration, authentication, session management, input validation and business logic.
Other references include NIST SP 800-115, a technical guide to security testing, and the OSSTMM. Many testers combine one overall methodology with the WSTG for web work and map web findings to the OWASP Top 10.
Legality and ethics in India
Permission is what separates a penetration test from a crime. India's Information Technology Act, 2000 makes unauthorised access to a computer system, unauthorised downloading or copying of data, and damage to systems liable to compensation and, in many cases, criminal prosecution. Good intentions, such as "just checking" a website for flaws, are not a defence.
- Test only with written authorisation from the system owner, and keep a copy during the engagement.
- Stay inside scope; a host that looks related is out of bounds until it is added in writing.
- Handle any personal data you see under a confidentiality agreement and in line with the Digital Personal Data Protection Act, 2023.
- If you find a flaw in a third-party site by accident, stop and use its published vulnerability disclosure or bug bounty process, or report it to CERT-In.
This guide is educational and not legal advice; organisations should consult a qualified lawyer for contracts and edge cases.
Writing a useful penetration test report
The report is the product the client pays for. It usually contains an executive summary for leadership, the scope and methodology, an attack narrative showing how weaknesses were chained, and detailed findings. Each finding should include a title, affected assets, a risk rating, step-by-step reproduction, evidence such as screenshots or request and response pairs, and specific remediation advice.
Redact passwords and personal data in evidence, share the report only through an agreed secure channel, and offer a re-test so the client can prove the fixes work.
Practical exercise: run a scoped lab engagement
Set up an isolated lab with Kali Linux and one intentionally vulnerable machine, such as Metasploitable 2 or a retired machine from a legal training platform.
- Write a one-page rules of engagement: target IP, permitted techniques, testing window and a rule to stop if the target crashes.
- Perform recon and a full port and version scan, saving all output.
- Identify two vulnerable services and research their CVEs.
- Exploit one of them and capture evidence of the access level you obtained.
- Attempt privilege escalation, then remove anything you created on the target.
- Write a report with an executive summary, an attack narrative and two detailed findings.
You are done when someone else could reproduce your findings from the report alone. Structured attack and defence labs are part of the Advanced Networking course; the toolkit is introduced in the Kali Linux guide.
Common mistakes
- Starting any testing before the written authorisation is signed.
- Testing a hostname or IP address that was not explicitly listed in scope.
- Running untested public exploit code that may crash production systems or contain malware.
- Leaving shells, accounts or uploaded files on the target after the engagement.
- Writing a report that lists tool output without explaining business impact or fixes.
Frequently asked questions
Is it legal to practise penetration testing at home?
Yes, on systems you own, such as virtual machines in an isolated lab, or on legal training platforms that give you explicit permission to attack their machines.
How long does a penetration test take?
It depends on scope. A small web application may take a few days, while a large internal network or a red team exercise can run for weeks. The scoping meeting sets the time.
Can automated tools replace a penetration tester?
No. Tools find known issues quickly, but chaining weaknesses, testing business logic and judging impact need a skilled person. Grounding in network security and Linux helps a great deal.
What is the difference between a bug bounty and a penetration test?
A penetration test is a contracted engagement with a fixed scope and timeline. A bug bounty is an open programme that pays researchers per valid finding within the published scope and rules.