Monday, August 8, 2011

Automating NMAP Capabilities


Many times I have encountered a problem with projects where large scanning of network host is required. In that case, you simply cannot expect your consultant to scan each host individually, analyze output and list down all vulnerable ports/services. Yes..we can even detect open ports with Nessus but still it has a host limitation per scan.

I thought to automate this process to get a list of open port for each host and dump the output in a single file. You just need to have perl installed on your machine to see how this works. Here’s a perl script to automate 
NMAP scan:

open FH, "ipadr.txt" or die $!;
my $line = <FH>;
my $s1="-sS -sV -P0"; #place your nmap scan command here
my $ip;
$file = ipadr.txt;
open (file) or die $!;
foreach $line (<file>)
{
chomp($line);
$ip=$line
$str="nmap $s1 $ip";
print "IP is:\t$str\n";
system($str);
}
close FH or die $!;

How to Use:

1.       Install perl from here
2.       Create a file named “ipadr.txt” and dump your entire IP list here; one entry on each line. For ex:

10.0.0.1
10.0.0.2
10.0.0.3

3.       Copy the above script in a textpad and save as nmap.pl
4.       Place nmap.pl and ipadr.txt in same folder. Ex: C:\Auto_NMAP
5.       Go to command prompt and browse till C:\Auto_NMAP.
6.       Fire command:

perl nmap.pl>output.txt

7.      Output.txt file will be created in the same folder and your entire nmap results will be dumped here.

Furthermore, you can use this script to run any NMAP command and get the output dumped in a single file. For running other commands you just need to edit below line:

my $s1="-sS -sV -P0";

Happy Scanning!!!

1 comment: