In this step, we're going to use Nmap to scan the UDP server you set up in the previous step. This process is crucial as it will help you understand how Nmap identifies open UDP ports and the services running on them. By the end of this step, you'll have a better grasp of how to use Nmap for UDP scanning, which is an essential skill in the field of cybersecurity.
Understanding Nmap UDP Scanning
Nmap, short for Network Mapper, is a well - known free and open - source tool used for network discovery and security auditing. When it comes to scanning UDP ports, Nmap operates differently compared to TCP port scanning.
UDP, or User Datagram Protocol, is a connectionless protocol. Unlike TCP, which establishes a connection before data transfer, UDP simply sends data without setting up a connection first. This means that traditional connection - based scanning methods used for TCP ports won't work for UDP.
When Nmap scans UDP ports, it sends empty UDP packets to the target port and then waits for a response. If the port is closed, the target system usually sends back an ICMP "port unreachable" message. However, if the port is open, things get a bit more complicated. There might be no response at all, which makes it hard to tell if the port is truly open. Or, if the UDP service running on the port recognizes the packet format, it might send a response.
It's important to note that UDP scanning is generally slower and less reliable than TCP scanning. This is because UDP doesn't have the built - in mechanisms for error checking and retransmission like TCP does.
-
First, open a new terminal window. Make sure to keep the previous terminal with the UDP server running. This is important because we'll be scanning the UDP server that's currently active in that terminal.
-
Next, we need to navigate to the project directory. In the new terminal, run the following command:
cd /home/labex/project
This command changes the current working directory to the project directory where all our relevant files and configurations are located.
- Now, it's time to run the Nmap UDP scan. We'll be scanning the localhost (127.0.0.1) targeting port 9999. Run the following command:
sudo nmap -sU -p 9999 127.0.0.1 > /home/labex/project/udp_scan_results.txt
Let's break down this command to understand what each part does:
sudo
: This is used to run the command with elevated privileges. UDP scanning requires these elevated privileges because it involves sending packets at a low - level network layer.
nmap
: This is the scanning tool we're using. It's the core of our operation for network discovery and security auditing.
-sU
: This option tells Nmap to perform a UDP scan.
-p 9999
: This option specifies that we only want to scan port 9999.
127.0.0.1
: This is the target IP address. In this case, it's the localhost, which means we're scanning our own machine.
> /home/labex/project/udp_scan_results.txt
: This part redirects the output of the Nmap scan to a file named udp_scan_results.txt
in the project directory. This way, we can review the results later.
- After the scan is complete, we can view the results. Run the following command:
cat /home/labex/project/udp_scan_results.txt
You should see output similar to the following:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-09-15 12:00 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000054s latency).
PORT STATE SERVICE
9999/udp open|filtered unknown
Nmap done: 1 IP address (1 host up) scanned in 0.41 seconds
Understanding the Results
Let's take a closer look at the scan results and understand what they mean.
The open|filtered
state indicates that Nmap did not receive an ICMP "port unreachable" message. There are a few possible explanations for this:
- The port is open, and the UDP service is running as expected.
- The port might be filtered by a firewall. A firewall could be blocking the ICMP "port unreachable" messages or the UDP traffic itself.
- The target system might not be sending ICMP "port unreachable" messages for some reason.
In our case, since we set up the UDP server ourselves, we know that the port is open. The unknown
service label means that Nmap couldn't determine what service is running on that port based on its service fingerprinting.
As mentioned earlier, UDP scanning is less conclusive than TCP scanning. That's why Nmap often shows the open|filtered
state for UDP ports, making it a bit more challenging to accurately determine the status of UDP ports.