line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package App::pscan::Command::Tcp; |
2
|
1
|
|
|
1
|
|
1217
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw( App::pscan::Scanner App::pscan::Command); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
582
|
|
5
|
1
|
|
|
1
|
|
1401
|
use POE qw(Wheel::SocketFactory Wheel::ReadWrite); |
|
1
|
|
|
|
|
38587
|
|
|
1
|
|
|
|
|
9
|
|
6
|
1
|
|
|
1
|
|
185498
|
use POE::Component::Client::TCP; |
|
1
|
|
|
|
|
2951
|
|
|
1
|
|
|
|
|
36
|
|
7
|
1
|
|
|
1
|
|
922
|
use POE::Filter::Stream; |
|
1
|
|
|
|
|
417
|
|
|
1
|
|
|
|
|
28
|
|
8
|
1
|
|
|
1
|
|
7
|
use App::pscan::Utils; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
939
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
App::pscan::Command::tcp - test the ip with the tcp protocol |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
tcp 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
|
|
|
|
|
|
|
=head1 OPTIONS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
-p or --payload specify a payload to send within the request |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=cut |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
sub options { |
28
|
0
|
|
|
0
|
0
|
|
( "verbose" => "verbose", |
29
|
|
|
|
|
|
|
"p|payload=s" => "payload" |
30
|
|
|
|
|
|
|
); |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub scan() { |
35
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
36
|
0
|
|
|
|
|
|
info 'TCP for ' |
37
|
|
|
|
|
|
|
. $self->{'IP'}->ip() |
38
|
|
|
|
|
|
|
. ' port range: ' |
39
|
|
|
|
|
|
|
. $self->{'first'} . "-" |
40
|
|
|
|
|
|
|
. $self->{'last'}; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
0
|
|
|
|
my $Payload = $self->{'payload'} || ""; |
43
|
0
|
|
|
|
|
|
info 'Payload: '.$Payload; |
44
|
0
|
|
|
|
|
|
do { |
45
|
0
|
|
|
|
|
|
for ( $self->{'first'} .. $self->{'last'} ) { |
46
|
0
|
|
|
|
|
|
my $port = $_; |
47
|
0
|
0
|
|
|
|
|
my $host = $self->{'IP'}->ip() if exists $self->{'IP'}; |
48
|
|
|
|
|
|
|
POE::Component::Client::TCP->new( |
49
|
|
|
|
|
|
|
RemoteAddress => $host, |
50
|
|
|
|
|
|
|
RemotePort => $port, |
51
|
|
|
|
|
|
|
Filter => "POE::Filter::Stream", |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# The client has connected. Display some status and prepare to |
54
|
|
|
|
|
|
|
# gather information. Start a timer that will send ENTER if the |
55
|
|
|
|
|
|
|
# server does not talk to us for a while. |
56
|
|
|
|
|
|
|
Connected => sub { |
57
|
0
|
|
|
0
|
|
|
info "connected to $host:$port ..."; |
58
|
0
|
|
|
|
|
|
$_[HEAP]->{banner_buffer} = []; |
59
|
0
|
|
|
|
|
|
$_[KERNEL]->delay( send_enter => 5 ); |
60
|
|
|
|
|
|
|
}, |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# The connection failed. |
63
|
0
|
|
|
0
|
|
|
ConnectError => sub { |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
#error "could not connect to $host:$port ..."; |
66
|
|
|
|
|
|
|
}, |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
# The server has sent us something. Save the information. Stop |
69
|
|
|
|
|
|
|
# the ENTER timer, and begin (or refresh) an input timer. The |
70
|
|
|
|
|
|
|
# input timer will go off if the server becomes idle. |
71
|
|
|
|
|
|
|
ServerInput => sub { |
72
|
0
|
|
|
0
|
|
|
my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ]; |
73
|
0
|
|
|
|
|
|
notice "got input from $host:$port ..."; |
74
|
0
|
|
|
|
|
|
push @{ $heap->{banner_buffer} }, $input; |
|
0
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$kernel->delay( send_enter => undef ); |
76
|
0
|
|
|
|
|
|
$kernel->delay( input_timeout => 1 ); |
77
|
|
|
|
|
|
|
}, |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
# These are handlers for additional events not included in the |
80
|
|
|
|
|
|
|
# default Server::TCP module. In this example, they handle |
81
|
|
|
|
|
|
|
# timers that have gone off. |
82
|
|
|
|
|
|
|
InlineStates => |
83
|
|
|
|
|
|
|
{ # The server has not sent us anything yet. Send an ENTER |
84
|
|
|
|
|
|
|
# keystroke (really a network newline, \x0D\x0A), and wait |
85
|
|
|
|
|
|
|
# some more. |
86
|
|
|
|
|
|
|
send_enter => sub { |
87
|
0
|
|
|
0
|
|
|
info "sending enter on $host:$port ..."; |
88
|
0
|
0
|
|
|
|
|
$_[HEAP]->{server}->put($Payload) |
89
|
|
|
|
|
|
|
if $_[HEAP]->{server}; # sends enter |
90
|
0
|
|
|
|
|
|
$_[KERNEL]->delay( input_timeout => 5 ); |
91
|
|
|
|
|
|
|
}, |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# The server sent us something already, but it has become idle |
94
|
|
|
|
|
|
|
# again. Display what the server sent us so far, and shut |
95
|
|
|
|
|
|
|
# down. |
96
|
|
|
|
|
|
|
input_timeout => sub { |
97
|
0
|
|
|
0
|
|
|
my ( $kernel, $heap ) = @_[ KERNEL, HEAP ]; |
98
|
0
|
|
|
|
|
|
notice "got input timeout from $host:$port ..."; |
99
|
0
|
|
|
|
|
|
notice ",----- Banner from $host:$port"; |
100
|
0
|
|
|
|
|
|
foreach ( @{ $heap->{banner_buffer} } ) { |
|
0
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
notice "| $_"; |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
# print "| ", unpack("H*", $_), "\n"; |
104
|
|
|
|
|
|
|
} |
105
|
0
|
|
|
|
|
|
notice "`-----"; |
106
|
0
|
|
|
|
|
|
$kernel->yield("shutdown"); |
107
|
|
|
|
|
|
|
}, |
108
|
|
|
|
|
|
|
}, |
109
|
0
|
|
|
|
|
|
); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
} while ( ++$self->{'IP'} ); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
info 'Spawning scans'; |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Run the clients until the last one has shut down. |
116
|
0
|
|
|
|
|
|
$poe_kernel->run(); |
117
|
0
|
|
|
|
|
|
exit; |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
1; |