remind me of something i wrote long time ago, before nmap added the '-sV' option. Basicly its a perl script that parse nmap results file and grab banner for the ports of interest
here is the code:
#!/usr/bin/perl
# h0ly ju4r3z 4nd b3y0nd
use Socket;
$|=1;
my $program = "nGrab";
my $version = "0.20";
my @banner = (21, 22, 23, 25, 80, 110);
&usage if !@ARGV; &main;
sub main {
while (<>) {
if (/^Interesting ports on.*\((\S+)\):/) {
$ip = $1; $i++;
} foreach $port (@banner) {
if (/^$port\/(\w+)\s+open/) {
$proto = $1; $p++;
&banner($ip, $port, $proto);
}
}
} &stats;
}
sub banner {
my ($ip, $port, $proto) = @_;
print "$ip:$port\t=> ";
socket(SOCK, PF_INET, SOCK_STREAM, getprotobyname($proto)) or die "Couldn't create socket: $!\n";
connect(SOCK, sockaddr_in($port, inet_aton($ip))) or print "Couldn't connect to socket: $!\n";
if ($port != 80) {
$banner =<SOCK>;
close(SOCK);
print $banner;
} else {
send(SOCK, "GET / HTTP/1.0\n\n", 0);
@o = <SOCK>;
close(SOCK);
foreach (@o) {
if (/Server:\s(.*)/) {
$banner = $1;
print $banner;
}
}
}
}
sub stats {
print "\n$program $version scan complete !\n";
print "------------------------------------------------------------------\n";
print "Host => $i\n";
print "Banner => $p\n";
}
sub usage {
print "\n<$program $version> Simple banner grabber for port 21/22/23/25/80/110/143\n";
print "------------------------------------------------------------------\n";
print "credit: <someone\@else.com>\n\n";
print "infos: Grab process portscan results files from nMap and extract\n";
print "\tthe ports banner automaticaly. nGrab is very fast and can\n";
print "\tprocess an entire Class (C) in less than 30 seconds. Speed\n";
print "\tmay vary depending what connection you are currently using\n";
print "\nusage: ngrab.pl <files>\n\n";
exit;
}
:P