NMAP — HTML Reports To PDF, Using CLI

Larry Dennis Lumban Toruan
2 min readJan 31, 2023

Convert your Nmap HTML reports to PDF files.

There’s a time when we are going to present our scanning reports in a proper way, whether we are going to show them to the upper managements or non-technical people. Nmap provides an option for generating our reports into XML files, but it is not enough considering the XML files somehow broken if opened from a browser.

Fortunately, there is a way. We will use a converter that would generate our reports into viewable files, with only using CLI.

Step #1: Generate our XML report

The usual first step is by generating our scan results into an XML file

nmap [OPTIONS] -oX file_name.xml [TARGET]

Step #2: Render our XML file into an HTML file

The second step is to use xsltproc [1]. It’s a tool for rendering XML files into HTML files. We have to install them first if it isn’t yet installed. Since I use Debian package manager, I’m going to install the tool through it. You may want to do the same using your favorite package manager.

sudo apt install xsltproc

Next, if the tool is already installed, we will convert the XML file.

xsltproc file_name.xml -o html_file_name.html

Step #3: Convert our HTML file into a PDF file

The last step is also pretty simple, but we need another tool. I recommend wkhtmltopdf [2] for its simplicity. We are going to convert our rendered HTML file into a PDF file. As usual, we have to install the tool first. Again, you may want to do the same using your favorite package manager.

sudo apt install wkhtmltopdf
wkhtmltopdf -n html_file_name.html pdf_file_name.pdf

Notice that we used -n option there. The rendered HTML file actually has Javascript code. There are functions written in Javascript which is used to toggle between hidden information on ports that are closed or filtered. It would work in HTML but not in PDF format. In the help section of the tool, the -n option is to disable Javascript when converting the file.

An Nmap scan report in a pdf file.
The PDF file, converted from an HTML format

There you have it. We have a generated report in a PDF format ready to be presented for our managers and non-technical people.

References

  1. https://nmap.org/book/output-formats-output-to-html.html
  2. https://unix.stackexchange.com/a/533953

--

--