| |||||
| |||||
Search Irongeek.com:
Help Irongeek.com pay for bandwidth and research equipment: |
Back To MAN Pages From BackTrack 5 R1 Master List
Ndiff, like the standard
diff
utility, compares two scans at a time.
-h, --help
-v, --verbose
--text
--xml
Any other arguments are taken to be the names of Nmap XML output files. There must be exactly two.
Let's use Ndiff to compare the output of two Nmap scans that use different options. In the first, we'll do a fast scan (-F), which scans fewer ports for speed. In the second, we'll scan the larger default set of ports, and run an NSE script.
Changes are marked by a
-
or
+
at the beginning of a line. We can see from the output that the scan without the
-F
fast scan option found two additional ports: 70 and 31337. The
html-title
script produced some additional output for port 80. From the port counts, we may infer that the fast scan scanned 100 ports (95 filtered, 3 open, and 2 closed), while the normal scan scanned 1000 (993 filtered, 3 open, and 4 closed).
The
-v
(or
--verbose) option to Ndiff made it show even the ports that didn't change, like 22 and 25. Without
-v, they would not have been shown.
There are two output modes: text and XML. Text output is the default, and can also be selected with the
--text
option. Text output resembles a unified diff of Nmap's normal terminal output. Each line is preceded by a character indicating whether and how it changed.
-
means that the line was in the first scan but not in the second;
+
means it was in the second but not the first. A line that changed is represented by a
-
line followed by a
+
line. Lines that did not change are preceded by a blank space.
Example 1
is an example of text output. Here, port 80 on the host photos-cache-snc1.facebook.com gained a service version (lighttpd 1.5.0). The host at 69.63.179.25 changed its reverse DNS name. The host at 69.63.184.145 was completely absent in the first scan but came up in the second.
Example 1. Ndiff text output
XML output, intended to be processed by other programs, is selected with the
--xml
option. It is based on Nmap's XML output, with a few additional elements to indicate differences. The XML document is enclosed in
nmapdiff
and
scandiff
elements. Host differences are enclosed in
hostdiff
tags and port differences are enclosed in
portdiff
tags. Inside a
hostdiff
or
portdiff,
a
and
b
tags show the state of the host or port in the first scan (a) or the second scan (b).
Example 2
shows the XML diff of the same scans shown above in
Example 1. Notice how port 80 of photos-cache-snc1.facebook.com is enclosed in
portdiff
tags. For 69.63.179.25, the old hostname is in
a
tags and the new is in
b. For the new host 69.63.184.145, there is a
b
in the
hostdiff
without a corresponding
a, indicating that there was no information for the host in the first scan.
Example 2. Ndiff XML output
Using Nmap, Ndiff, cron, and a shell script, it's possible to scan a network daily and get email reports of the state of the network and changes since the previous scan.
Example 3
shows the script that ties it together.
Example 3. Scanning a network periodically with Ndiff and cron
If the script is saved as
/root/scan-ndiff.sh, add the following line to root's crontab:
The exit code indicates whether the scans are equal.
Report bugs to the
nmap-dev
mailing list at
nmap-dev@insecure.org.
Ndiff started as a project by Michael Pattrick during the 2008 Google Summer of Code. Michael designed the program and led the discussion of its output formats. He wrote versions of the program in Perl and C++, but the summer ended shortly after it was decided to rewrite the program in Python for the sake of Windows (and Zenmap) compatibility. This Python version was written by David Fifield. James Levine
released[1]
a Perl script named Ndiff with similar functionality in 2000.
David Fifield
david@bamsoftware.com
Michael Pattrick
mpattrick@rhinovirus.org
15 most recent posts on Irongeek.com:
|
If you would like to republish one of the articles from this site on your
webpage or print journal please contact IronGeek.
Copyright 2020, IronGeek
Louisville / Kentuckiana Information Security Enthusiast