line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::pscan::Command::Udp; |
2
|
1
|
|
|
1
|
|
1079
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
35
|
|
3
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw( App::pscan::Scanner App::pscan::Command); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
133
|
|
5
|
1
|
|
|
1
|
|
5
|
use IO::Socket::INET; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
6
|
1
|
|
|
1
|
|
906
|
use POE; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
7
|
1
|
|
|
1
|
|
448
|
use constant DATAGRAM_MAXLEN => 1024; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
56
|
|
8
|
1
|
|
|
1
|
|
5
|
use App::pscan::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
793
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
App::pscan::Command::udp - test the ip with the udp protocol |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
udp scan of a given range of the format of Net::IP and a port range. |
17
|
|
|
|
|
|
|
e.g.: 192.168.1.0/24:80 |
18
|
|
|
|
|
|
|
192.168.1.1:20-90 |
19
|
|
|
|
|
|
|
www.google.it:70-80 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 OPTIONS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
-p or --payload specify a payload to send within the request |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=cut |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub options { |
29
|
0
|
|
|
0
|
0
|
|
( "verbose" => "verbose", |
30
|
|
|
|
|
|
|
"p|payload=s" => "payload" |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub scan { |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
info 'UDP for ' |
37
|
|
|
|
|
|
|
. $self->{'IP'}->ip() |
38
|
|
|
|
|
|
|
. ' port range: ' |
39
|
|
|
|
|
|
|
. $self->{'first'} . "-" |
40
|
|
|
|
|
|
|
. $self->{'last'}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
|
my $Payload = $self->{'payload'} || "This is a test by App::pscan"; |
43
|
0
|
|
|
|
|
|
info 'Payload: ' . $Payload; |
44
|
0
|
|
|
|
|
|
do { |
45
|
0
|
|
|
|
|
|
for ( $self->{'first'} .. $self->{'last'} ) { |
46
|
0
|
|
|
|
|
|
my $port = $_; |
47
|
0
|
|
|
|
|
|
my $host = $self->{'IP'}->ip(); |
48
|
0
|
|
|
|
|
|
POE::Session->create( |
49
|
|
|
|
|
|
|
inline_states => { |
50
|
|
|
|
|
|
|
_start => \&client_start, |
51
|
|
|
|
|
|
|
get_datagram => \&client_read, |
52
|
|
|
|
|
|
|
timed_out => \&timeout |
53
|
|
|
|
|
|
|
}, |
54
|
|
|
|
|
|
|
args => [ $host, $port, $Payload ], |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
} while ( ++$self->{'IP'} ); |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# Run the clients until the last one has shut down. |
61
|
0
|
|
|
|
|
|
POE::Kernel->run(); |
62
|
0
|
|
|
|
|
|
exit; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub client_start { |
66
|
0
|
|
|
0
|
0
|
|
my ( $kernel, $session, $heap, $ip, $port, $Payload ) |
67
|
|
|
|
|
|
|
= @_[ KERNEL, SESSION, HEAP, ARG0, ARG1, ARG2 ]; |
68
|
0
|
|
|
|
|
|
my $socket = IO::Socket::INET->new( Proto => 'udp', Timeout => 4 ); |
69
|
0
|
0
|
|
|
|
|
die "Couldn't create client socket: $!" unless $socket; |
70
|
0
|
|
|
|
|
|
$kernel->select_read( $socket, "get_datagram" ); |
71
|
0
|
|
|
|
|
|
$kernel->delay( timed_out => 4, $socket ); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
#info "Sending '$message' to $ip, waiting for responses"; |
74
|
0
|
|
|
|
|
|
my $server_address = pack_sockaddr_in( $port, inet_aton($ip) ); |
75
|
0
|
0
|
|
|
|
|
if ( my $result = send( $socket, $Payload, 0, $server_address ) ) { |
76
|
0
|
0
|
|
|
|
|
if ( $result == length($Payload) ) { |
77
|
0
|
|
|
|
|
|
info "Message sent to $ip:$port"; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
else { |
80
|
0
|
|
|
|
|
|
die "Trouble sending message: $!"; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub client_read { |
86
|
0
|
|
|
0
|
0
|
|
my ( $kernel, $socket ) = @_[ KERNEL, ARG0 ]; |
87
|
0
|
|
|
|
|
|
my $remote_address |
88
|
|
|
|
|
|
|
= recv( $socket, my $message = "", DATAGRAM_MAXLEN, 0 ); |
89
|
0
|
0
|
|
|
|
|
return unless defined $remote_address; |
90
|
0
|
|
|
|
|
|
my ( $peer_port, $peer_addr ) = unpack_sockaddr_in($remote_address); |
91
|
0
|
|
|
|
|
|
my $human_addr = inet_ntoa($peer_addr); |
92
|
|
|
|
|
|
|
|
93
|
0
|
|
|
|
|
|
notice "(answer) $human_addr:$peer_port ..."; |
94
|
0
|
|
|
|
|
|
notice ",----- Banner from $human_addr:$peer_port"; |
95
|
0
|
|
|
|
|
|
notice "| $message"; |
96
|
0
|
|
|
|
|
|
notice "`-----"; |
97
|
0
|
|
|
|
|
|
$kernel->select_read($socket); |
98
|
0
|
|
|
|
|
|
$kernel->yield("shutdown"); |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
sub timeout { |
103
|
|
|
|
|
|
|
|
104
|
0
|
|
|
0
|
0
|
|
$_[KERNEL]->select_read( $_[ARG0] ); |
105
|
0
|
|
|
|
|
|
$_[KERNEL]->yield("shutdown"); |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
1; |