App-WebPerimeterScan
view release on metacpan or search on metacpan
lib/App/WebPerimeterScan/HTTP.pm view on Meta::CPAN
# Purpose: open a TCP or TLS connection.
# Entry: $target from _target.
# Exit: the socket, or undef on failure ($! / SSL_ERROR set).
# Side effects: network connection.
sub _connect :Private
{
my ($self, $target) = @_;
my %common = (
PeerPort => $target->{port},
Timeout => $self->{timeout},
);
# Verification failures are reported by App::WebPerimeterScan::TLS;
# here the response is still wanted so the other checks can run.
return IO::Socket::SSL->new(
%common,
PeerHost => $target->{host},
SSL_hostname => $target->{host},
SSL_verify_mode => SSL_VERIFY_NONE,
) if $target->{scheme} eq 'https';
lib/App/WebPerimeterScan/Ports.pm view on Meta::CPAN
sub _connect_serial :Private
{
my ($host, $ports, $timeout) = @_;
my @open;
for my $port (@{$ports}) {
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => $timeout,
) or next;
# IO::Socket::INET can hand back a socket whose connect is still in
# progress, so a refused port looks open; wait for it to become
# writable before asking how the handshake ended.
push @open, _open_port($port)
if IO::Select->new($sock)->can_write($timeout) && _handshake_ok($sock);
close $sock;
}
lib/App/WebPerimeterScan/Ports.pm view on Meta::CPAN
# Exit: printable, single-line text; '' when the service is silent.
# Side effects: one short TCP connection. Read-only: nothing is sent.
sub _banner :Private
{
my ($host, $port) = @_;
my $sock = IO::Socket::INET->new(
PeerAddr => $host,
PeerPort => $port,
Proto => 'tcp',
Timeout => $config{banner_timeout},
) or return '';
# Silence is a valid answer: many services wait for the client.
my $buffer = '';
sysread($sock, $buffer, $config{banner_bytes})
if IO::Select->new($sock)->can_read($config{banner_timeout});
close $sock;
# One line of printable ASCII, so a banner cannot corrupt a report.
$buffer =~ s/[\r\n]+/ /g;
lib/App/WebPerimeterScan/TLS.pm view on Meta::CPAN
# Entry: $version, if given, is one of @PROBE_VERSIONS.
# Exit: the socket, or undef (SSL_ERROR / $! set).
# Side effects: a TLS handshake.
sub _connect :Private
{
my ($host, $port, $timeout, $version) = @_;
my %args = (
PeerHost => $host,
PeerPort => $port,
Timeout => $timeout,
SSL_hostname => $host,
SSL_verify_mode => SSL_VERIFY_NONE,
);
$args{SSL_version} = $version if $version;
$args{SSL_cipher_list} = $PROBE_CIPHERS{$version} if $version && $PROBE_CIPHERS{$version};
return IO::Socket::SSL->new(%args);
}
# _verify
lib/App/WebPerimeterScan/TLS.pm view on Meta::CPAN
# Entry: as _connect.
# Exit: undef if it verifies, else the reason.
# Side effects: a TLS handshake.
sub _verify :Private
{
my ($class, $host, $port, $timeout) = @_;
my $sock = IO::Socket::SSL->new(
PeerHost => $host,
PeerPort => $port,
Timeout => $timeout,
SSL_hostname => $host,
SSL_verify_mode => SSL_VERIFY_PEER,
SSL_verifycn_name => $host,
SSL_verifycn_scheme => 'http',
);
close $sock if $sock;
return $sock ? undef : (_ssl_error() // $class->i18n('tls.verify_failed'));
}
open STDOUT, '>', File::Spec->devnull;
open STDERR, '>', File::Spec->devnull;
exec("$openssl/openssl", 's_server', '-accept', "127.0.0.1:$port", '-cert', "$dir/c.pem",
'-key', "$dir/k.pem", '-tls1', '-cipher', 'DEFAULT:@SECLEVEL=0', '-www', '-quiet');
exit 1;
}
# Wait for the server to listen.
my $up;
for (1 .. 50) {
last if $up = IO::Socket::INET->new(PeerAddr => '127.0.0.1', PeerPort => $port, Timeout => 1);
select(undef, undef, undef, 0.1);
}
if(!$up) {
kill 'TERM', $pid;
waitpid $pid, 0;
skip 'openssl s_server did not start', 1;
}
close $up;
my $tls = App::WebPerimeterScan::TLS->inspect(host => '127.0.0.1', port => $port, timeout => 3);
( run in 1.718 second using v1.01-cache-2.11-cpan-234fa220139 )