Exploring Nmap Port Scanning Techniques
Nmap is a powerful tool in the field of cybersecurity, especially when it comes to port scanning. Port scanning is a method used to discover which ports on a target system are open and what services might be running on those ports. Different types of port scanning techniques exist, each with its own unique advantages and specific use cases. In this step, we'll explore some of these techniques by scanning our mock service.
First, let's perform a basic TCP connect scan specifically targeting our port 8888. A TCP connect scan is a straightforward way to check if a port is open. It works by attempting to establish a full TCP connection to the target port. If the connection is successful, the port is considered open.
nmap -p 8888 localhost
In this command, the -p
option is used to specify which port(s) we want to scan. Here, we're telling Nmap to scan port 8888 on the localhost
, which refers to the current machine. After running this command, you should see output similar to this:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-30 15:50 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000097s latency).
PORT STATE SERVICE
8888/tcp open sun-answerbook
Nmap done: 1 IP address (1 host up) scanned in 0.05 seconds
This output confirms that our port 8888 is open. Nmap has also identified the service name associated with this port according to its internal database.
Now, let's try a SYN scan. A SYN scan is a stealthier approach compared to the TCP connect scan. It doesn't complete the full TCP connection, which makes it less likely to be detected by intrusion detection systems.
sudo nmap -sS -p 8888 localhost
The -sS
option specifies that we want to perform a SYN scan. This type of scan requires root privileges because it involves sending raw network packets, which is a low - level operation. That's why we use the sudo
command. The output should be similar to the previous scan:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-30 15:55 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000097s latency).
PORT STATE SERVICE
8888/tcp open sun-answerbook
Nmap done: 1 IP address (1 host up) scanned in 0.04 seconds
Next, let's try a UDP scan. UDP (User Datagram Protocol) is a different type of network protocol compared to TCP. While TCP provides a reliable, connection - oriented service, UDP is a connectionless protocol. We'll use a UDP scan to check if port 8888 is open for UDP traffic.
sudo nmap -sU -p 8888 localhost
The -sU
option specifies a UDP scan. UDP scans can be more time - consuming than TCP scans because UDP doesn't have the same built - in acknowledgment mechanism as TCP, so Nmap has to wait longer to determine if a port is open or closed. The output might look like this:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-30 16:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000097s latency).
PORT STATE SERVICE
8888/udp closed sun-answerbook
Nmap done: 1 IP address (1 host up) scanned in 0.15 seconds
Notice that the UDP port is shown as closed. This is expected because our netcat service is listening for TCP connections, not UDP.
Finally, let's perform a service version detection scan. This type of scan helps us identify what specific service and its version are running on a particular port.
nmap -sV -p 8888 localhost
The -sV
option tells Nmap to perform service/version detection. It tries to send specific probes to the open ports and analyze the responses to determine the service and its version. The output might look like this:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-30 16:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000097s latency).
PORT STATE SERVICE VERSION
8888/tcp open http Apache httpd
Service Info: OS: Linux; CPE: cpe:/o:linux:linux_kernel
Nmap done: 1 IP address (1 host up) scanned in 6.51 seconds
The version detection might not accurately identify our netcat service as a genuine application, but it demonstrates how Nmap tries to determine what's running on open ports.
Let's save our findings to a file for future reference. Saving the scan results allows us to review them later, share them with others, or use them for further analysis.
nmap -p 8888 localhost > /home/labex/project/nmap_scan_results.txt
In this command, the >
symbol is used to redirect the output of the Nmap scan to a file named nmap_scan_results.txt
located in the /home/labex/project
directory.
You can view the saved results with:
cat /home/labex/project/nmap_scan_results.txt
The cat
command is used to display the contents of a file.
This concludes our exploration of different Nmap port scanning techniques.