Reconnaissance and information gathering in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When gathering information about a target system, it is important to understand how the time taken grows as the amount of data or targets increases.
We want to know how the effort changes when scanning more hosts or collecting more details.
Analyze the time complexity of the following reconnaissance code snippet.
for ip in ip_range:
open_ports = scan_ports(ip)
for port in open_ports:
service_info = get_service_info(ip, port)
store(service_info)
gather_os_info(ip)
This code scans a list of IP addresses, checks open ports on each, collects service details, and gathers operating system info.
Look at the loops and repeated steps:
- Primary operation: Looping over each IP address in the range.
- Nested operation: For each IP, scanning all open ports and gathering info on each port.
- How many times: The outer loop runs once per IP; the inner loop runs once per open port found on that IP.
As the number of IPs increases, the scanning time grows roughly in proportion to the number of IPs and the number of open ports per IP.
| Input Size (IPs) | Approx. Operations |
|---|---|
| 10 | About 10 times the port scans and info gathers |
| 100 | About 100 times the port scans and info gathers |
| 1000 | About 1000 times the port scans and info gathers |
Pattern observation: The total work grows roughly linearly with the number of IPs scanned, multiplied by the number of ports per IP.
Time Complexity: O(n * p)
This means the time grows proportionally to the number of IP addresses (n) times the average number of open ports (p) per IP.
[X] Wrong: "Scanning more IPs only slightly increases time because ports are scanned in parallel."
[OK] Correct: Even with some parallelism, each IP and port still requires time to scan, so total time grows with the total number of checks.
Understanding how scanning time grows helps you plan efficient reconnaissance and shows you can think about scaling tasks in cybersecurity.
"What if we limited port scanning to only the top 10 common ports instead of all open ports? How would the time complexity change?"
Practice
Solution
Step 1: Understand the role of reconnaissance
Reconnaissance is the initial phase where information about a target is collected to plan further actions.Step 2: Identify the correct purpose
Among the options, only gathering information fits the reconnaissance phase.Final Answer:
To gather information about a target system or network -> Option AQuick Check:
Reconnaissance = Information gathering [OK]
- Confusing reconnaissance with fixing or attacking
- Thinking it involves encryption
- Assuming it creates accounts
Solution
Step 1: Identify passive reconnaissance tools
Passive reconnaissance collects data without interacting directly with the target system.Step 2: Match command to passive info gathering
Thewhoiscommand queries public domain registration info without contacting the target directly.Final Answer:
whois -> Option CQuick Check:
Passive info tool = whois [OK]
- Using ping which sends packets actively
- Confusing nmap as passive (it scans actively)
- Thinking netstat gathers external info
nmap -sP 192.168.1.0/30:Host 192.168.1.1 is up Host 192.168.1.2 is up Host 192.168.1.3 is down Host 192.168.1.4 is up
What does this output tell you?
Solution
Step 1: Understand nmap ping scan output
The-sPoption checks which hosts respond to ping requests in the given IP range.Step 2: Interpret the output lines
Hosts marked "is up" respond and are reachable; "is down" means no response.Final Answer:
Hosts 192.168.1.1, 1.2, and 1.4 are reachable; 1.3 is not -> Option BQuick Check:
Ping scan shows reachable hosts = 1.1, 1.2, 1.4 [OK]
- Assuming 'is down' means reachable
- Thinking all hosts are unreachable
- Confusing syntax error with normal output
nslookup example.com but gets an error saying "server can't find example.com". What is the most likely cause?Solution
Step 1: Understand nslookup error message
The error "server can't find" usually means the DNS server queried cannot resolve the domain.Step 2: Analyze possible causes
If the domain exists, the likely cause is DNS server issues, not user typo or physical network problems.Final Answer:
The DNS server is unreachable or misconfigured -> Option AQuick Check:
DNS error = server unreachable or misconfigured [OK]
- Assuming domain does not exist without checking
- Blaming user typo without evidence
- Thinking physical cable issues cause DNS errors
Solution
Step 1: Understand active vs passive reconnaissance
Active methods interact directly and can alert security; passive methods gather info without direct contact.Step 2: Choose method to avoid detection
Analyzing public web pages is passive and safe for collecting emails without triggering alarms.Final Answer:
Passive reconnaissance by analyzing public web pages -> Option DQuick Check:
Safe info gathering = passive reconnaissance [OK]
- Using active scans that trigger alerts
- Trying brute force which is illegal and noisy
- Confusing phishing with reconnaissance
