| 1 | package Nmap::Scanner::Util::BannerScanner; | ||||||||||||
| 2 | |||||||||||||
| 3 | =pod | ||||||||||||
| 4 | |||||||||||||
| 5 | =head2 NAME | ||||||||||||
| 6 | |||||||||||||
| 7 | BannerScanner - base class for performing banner scans [DEPRECATED] | ||||||||||||
| 8 | |||||||||||||
| 9 | =cut | ||||||||||||
| 10 | 3 | ▶ | use IO::Socket; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 11 | |||||||||||||
| 12 | 3 | ▶ | use Nmap::Scanner::Scanner; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 13 | 3 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 14 | 3 | ▶ | use vars qw(@ISA); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 15 | |||||||||||||
| 16 | 3 | @ISA = qw(Nmap::Scanner::Scanner); | |||||||||||
| 17 | |||||||||||||
| 18 | 0 | ▶ | sub new { | ||||||||||
|
Subroutine
new: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 19 | 0 | my $class = shift; | |||||||||||
| 20 | 0 | my $self = $class->SUPER::new(); | |||||||||||
| 21 | 0 | return bless $self, $class; | |||||||||||
| 22 | } | ||||||||||||
| 23 | |||||||||||||
| 24 | =pod | ||||||||||||
| 25 | |||||||||||||
| 26 | =head2 regex() | ||||||||||||
| 27 | |||||||||||||
| 28 | Regular expression to use to match the banner in the remote | ||||||||||||
| 29 | system output. | ||||||||||||
| 30 | |||||||||||||
| 31 | =cut | ||||||||||||
| 32 | |||||||||||||
| 33 | 0 | ▶ | sub regex { | ||||||||||
|
Subroutine
regex: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 34 | 0 | ▶ | (defined $_[1]) ? ($_[0]->{REGEX} = $_[1]) : return $_[0]->{REGEX}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 35 | } | ||||||||||||
| 36 | |||||||||||||
| 37 | =pod | ||||||||||||
| 38 | |||||||||||||
| 39 | =head2 send_on_connect() | ||||||||||||
| 40 | |||||||||||||
| 41 | Protocol string to send once a connection to the remote host has been | ||||||||||||
| 42 | successfully made. | ||||||||||||
| 43 | |||||||||||||
| 44 | =cut | ||||||||||||
| 45 | |||||||||||||
| 46 | 0 | ▶ | sub send_on_connect { | ||||||||||
|
Subroutine
send_on_connect: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||
| 47 | 0 | ▶ | (defined $_[1]) ? ($_[0]->{SEND} = $_[1]) : return $_[0]->{SEND}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | =pod | ||||||||||||
| 51 | |||||||||||||
| 52 | =head2 register_scan_complete_event() | ||||||||||||
| 53 | |||||||||||||
| 54 | Pass in a reference to a function that will be called when the banner is | ||||||||||||
| 55 | found. The function will receive three arguments: a reference to self | ||||||||||||
| 56 | (object reference of caller), a reference to an Host object representing | ||||||||||||
| 57 | the remote host, and the banner as captured. | ||||||||||||
| 58 | |||||||||||||
| 59 | =cut | ||||||||||||
| 60 | |||||||||||||
| 61 | 0 | ▶ | sub register_banner_found_event { | ||||||||||
|
Subroutine
register_banner_found_event: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 62 | 0 | ▶ | (defined $_[1]) ? ($_[0]->{CALLBACK} = $_[1]) : return $_[0]->{CALLBACK}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 0 | ▶ | sub scan { | ||||||||||
|
Subroutine
scan: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||
| 66 | |||||||||||||
| 67 | 0 | $_[0]->tcp_syn_scan(); | |||||||||||
| 68 | 0 | $_[0]->register_scan_complete_event(\&banner); | |||||||||||
| 69 | 0 | $_[0]->SUPER::scan(); | |||||||||||
| 70 | |||||||||||||
| 71 | } | ||||||||||||
| 72 | |||||||||||||
| 73 | 0 | ▶ | sub banner { | ||||||||||
|
Subroutine
banner: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 74 | 0 | my $self = shift; | |||||||||||
| 75 | 0 | my $host = shift; | |||||||||||
| 76 | 0 | my $port = $host->get_port_list->get_next(); | |||||||||||
| 77 | my $banner = get_banner( | ||||||||||||
| 78 | $host, $port, $self->{REGEX}, $self->{SEND} | ||||||||||||
| 79 | 0 | ); | |||||||||||
| 80 | |||||||||||||
| 81 | 0 | &{$self->{CALLBACK}}($self, $host, $banner) | |||||||||||
| 82 | 0 | ▶ | if (ref($self->{'CALLBACK'}) eq 'CODE'); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 0 | ▶ | sub get_banner { | ||||||||||
|
Subroutine
get_banner: not called CC=7 SCAR=40.3
Pod
undocumented
| |||||||||||||
| 86 | |||||||||||||
| 87 | 0 | my $host = (shift->addresses())[0]->addr(); | |||||||||||
| 88 | 0 | ▶ | my $port = shift || return; | ||||||||||
|
Condition0%0/2
shift() || (return)
MC/DC0%0/1
shift() || (return)
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 89 | 0 | ▶ | my $regex = shift || '.'; | ||||||||||
|
Condition0%0/2
shift() || '.'
MC/DC0%0/1
shift() || '.'
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||
| 90 | 0 | my $send = shift; | |||||||||||
| 91 | |||||||||||||
| 92 | 0 | $port = $port->portid(); | |||||||||||
| 93 | |||||||||||||
| 94 | 0 | my $server = ""; | |||||||||||
| 95 | 0 | local($_); | |||||||||||
| 96 | |||||||||||||
| 97 | 0 | my $sock = new IO::Socket::INET( | |||||||||||
| 98 | PeerAddr => "$host:$port", | ||||||||||||
| 99 | Timeout => 30 | ||||||||||||
| 100 | ); | ||||||||||||
| 101 | |||||||||||||
| 102 | 0 | ▶ | if (! $sock) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 103 | 0 | print "$host: can't connect: $!\n"; | |||||||||||
| 104 | 0 | return ""; | |||||||||||
| 105 | } | ||||||||||||
| 106 | |||||||||||||
| 107 | 0 | ▶ | if ($send) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 108 | 0 | $sock->print($send); | |||||||||||
| 109 | } | ||||||||||||
| 110 | |||||||||||||
| 111 | 0 | ▶ | while (<$sock>) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 112 | 0 | ▶ | if (/$regex/) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 113 | 0 | $server = $1; | |||||||||||
| 114 | 0 | $server =~ s/\r\n//g; | |||||||||||
| 115 | 0 | $sock->close(); | |||||||||||
| 116 | 0 | last; | |||||||||||
| 117 | } | ||||||||||||
| 118 | } | ||||||||||||
| 119 | |||||||||||||
| 120 | 0 | $sock->close(); | |||||||||||
| 121 | 0 | undef $sock; | |||||||||||
| 122 | |||||||||||||
| 123 | 0 | return $server; | |||||||||||
| 124 | |||||||||||||
| 125 | } | ||||||||||||
| 126 | |||||||||||||
| 127 | 3 | 1; | |||||||||||