Common network protocols and vulnerabilities in Cybersecurity - Time & Space Complexity
Start learning this pattern below
Jump into concepts and practice - no test required
When studying network protocols and their vulnerabilities, it is important to understand how the time to detect or exploit a vulnerability grows as the network size or traffic increases.
We want to know how the effort or operations needed change as more devices or data are involved.
Analyze the time complexity of scanning a network for open ports using a simple port scanner.
for ip in network_range:
for port in common_ports:
if scan_port(ip, port) == 'open':
log_open_port(ip, port)
This code checks each IP address in a network range against a list of common ports to find which ports are open.
- Primary operation: Checking each port on each IP address.
- How many times: For every IP in the network range, it checks every port in the list.
As the number of IP addresses or ports increases, the total checks grow quickly.
| Input Size (IPs x Ports) | Approx. Operations |
|---|---|
| 10 IPs x 10 Ports | 100 checks |
| 100 IPs x 10 Ports | 1,000 checks |
| 1,000 IPs x 10 Ports | 10,000 checks |
Pattern observation: The total operations grow proportionally to the number of IPs times the number of ports.
Time Complexity: O(n * m)
This means the time needed grows directly with both the number of IP addresses and the number of ports scanned.
[X] Wrong: "Scanning more ports won't affect the time much if the network is small."
[OK] Correct: Even with a small network, increasing ports scanned multiplies the total checks, so time grows accordingly.
Understanding how scanning operations grow helps you explain how vulnerabilities can be found or exploited efficiently in real networks.
"What if we only scan a random sample of ports instead of all common ports? How would the time complexity change?"
Practice
Solution
Step 1: Understand the purpose of HTTPS
HTTPS stands for HyperText Transfer Protocol Secure and encrypts data to protect privacy.Step 2: Compare with other protocols
HTTP is not secure, FTP is for file transfer, and DNS resolves domain names, none encrypt data like HTTPS.Final Answer:
HTTPS -> Option AQuick Check:
Secure web browsing = HTTPS [OK]
- Confusing HTTP with HTTPS
- Thinking FTP encrypts web data
- Assuming DNS secures browsing
Solution
Step 1: Recall default FTP port
FTP (File Transfer Protocol) uses port 21 by default for control commands.Step 2: Identify other ports
Port 80 is for HTTP, 443 for HTTPS, and 53 for DNS, so they are incorrect for FTP.Final Answer:
21 -> Option BQuick Check:
FTP default port = 21 [OK]
- Choosing port 80 (HTTP) for FTP
- Confusing HTTPS port 443 with FTP
- Selecting DNS port 53
response = {'status': 'NOERROR', 'data': '1.2.3.4'}
if response['status'] == 'NOERROR':
print('Valid IP:', response['data'])
else:
print('Error in DNS response')What will be printed?
Solution
Step 1: Check the condition on response status
The code checks if response['status'] equals 'NOERROR', which it does.Step 2: Determine the printed output
Since condition is true, it prints 'Valid IP:' followed by response['data'], which is '1.2.3.4'.Final Answer:
Valid IP: 1.2.3.4 -> Option AQuick Check:
response['status'] == 'NOERROR' prints IP [OK]
- Confusing status with data value
- Expecting error when none occurs
- Assuming KeyError without missing keys
Solution
Step 1: Identify the nature of the attack
Intercepting FTP traffic and stealing credentials indicates someone is spying on communication.Step 2: Match with known vulnerabilities
Man-in-the-Middle (MitM) attacks intercept and alter communication between two parties, fitting this scenario.Final Answer:
Man-in-the-Middle Attack -> Option CQuick Check:
Intercepted FTP = Man-in-the-Middle [OK]
- Confusing with DNS Spoofing
- Thinking SQL Injection affects FTP
- Mixing with Cross-Site Scripting
Solution
Step 1: Identify email transmission protocols
SMTP is the standard protocol for sending emails, but by default it is unencrypted.Step 2: Choose encryption method for SMTP
STARTTLS upgrades SMTP to use encryption, protecting emails from eavesdropping during transmission.Step 3: Exclude other protocols
FTP is for file transfer, HTTP is for web browsing, and Telnet is insecure remote access; none encrypt email.Final Answer:
SMTP with STARTTLS -> Option DQuick Check:
Email encryption during send = SMTP + STARTTLS [OK]
- Choosing FTP or HTTP for email
- Ignoring encryption in SMTP
- Selecting Telnet which is insecure
