1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128
| #!/usr/bin/perl
use lib 'lib';
package OsGuesser;
use Nmap::Scanner::Scanner;
use vars qw(@ISA);
@ISA = qw(Nmap::Scanner::Scanner);
$Nmap::Scanner::DEBUG = 0;
sub new {
my $class = shift;
my $self = $class->SUPER::new();
my $target = $_[0] || die "Need target (host spec/file)!";
$self->{'OS_SCAN_TARGET'} = $target;
$self->tcp_syn_scan();
$self->add_scan_port('1-5000');
$self->guess_os();
$self->register_scan_complete_event(\&complete);
return bless $self, $class;
}
sub scan {
die "Need callback!\n" unless $_[0]->{'CALLBACK'};
my $target = $_[0]->{'OS_SCAN_TARGET'};
if ( -r $target ) {
$_[0]->SUPER::scan_from_file($target);
} else {
$_[0]->add_target($target);
$_[0]->SUPER::scan();
}
}
sub callback {
$_[0]->{'CALLBACK'} = $_[1] || return $_[0]->{'CALLBACK'};
}
sub complete {
&{$_[0]->{'CALLBACK'}}($_[0], $_[1]);
}
1;
use lib 'lib';
use Nmap::Scanner;
$fileout = '>$ARGV[1]';
open(FICHOUT,$fileout) or die "je ne peux ouvrir $fileout : $!\n";
my $os = OsGuesser->new($ARGV[0] ||
die "Missing host to scan or file to scan from!\n$0 host\n");
$os->callback(\&guessed);
$os->scan();
sub guessed {
my $self = shift;
my $host = shift;
my $name = $host->hostname();
my $ip = ($host->addresses())[0]->addr();
my $os = $host->os();
unless ($os) {
print (FICHOUT "Could not guess anything about the OS of $name ($ip)\n");
return;
}
if (scalar($os->osclasses()) > 0) {
print (FICHOUT "OS classes: $name ($ip) could be:\n");
for my $osc ($os->osclasses()) {
print FICHOUT ' * ',
join(' ', $osc->vendor(), ($osc->osgen() || "\b")) .
" (" . $osc->accuracy() . "%)",
"\n";
}
}
if (scalar($os->osmatches()) > 0) {
print (FICHOUT "OS matches: $name ($ip) could be:\n");
for my $m ($os->osmatches()) {
print FICHOUT ' * ', $m->name(), " (" . $m->accuracy() . "%)",
"\n";
}
} else {
print (FICHOUT "OS matches: $name ($ip):\n");
print (FICHOUT " * No matches found\n");
}
my $u = $os->uptime();
if ($u->seconds() > 0) {
print FICHOUT "Uptime: ", ($u->seconds()/(24*60*60)),
" days (",$u->lastboot(),")\n";
}
print FICHOUT "Ports used for OS fingerprint: ";
print FICHOUT join(', ', map { $_->portid() } $os->ports_used());
print FICHOUT "\n";
} |
Partager