Add Verbosity and Save Results to a File
In this step, you will learn how to add verbosity to your Nmap scan and save the results to a file. This is crucial for later analysis, reporting, or comparison with previous scans. You'll continue to randomize the host order while performing these actions.
The -v option in Nmap increases the verbosity level, providing more detailed information about the scan process. The -oN option specifies "normal" output, which is human-readable and suitable for parsing with simple tools.
To add verbosity and save the results of a randomized host scan to a file named random_scan.txt, execute the following command in your Xfce terminal:
sudo nmap -v --randomize-hosts -oN random_scan.txt 127.0.0.1/24
You will be prompted for your password. Since the labex user has sudo privileges without a password, simply press Enter.
This command tells Nmap to scan the 127.0.0.1/24 subnet, randomize the host order, provide verbose output, and save the output in the "normal" format to a file named random_scan.txt in your current directory (~/project).
The output in the terminal will now include details about the scan process, such as the probes being sent, the ports being scanned, and the reasons for certain decisions.
Example verbose output (the actual output will vary depending on your network):
Starting Nmap <version> ( https://nmap.org ) at <date>
Initiating Ping Scan at <time>
Scanning 256 hosts [2 ports/host]
Completed Ping Scan at <time>, <time>s elapsed (256 total hosts)
Initiating Parallel DNS resolution of 256 hosts. at <time>
Completed Parallel DNS resolution of 256 hosts. at <time>, <time>s elapsed
Initiating SYN Stealth Scan at <time>
Scanning 256 hosts [1000 ports/host]
Discovered open port 22/tcp on 127.0.0.1
Discovered open port 2121/tcp on 127.0.0.1
Discovered open port 2222/tcp on 127.0.0.1
Discovered open port 3001/tcp on 127.0.0.1
Discovered open port 8080/tcp on 127.0.0.1
Completed SYN Stealth Scan at <time>, <time>s elapsed (256 total hosts)
Nmap scan report for localhost (127.0.0.1)
Host is up (<latency>s latency).
PORT STATE SERVICE
22/tcp open ssh
2121/tcp open ccproxy-ftp
2222/tcp open EtherNetIP-1
3001/tcp open nessus
8080/tcp open http-proxy
Nmap done: 256 IP addresses (1 host up) scanned in <time> seconds
After the scan completes, you can view the contents of the random_scan.txt file using the cat command:
cat random_scan.txt
The random_scan.txt file now contains the same information that was displayed on the screen during the scan. You can now use this file for further analysis or reporting.