| 1 | package App::pscan::Command::Udp; | ||||||||||||
| 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 IO::Socket::INET; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 6 | 1 | ▶ | use POE; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 7 | 1 | ▶ | use constant DATAGRAM_MAXLEN => 1024; | ||||||||||
|
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::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 | 0 | ▶ | sub options { | ||||||||||
|
Subroutine
options: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 29 | 0 | ( "verbose" => "verbose", | |||||||||||
| 30 | "p|payload=s" => "payload" | ||||||||||||
| 31 | ); | ||||||||||||
| 32 | } | ||||||||||||
| 33 | |||||||||||||
| 34 | 0 | ▶ | sub scan { | ||||||||||
|
Subroutine
scan: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 35 | 0 | my $self = shift; | |||||||||||
| 36 | info 'UDP for ' | ||||||||||||
| 37 | . $self->{'IP'}->ip() | ||||||||||||
| 38 | . ' port range: ' | ||||||||||||
| 39 | . $self->{'first'} . "-" | ||||||||||||
| 40 | 0 | . $self->{'last'}; | |||||||||||
| 41 | |||||||||||||
| 42 | 0 | ▶ | my $Payload = $self->{'payload'} || "This is a test by App::pscan"; | ||||||||||
|
Condition0%0/2
$self->{'payload'} || 'This is a test by App::pscan'
MC/DC0%0/1
$self->{'payload'} || 'This is a test by App::pscan'
$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(); | |||||||||||
| 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 | 0 | ▶ | } while ( ++$self->{'IP'} ); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 59 | |||||||||||||
| 60 | # Run the clients until the last one has shut down. | ||||||||||||
| 61 | 0 | POE::Kernel->run(); | |||||||||||
| 62 | 0 | exit; | |||||||||||
| 63 | } | ||||||||||||
| 64 | |||||||||||||
| 65 | 0 | ▶ | sub client_start { | ||||||||||
|
Subroutine
client_start: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||
| 66 | 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 | ▶ | die "Couldn't create client socket: $!" unless $socket; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | ▶ | if ( my $result = send( $socket, $Payload, 0, $server_address ) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 76 | 0 | ▶ | if ( $result == length($Payload) ) { | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 77 | 0 | info "Message sent to $ip:$port"; | |||||||||||
| 78 | } | ||||||||||||
| 79 | else { | ||||||||||||
| 80 | 0 | die "Trouble sending message: $!"; | |||||||||||
| 81 | } | ||||||||||||
| 82 | } | ||||||||||||
| 83 | } | ||||||||||||
| 84 | |||||||||||||
| 85 | 0 | ▶ | sub client_read { | ||||||||||
|
Subroutine
client_read: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||
| 86 | 0 | my ( $kernel, $socket ) = @_[ KERNEL, ARG0 ]; | |||||||||||
| 87 | 0 | my $remote_address | |||||||||||
| 88 | = recv( $socket, my $message = "", DATAGRAM_MAXLEN, 0 ); | ||||||||||||
| 89 | 0 | ▶ | return unless defined $remote_address; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 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 | 0 | ▶ | sub timeout { | ||||||||||
|
Subroutine
timeout: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||
| 103 | |||||||||||||
| 104 | 0 | $_[KERNEL]->select_read( $_[ARG0] ); | |||||||||||
| 105 | 0 | $_[KERNEL]->yield("shutdown"); | |||||||||||
| 106 | |||||||||||||
| 107 | } | ||||||||||||
| 108 | 1 | 1; | |||||||||||