Scan specific ports with nmap --script banner -p 22,80 127.0.0.1
In the previous step, we scanned all default ports using the banner script. Now, we'll focus on scanning specific ports. This is useful when you know which services you're interested in, or when you want to reduce the scan time.
The command we'll be using is:
nmap --script banner -p 22,80 127.0.0.1
Let's break down the command:
nmap
: The network scanner.
--script banner
: Specifies the banner grabbing script.
-p 22,80
: This option tells Nmap to only scan ports 22 and 80. Port 22 is commonly used for SSH (Secure Shell), and port 80 is commonly used for HTTP (web server).
127.0.0.1
: The target IP address (localhost).
Before running the command, let's make sure we have services running on these ports. The LabEx VM should have SSH running on port 22 by default. We'll install a simple web server on port 80.
Open your Xfce terminal and run the following commands to install a basic HTTP server using Python:
sudo apt update
sudo apt install -y python3-pip
sudo python3 -m pip install http.server
Now, start the HTTP server on port 80. Navigate to your ~/project
directory first.
cd ~/project
python3 -m http.server 80
Keep this terminal window open and running the HTTP server. Open a new Xfce terminal window to continue with the Nmap scan.
Now, in the new terminal window, execute the Nmap command:
nmap --script banner -p 22,80 127.0.0.1
You should see output similar to this:
Starting Nmap 7.80 ( https://nmap.org ) at 2023-10-27 10:05 UTC
Nmap scan report for localhost (127.0.0.1)
Host is up (0.000072s latency).
Other addresses for localhost (alias(es)): localhost
PORT STATE SERVICE
22/tcp open ssh
| banner: SSH-2.0-OpenSSH_8.2p1 Ubuntu-4ubuntu0.5
|_
80/tcp open http
| banner: Server: SimpleHTTP/3.10 Python/3.10
|_
Nmap done: 1 IP address (1 host up) scanned in 0.10 seconds
This output shows that Nmap scanned ports 22 and 80, grabbed the banners, and displayed the service information. You can see the SSH banner and the SimpleHTTP server banner.
Remember to stop the python http server after you are done with this step by pressing Ctrl+C
in the terminal where it is running.