Penetration testing methodology in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When performing penetration testing, it is important to understand how the time needed grows as the target system or network size increases.
We want to know how the steps in the testing process scale with the amount of information or systems involved.
Analyze the time complexity of the following simplified penetration testing steps.
for each host in network:
scan open ports on host
for each open port:
attempt known exploits
record results
This code scans each host in a network, checks open ports, tries exploits on those ports, and saves findings.
Identify the loops, recursion, array traversals that repeat.
- Primary operation: Looping over each host and then each open port on that host.
- How many times: The outer loop runs once per host; the inner loop runs once per open port on that host.
As the number of hosts increases, the scanning time grows roughly in proportion to the number of hosts and their open ports.
| Input Size (hosts) | Approx. Operations |
|---|---|
| 10 | Scanning 10 hosts and their ports |
| 100 | Scanning 100 hosts and their ports, about 10 times more work |
| 1000 | Scanning 1000 hosts and their ports, about 100 times more work than 10 hosts |
Pattern observation: The work grows roughly in direct proportion to the number of hosts and ports scanned.
Time Complexity: O(n * m)
This means the time grows with the number of hosts (n) times the average number of open ports per host (m).
[X] Wrong: "The time only depends on the number of hosts, so it grows linearly with hosts."
[OK] Correct: Each host can have many open ports, and testing each port adds extra work, so the total time depends on both hosts and ports.
Understanding how testing steps scale helps you explain your approach clearly and shows you think about efficiency in real-world security tasks.
"What if we added a step that tries multiple exploits per open port? How would the time complexity change?"
Practice
penetration testing methodology?Solution
Step 1: Understand the methodology sequence
The penetration testing methodology starts with planning and gathering information about the target system.Step 2: Identify the first step in the process
Before any testing or exploitation, testers must plan and collect data to know what to test.Final Answer:
Planning and information gathering -> Option BQuick Check:
First step = Planning and information gathering [OK]
- Starting with exploitation before planning
- Reporting before testing
- Skipping cleanup step
Solution
Step 1: Recall the standard penetration testing phases
The typical order is Planning, Scanning (information gathering), Exploitation (attacking), then Reporting.Step 2: Match the correct sequence
Planning, Scanning, Exploitation, Reporting correctly lists the steps in the right order.Final Answer:
Planning, Scanning, Exploitation, Reporting -> Option CQuick Check:
Correct order = Planning, Scanning, Exploitation, Reporting [OK]
- Mixing up the order of steps
- Starting with exploitation
- Reporting before testing
Solution
Step 1: Understand the scanning results
Open ports 22 (SSH) and 80 (HTTP) indicate services that can be tested for weaknesses.Step 2: Decide the next step in methodology
After scanning, the next step is exploitation, trying to find and use vulnerabilities on those services.Final Answer:
Exploit vulnerabilities on services running on ports 22 and 80 -> Option DQuick Check:
Scan -> Exploit next [OK]
- Reporting before exploitation
- Skipping exploitation step
- Ignoring open ports
Solution
Step 1: Identify the cleanup phase purpose
The cleanup phase ensures no test artifacts or accounts remain that could be exploited later.Step 2: Understand consequences of skipping cleanup
Leaving test accounts active creates security risks and violates best practices.Final Answer:
It violates the cleanup phase and may leave security risks -> Option AQuick Check:
Cleanup prevents leftover risks [OK]
- Thinking leftover accounts improve security
- Confusing cleanup with reporting
- Ignoring cleanup importance
Solution
Step 1: Understand reporting responsibilities
Penetration testing methodology requires reporting all findings to give a full security picture.Step 2: Evaluate the options
Ignoring minor vulnerabilities is not best practice; all should be reported for client awareness.Final Answer:
Report all vulnerabilities found, regardless of severity -> Option AQuick Check:
Report all findings for full transparency [OK]
- Ignoring minor issues
- Reporting only major vulnerabilities
- Waiting for client to ask
