Port scanning is a method used to check which ports on a computer or server are open and listening for connections. It helps find services running on those ports.
Click to reveal answer
beginner
What does an open port indicate?
An open port means a program or service is ready to accept connections on that port. It can be used to communicate or transfer data.
Click to reveal answer
beginner
Which bash tool is commonly used for port scanning?
The tool 'nc' (netcat) is often used in bash scripts to scan ports by trying to connect to them.
Click to reveal answer
beginner
What does a closed port mean during a scan?
A closed port means no service is listening on that port, so connection attempts will fail or be refused.
Click to reveal answer
beginner
Why should you be careful when performing port scans?
Port scanning can be seen as suspicious or intrusive by network owners. Always have permission before scanning to avoid legal or ethical issues.
Click to reveal answer
What does port scanning help you discover?
AThe CPU speed of a server
BWhich ports are open on a target machine
CThe amount of RAM installed
DThe operating system version
✗ Incorrect
Port scanning checks which ports are open and listening on a target machine.
Which bash command is commonly used for simple port scanning?
Agrep
Bls
Cnc (netcat)
Dchmod
✗ Incorrect
'nc' or netcat can connect to ports to check if they are open.
What does an open port mean?
AA service is listening and ready to accept connections
BThe port is blocked by a firewall
CThe port is closed and unused
DThe server is turned off
✗ Incorrect
An open port means a service is listening on that port.
What should you do before scanning someone else's network?
AUse a slow internet connection
BScan without telling anyone
COnly scan during the night
DGet permission from the network owner
✗ Incorrect
Always get permission to avoid legal or ethical problems.
If a port scan shows a port is closed, what does it mean?
ANo service is listening on that port
BThe port is open and active
CThe port is used for file storage
DThe port is hidden
✗ Incorrect
A closed port means no service is listening there.
Explain in simple terms what port scanning is and why it is useful.
Think about checking which doors (ports) are open in a building (computer).
You got /3 concepts.
Describe a basic way to scan ports using bash scripting.
Imagine knocking on doors to see if someone answers.
You got /3 concepts.
Practice
(1/5)
1. What is the main purpose of port scanning in network security?
easy
A. To install software remotely
B. To delete files on a remote server
C. To speed up internet connection
D. To find open ports on a computer
Solution
Step 1: Understand port scanning basics
Port scanning is used to check which network ports on a computer are open and accepting connections.
Step 2: Identify the correct purpose
Among the options, only finding open ports matches the purpose of port scanning.
Final Answer:
To find open ports on a computer -> Option D
Quick Check:
Port scanning = find open ports [OK]
Hint: Port scanning checks open ports, not files or speed [OK]
Common Mistakes:
Confusing port scanning with file operations
Thinking it improves internet speed
Assuming it installs software
2. Which of the following bash commands correctly scans if port 80 is open on host 192.168.1.1?
easy
A. nc -zv 192.168.1.1 80
B. nc -xv 192.168.1.1 80
C. nc -z 192.168.1.1 -p 80
D. nc -v 192.168.1.1
Solution
Step 1: Recall correct netcat syntax for port scanning
The option '-z' tells nc to scan without sending data, and '-v' enables verbose output. The host and port follow these flags.
Step 2: Check each option
Only nc -zv 192.168.1.1 80 uses the correct flags '-z' for scanning and '-v' for verbose, followed by host and port. Other options either lack necessary flags, use incorrect flags like -xv or misuse -p for source port, or omit the port specification.
Final Answer:
nc -zv 192.168.1.1 80 -> Option A
Quick Check:
Correct nc flags = -zv [OK]
Hint: Use nc -zv host port to scan a port [OK]
Common Mistakes:
Using wrong flags like -xv
Misplacing port with -p flag
Omitting port number
3. What will be the output of this bash snippet scanning ports 22 and 80 on localhost?
for port in 22 80; do
nc -zv localhost $port
done
medium
A. It will produce a syntax error
B. It will show if ports 22 and 80 are open or closed on localhost
C. It will scan ports 22 and 80 on a remote host
D. It will scan all ports from 22 to 80
Solution
Step 1: Analyze the for loop and command
The loop iterates over ports 22 and 80, running 'nc -zv localhost $port' for each port.
Step 2: Understand the command effect
Netcat checks if each specified port on localhost is open, printing the result.
Final Answer:
It will show if ports 22 and 80 are open or closed on localhost -> Option B
Quick Check:
Loop scans specified ports on localhost [OK]
Hint: Loop scans listed ports on localhost, not a range [OK]
Common Mistakes:
Thinking it scans a range of ports
Assuming remote host scanning
Expecting syntax errors
4. Identify the error in this bash script intended to scan ports 20 to 25 on 127.0.0.1:
for port in {20..25} do
nc -zv 127.0.0.1 $port
done
medium
A. The loop syntax is incorrect; it should use parentheses
B. The loop variable $port is not referenced correctly
C. The script is missing a semicolon after the for statement
D. The loop block is missing a 'do' keyword
Solution
Step 1: Check for correct bash for-loop syntax
Bash requires a semicolon or newline after the for statement before 'do'. Here, 'for port in {20..25}' is not followed by a semicolon or newline before 'do'.
Step 2: Verify other syntax elements
The loop variable and block are correct, and 'do' is present. The missing semicolon causes a syntax error.
Final Answer:
The script is missing a semicolon after the for statement -> Option C
Quick Check:
Missing semicolon after for statement causes error [OK]
Hint: Add semicolon or newline after for statement before do [OK]
Common Mistakes:
Omitting semicolon after for line
Misplacing 'do' keyword
Incorrect variable usage
5. You want to scan all ports from 80 to 85 on host 10.0.0.5 and save only open ports to a file named open_ports.txt. Which bash script snippet achieves this?
hard
A. for port in {80..85}; do nc -zv 10.0.0.5 $port 2>&1 | grep 'succeeded' >> open_ports.txt; done
B. for port in 80 81 82 83 84 85; do nc -zv 10.0.0.5 $port > open_ports.txt; done
C. nc -zv 10.0.0.5 80-85 > open_ports.txt
D. for port in {80..85}; do nc -zv 10.0.0.5 $port | grep 'failed' >> open_ports.txt; done
Solution
Step 1: Understand the scanning and filtering requirements
The script must scan ports 80 to 85, detect open ports, and save only those results to a file.
Step 2: Analyze each option
for port in {80..85}; do nc -zv 10.0.0.5 $port 2>&1 | grep 'succeeded' >> open_ports.txt; done loops over ports 80 to 85, runs nc with verbose and zero-I/O flags, redirects stderr to stdout, filters lines containing 'succeeded' (indicating open ports), and appends to open_ports.txt. for port in 80 81 82 83 84 85; do nc -zv 10.0.0.5 $port > open_ports.txt; done overwrites the file each time and does not filter open ports. nc -zv 10.0.0.5 80-85 > open_ports.txt uses invalid port range syntax. for port in {80..85}; do nc -zv 10.0.0.5 $port | grep 'failed' >> open_ports.txt; done filters 'failed' ports, opposite of requirement.
Final Answer:
for port in {80..85}; do nc -zv 10.0.0.5 $port 2>&1 | grep 'succeeded' >> open_ports.txt; done -> Option A