| 1 | package App::pscan::Command::Tcp; | ||||||||||||
| 2 | 1 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 1 | ▶ | use base qw( App::pscan::Scanner App::pscan::Command); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | 1 | ▶ | use POE qw(Wheel::SocketFactory Wheel::ReadWrite); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use POE::Component::Client::TCP; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use POE::Filter::Stream; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 8 | 1 | ▶ | use App::pscan::Utils; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 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 | 0 | ▶ | sub options { | ||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 28 | 0 | ( "verbose" => "verbose", | |||||||||||
| 29 | "p|payload=s" => "payload" | ||||||||||||
| 30 | ); | ||||||||||||
| 31 | } | ||||||||||||
| 32 | |||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub scan() { | ||||||||||
|
Subroutine
scan: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||
| 36 | info 'TCP for ' | ||||||||||||
| 37 | . $self->{'IP'}->ip() | ||||||||||||
| 38 | . ' port range: ' | ||||||||||||
| 39 | . $self->{'first'} . "-" | ||||||||||||
| 40 | 0 | . $self->{'last'}; | |||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | my $Payload = $self->{'payload'} || ""; | ||||||||||
|
Condition0%0/2
$self->{'payload'} || ''
MC/DC0%0/1
$self->{'payload'} || ''
$self->{'payload'}
Truth table0%0/2
A
A= $self->{'payload'}
| |||||||||||||
| 43 | 0 | info 'Payload: '.$Payload; | |||||||||||
| 44 | do { | ||||||||||||
| 45 | 0 | for ( $self->{'first'} .. $self->{'last'} ) { | |||||||||||
| 46 | 0 | my $port = $_; | |||||||||||
| 47 | 0 | ▶ | my $host = $self->{'IP'}->ip() if exists $self->{'IP'}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | Connected => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 57 | 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 | ▶ | ConnectError => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=0.0
| |||||||||||||
| 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 | 0 | ▶ | ServerInput => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||
| 72 | 0 | my ( $kernel, $heap, $input ) = @_[ KERNEL, HEAP, ARG0 ]; | |||||||||||
| 73 | 0 | notice "got input from $host:$port ..."; | |||||||||||
| 74 | 0 | push @{ $heap->{banner_buffer} }, $input; | |||||||||||
| 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 | 0 | ▶ | send_enter => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 87 | 0 | info "sending enter on $host:$port ..."; | |||||||||||
| 88 | $_[HEAP]->{server}->put($Payload) | ||||||||||||
| 89 | 0 | ▶ | if $_[HEAP]->{server}; # sends enter | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | input_timeout => sub { | ||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||||
| 97 | 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} } ) { | |||||||||||
| 101 | 0 | notice "| $_"; | |||||||||||
| 102 | |||||||||||||
| 103 | # print "| ", unpack("H*", $_), "\n"; | ||||||||||||
| 104 | } | ||||||||||||
| 105 | 0 | notice "`-----"; | |||||||||||
| 106 | 0 | $kernel->yield("shutdown"); | |||||||||||
| 107 | }, | ||||||||||||
| 108 | }, | ||||||||||||
| 109 | 0 | ); | |||||||||||
| 110 | } | ||||||||||||
| 111 | 0 | ▶ | } while ( ++$self->{'IP'} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 1; | |||||||||||