As part of Trustwave SpiderLabs network penetration testing team, I perform many internal penetration tests each year. As part of those tests, we see a lot of web servers. Some of those are internal portals like Sharepoint. Others are non-production copies of production systems. Some are random systems people have set up to test other applications. So, while we’re doing mapping on the internal network, it’s not always easy to figure out which of the 400 web services are worth examining closer. While I was thinking about this, I remembered something Russ Swift had shared with me: couldn’t you take screenshots with Nmap?
The answer is: yes. You can do anything with the Nmap Scripting Engine (NSE) that you can do with Lua, the language that NSE is based on. So, I set out to build a NSE screenshot tool. Unfortunately I couldn’t find a good library that would allow me to use the Lua bindings to render web pages into PNG files, so I needed some additional help. Thanks to a suggestion from Nate Drier, another of the SpiderLabs members, I found a tool that uses the webkit libraries to take screenshots. It’s the wkhtmltoimage tool that’s part of the wkhtmltopdf project.
Because the module uses an external binary to perform most of it’s work, I don’t think it’s suitable for inclusion in the standard Nmap scripts, but I have shared the module as part of SpiderLabs Git repository here: https://github.com/SpiderLabs/Nmap-Tools .
I’ll walk you through installing the pre-requisites, then we’ll take this for a test drive by running a penetration testing scenario. For this exercise, I’ll assume that you’re using BackTrack 5.
First, let’s get wkhtmltoimage:
wget http://wkhtmltopdf.googlecode.com/files/wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2
tar -jxvf wkhtmltoimage-0.11.0_rc1-static-i386.tar.bz2
cp wkhtmltoimage-i386 /usr/local/bin/
Next, let’s get and install the Nmap module:
git clone git://github.com/SpiderLabs/Nmap-Tools.git
cd Nmap-Tools/NSE/
cp http-screenshot.nse /usr/local/share/nmap/scripts/
nmap --script-updatedb
Now, let’s see what web services are listening. My test network uses the 192.168.1.0/24 network. We want to run an Nmap scan for that network and include the default scripts that are run in addition to our screenshot module. To do that, we type:
nmap -A --script=default,http-screenshot 192.168.1.0/24 -oA nmap-local
This launches the Nmap scan with OS detection, version detection, traceroute and scripts scanning using the default scripts as well as the http-screenshot module. It will scan the 192.168.1.0/24 network and output three types of output files: the Nmap format, the XML format, and the grepable format.
Why all 3? If we want to use the output for other tools such as Metasploit, it will want the XML format for input. The grepable format makes finding hosts with certain ports open very easy. For instance, if you wanted to find all the hosts with port 80 open you could issue the command: grep 80/open nmap-local.gnmap . That will return all of the hosts with port 80 open. Finally, sometimes we just want to browse through the results, and the Nmap format is the most human readable of the formats, so we always want it around in case we want to manually browse information.
Once scanning is completed, you can see the script has saved a screenshot of the open http port to the filename: screenshot-nmap-192.168.1.1:80.png. For each web port (http or https) a screenshot file will be created and a note will have been added to the Nmap output to indicate the filename it was saved as.[Screenshot example for http]
So now that we have our scan directory full of PNG screenshots of the web sites on our local network, we need a quick way to view them. One easy way is to script together a quick web page with the preview images on it. Here’s an example:
#!/bin/bash
printf "<HTML><BODY><BR>" > preview.html
ls -1 *.png | awk -F : '{ print $1":"$2"\n<BR><IMG SRC=\""$1"%3A"$2"\" width=400><BR><BR>"}' >> preview.html
printf "</BODY></HTML>" >> preview.html
When we look at the preview.html in a web browser we see this:
[Sample Web Page]
Based on the results, we see that there are a few web based services on the local network. Two of them are the default Apache page letting us know the site doesn’t have a specific default site, but may have sub-sites or pages that are part of it. Then we see two other services that are active and are worth additional investigation: a D-Link gateway page at 192.168.1.1 on port 80, and a page that requires JavaScript at 192.168.1.102 on port 8080.
Based on this quick example, it’s easy to see this method would make it easy to pick out things we’d like to investigate further if there are hundreds of web sites surfaced. Sites that are frequently interesting are: SharePoint sites, Tomcat Admin pages, Cisco setup pages, and internal Wiki pages. Let us know if you find this useful, or if you have suggestions on how to take this concept to the next level!

This segment talks about how to use custom Nmap NSE scripts to discover web services and take a screenshot of the resulting web page. Based on a script made available by Trustwave Spiderlabs..
Izrada web stranice
Posted by: online money | 22 December 2012 at 05:46
Recently a member from the Trustwave SpiderLabs team created an nmap NSE script that could be used to take a screenshot of webpages as it scanned the network. Working for a top 10 accounting firm, I conduct a lot of internal penetration tests for clients that operate on very large networks, and sometimes I’m required to audit entire counties. Having the ability to view all the webpages on the internal network without being required to manually type in each addresses into the browser sounded amazing. This was very exciting news now that there was a way to automate this process and have the ability to scale.
izrada web stranice
Posted by: online money | 22 December 2012 at 05:30
I had issues initially getting this NSE script to work because of a different OS and version of nmap.
I posted a tutorial including tweaks and optimizations I made to the code in order to make it run, and perform better:
http://www.pentestgeek.com/2012/07/11/using-nmap-to-screenshot-web-services-troubleshooting/
Posted by: Zeknox | 12 July 2012 at 01:05
Love the post!
I made some modifications to the scripts posted here:
http://pauldotcom.com/wiki/index.php/Episode295#Tech_Segment:_Using_Nmap_To_Screenshot_Web_Services
Enjoy!
Cheers,
Paul
Posted by: Psw | 09 July 2012 at 13:52
Which script are you trying to find that it's showing isn't there? You can get to the git rep by going to https://github.com/SpiderLabs/Nmap-Tools and then copying and pasting the github URL. If you are not able to get the binary, you can get it by going directly to http://wkhtmltopdf.googlecode.com and downloading it from the links on the left.
I've had a few people test it out, and show that it is working, however some sites it appears that wkhtmltoimage has problems with. It's not really a NSE script bug, but more a problem with the wkhtmltoimage binary as it's erroring out. I'll do some more testing and see if I can find a workaround.
Thanks for the feedback.
Posted by: Ryan Linn | 08 July 2012 at 07:56
Looks like the script source link is dead, any alternative sites? Very nice work on the script, if it works as advertised would be extremely cool.
Posted by: Smith8680 | 07 July 2012 at 22:25
Has anyone other than the author tried this tutorial?
Posted by: Monty Sharma | 29 June 2012 at 13:52
another simple tweak on top of preview page would be to add clickable links to respective url's.
Posted by: anantshri | 15 June 2012 at 13:10
The instructions only worked with the BackTrack maintained nmap. I had nmap installed from source and it failed for me. That's okay, because I just went back to maintained version.
Posted by: Winfang98 | 14 June 2012 at 16:44