Skip to content

Instantly share code, notes, and snippets.

@PSJoshi
Created November 1, 2022 12:16
Show Gist options
  • Save PSJoshi/1ddb53b42a1b099355df9eac86ced222 to your computer and use it in GitHub Desktop.
Save PSJoshi/1ddb53b42a1b099355df9eac86ced222 to your computer and use it in GitHub Desktop.
Using Nmap to detect vulnerabilities

Converting Nmap xml reports to html

Nmap is popular network scanner for scanning of ports and vulnerabilities and supports various output formats like XML. As a result, scan data can be parsed by other tools such as Metasploit or ZenMap GUI. For human readability, nmap scan output can be formatted to a nice HTML report using tool like xsltproc.

Typical Nmap scan command looks like

# nmap -sTV -p- -A -T4 -vvvv -oA <nmap-scan-xml-report-file> <machine-ip-to-scan>
  • -sTV TCP connect scan with version detection
  • -p- Port selection: All ports from 1-65535
  • -A Enables several modes. This enables version & OS detection

Once the scan is over, it will create scan report in various formats.

Converting the XML File into an HTML File

xsltproc tool can be used to convert nmap XML report file into a nicely formatted HTML file. To perform this conversion, run the following command:

# xsltproc <nmap-scan-xml-report-file> -o <nmap-scan-html-report-file>

Once html conversion is done, you can use any browser to view the report.

IP specific nmap reports

You can generate ip specific nmap report with date using the script below:

#!/bin/bash
# script: host-date.sh
cur_date=$(date +%F)
host_name=$(hostname -I|xargs)
echo $host_name-$cur_date

Use the name generated in the last line of bash script for html report.

Using nmap to find security vulnerabilities

#!/bin/bash
# nmap -sV -A -oX <nmap-scan-xml-report-file> --script=vulscan/vulscan.nse <machine-ip-to-scan>
# OR
# nmap -sV -A -oX <nmap-scan-xml-report-file> --script=vulners.nse <machine-ip-to-scan>

# xsltproc <nmap-scan-xml-report-file> -o <nmap-scan-html-report-file>

-SV: Probe open ports to determine service/version info A: Enable OS detection, version detection, script scanning, and traceroute

More details:

Testing SSL certificate expiry using nmap

# nmap -iL <site-list.txt> -sV -p 443 -oX <nmap-xml-report-file> --script=ssl-cert
# OR
# nmap -sV -p 443 -oX <nmap-xml-report-file> --script=ssl-cert <machine-ip-to-scan>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment