| 1 | #!/usr/bin/env perl | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use autodie qw(:all); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 21 | ▶ | use FindBin qw($Bin); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | # Run from a checkout without installing: prefer the lib/ beside this script. | ||||||||||||||||||||||||||||||||||||||||||
| 10 | 21 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 21 | ▶ | unshift @INC, "$Bin/../lib" if -d "$Bin/../lib/App/WebPerimeterScan"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | } | ||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 21 | ▶ | use Getopt::Long; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 21 | ▶ | use POSIX qw(strftime); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 21 | ▶ | use Readonly; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 21 | ▶ | use App::WebPerimeterScan; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 21 | ▶ | use App::WebPerimeterScan::I18N; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | 21 | ▶ | use App::WebPerimeterScan::Ports; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 21 | 21 | ▶ | use App::WebPerimeterScan::Report; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 21 | ▶ | use App::WebPerimeterScan::Scope; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | # -v and -V must stay distinct; Getopt::Long ignores case by default. | ||||||||||||||||||||||||||||||||||||||||||
| 25 | 21 | Getopt::Long::Configure(qw(no_ignore_case)); | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | # Exit statuses, as documented in the usage text. | ||||||||||||||||||||||||||||||||||||||||||
| 28 | 21 | Readonly::Scalar my $EXIT_CLEAN => 0; | |||||||||||||||||||||||||||||||||||||||||
| 29 | 21 | Readonly::Scalar my $EXIT_FINDING => 1; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 21 | Readonly::Scalar my $EXIT_USAGE => 2; | |||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||
| 32 | 21 | Readonly::Hash my %FORMAT => ( | |||||||||||||||||||||||||||||||||||||||||
| 33 | text => \&App::WebPerimeterScan::Report::as_text, | ||||||||||||||||||||||||||||||||||||||||||
| 34 | json => \&App::WebPerimeterScan::Report::as_json, | ||||||||||||||||||||||||||||||||||||||||||
| 35 | html => \&App::WebPerimeterScan::Report::as_html, | ||||||||||||||||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||||||||||||||
| 38 | # --fail-on accepts every severity, plus "never". | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 21 | Readonly::Scalar my $NEVER => 'never'; | |||||||||||||||||||||||||||||||||||||||||
| 40 | 21 | Readonly::Hash my %FAIL_ON => map { $_ => 1 } @App::WebPerimeterScan::Findings::SEVERITIES, $NEVER; | |||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | 21 | Readonly::Scalar my $MIN_PORT => 1; | |||||||||||||||||||||||||||||||||||||||||
| 43 | 21 | Readonly::Scalar my $MAX_PORT => 65_535; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 21 | Readonly::Scalar my $PORT_SEPARATOR => qr/[,\s]+/; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 21 | my %opt = ( | |||||||||||||||||||||||||||||||||||||||||
| 47 | format => 'text', | ||||||||||||||||||||||||||||||||||||||||||
| 48 | fail_on => 'high', | ||||||||||||||||||||||||||||||||||||||||||
| 49 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | GetOptions( | ||||||||||||||||||||||||||||||||||||||||||
| 52 | 'scope|s=s' => \$opt{scope}, | ||||||||||||||||||||||||||||||||||||||||||
| 53 | 'authorized|authorised' => \$opt{authorized}, | ||||||||||||||||||||||||||||||||||||||||||
| 54 | 'format|f=s' => \$opt{format}, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 'output|o=s' => \$opt{output}, | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 'ports=s' => \$opt{ports}, | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 'docroot=s@' => \$opt{docroot}, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 'source=s@' => \$opt{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 'timeout=i' => \$opt{timeout}, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | 'connect-timeout=i' => \$opt{connect_timeout}, | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 'delay=f' => \$opt{delay}, | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 'depth|d=i' => \$opt{depth}, | ||||||||||||||||||||||||||||||||||||||||||
| 63 | 'max-urls=i' => \$opt{max_urls}, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | 5 | ▶ | 'no-path-probes' => sub { $opt{path_probes} = 0 }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 65 | 'reflection-probe' => \$opt{reflection}, | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 'allow-private' => \$opt{allow_private}, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 'dry-run' => \$opt{dry_run}, | ||||||||||||||||||||||||||||||||||||||||||
| 68 | 'fail-on=s' => \$opt{fail_on}, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 'color|colour!' => \$opt{color}, # either spelling, and --no-colour | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 'verbose|v' => \$opt{verbose}, | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 'help|h' => \$opt{help}, | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 'version|V' => \$opt{version}, | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 21 | ▶ | ) or usage($EXIT_USAGE); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 20 | ▶ | usage($EXIT_CLEAN) if $opt{help}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | 19 | ▶ | if($opt{version}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 78 | 2 | print msg('cli.version', { version => $App::WebPerimeterScan::VERSION }), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | exit $EXIT_CLEAN; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Every option is checked before anything is sent: a typo in --fail-on used | ||||||||||||||||||||||||||||||||||||||||||
| 83 | # to be noticed only after the whole scan had run. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 17 | ▶ | usage($EXIT_USAGE) unless $opt{scope}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | 16 | ▶ | fail('cli.bad_format') unless $FORMAT{ $opt{format} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 86 | 15 | ▶ | fail('cli.bad_fail_on') unless $FAIL_ON{ $opt{fail_on} }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 14 | my $ports = parse_ports($opt{ports}); | |||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | 11 | for my $option (qw(docroot source)) { | |||||||||||||||||||||||||||||||||||||||||
| 91 | 21 | ▶ | for my $dir (@{ $opt{$option} || [] }) { | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$opt{$option} || []
MC/DC100%1/1
$opt{$option} || []
$opt{$option}
Truth table100%2/2
A
A= $opt{$option}
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | ▶ | fail('cli.not_directory', { option => $option, dir => $dir }) unless -d $dir; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | 9 | ▶ | my $scope = eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 9 | ▶ | App::WebPerimeterScan::Scope->new(allow_private => $opt{allow_private} ? 1 : 0)->load_file($opt{scope}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | } or fail_with($@); | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 8 | ▶ | if($opt{dry_run}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | 1 | dry_run($scope, $ports); | |||||||||||||||||||||||||||||||||||||||||
| 102 | 1 | exit $EXIT_CLEAN; | |||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 7 | ▶ | unless($opt{authorized}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 106 | 1 | print STDERR msg('cli.unauthorized'); | |||||||||||||||||||||||||||||||||||||||||
| 107 | 1 | exit $EXIT_USAGE; | |||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Only the options actually given are passed, so the defaults live in one | ||||||||||||||||||||||||||||||||||||||||||
| 111 | # place: %App::WebPerimeterScan::config. | ||||||||||||||||||||||||||||||||||||||||||
| 112 | my %scan_options = ( | ||||||||||||||||||||||||||||||||||||||||||
| 113 | scope => $scope, | ||||||||||||||||||||||||||||||||||||||||||
| 114 | ports => $ports, | ||||||||||||||||||||||||||||||||||||||||||
| 115 | docroots => $opt{docroot}, | ||||||||||||||||||||||||||||||||||||||||||
| 116 | source_dirs => $opt{source}, | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 36 | ▶ | (map { defined $opt{$_} ? ($_ => $opt{$_}) : () } qw(timeout connect_timeout delay depth max_urls path_probes)), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 118 | 6 | ▶ | (map { $opt{$_} ? ($_ => 1) : () } qw(reflection verbose)), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 6 | delete @scan_options{ grep { !defined $scan_options{$_} } keys %scan_options }; | |||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | 6 | my $scanner = App::WebPerimeterScan->new(%scan_options); | |||||||||||||||||||||||||||||||||||||||||
| 123 | 6 | my $findings = $scanner->run; | |||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | my $rendered = $FORMAT{ $opt{format} }->($findings, | ||||||||||||||||||||||||||||||||||||||||||
| 126 | version => "$App::WebPerimeterScan::VERSION", | ||||||||||||||||||||||||||||||||||||||||||
| 127 | generated => strftime('%Y-%m-%dT%H:%M:%SZ', gmtime), | ||||||||||||||||||||||||||||||||||||||||||
| 128 | scope_source => $scope->source, | ||||||||||||||||||||||||||||||||||||||||||
| 129 | requests => $scanner->http->requests, | ||||||||||||||||||||||||||||||||||||||||||
| 130 | hosts => $scanner->host_reports, | ||||||||||||||||||||||||||||||||||||||||||
| 131 | # Colour is for a terminal; a file or a pipe gets plain text. | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 6 | ▶ | (defined $opt{color} ? (color => $opt{color} ? 1 : 0) : $opt{output} ? (color => 0) : ()), | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | 6 | ▶ | if($opt{output}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 136 | # autodie reports a failed open or close with the file name and reason. | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 1 | open my $fh, '>', $opt{output}; | |||||||||||||||||||||||||||||||||||||||||
| 138 | 1 | print {$fh} $rendered; | |||||||||||||||||||||||||||||||||||||||||
| 139 | 1 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 140 | 1 | ▶ | print msg('cli.written', { file => $opt{output} }), "\n" unless $opt{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 141 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 142 | 5 | print $rendered; | |||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 6 | ▶ | exit $EXIT_CLEAN if $opt{fail_on} eq $NEVER; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | ▶ | exit(@{ $findings->at_or_above($opt{fail_on}) } ? $EXIT_FINDING : $EXIT_CLEAN); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # msg | ||||||||||||||||||||||||||||||||||||||||||
| 149 | # Purpose: catalogue text for the command line. | ||||||||||||||||||||||||||||||||||||||||||
| 150 | # Entry: as App::WebPerimeterScan::I18N::i18n. | ||||||||||||||||||||||||||||||||||||||||||
| 151 | # Exit: the rendered string. | ||||||||||||||||||||||||||||||||||||||||||
| 152 | # Side effects: none. | ||||||||||||||||||||||||||||||||||||||||||
| 153 | sub msg | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 25 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
msg: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 155 | 25 | my ($key, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||||||||||||||||
| 157 | 25 | return App::WebPerimeterScan::I18N->i18n($key, $args); | |||||||||||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | # fail | ||||||||||||||||||||||||||||||||||||||||||
| 161 | # Purpose: report a usage or setup error and exit 2. | ||||||||||||||||||||||||||||||||||||||||||
| 162 | # Entry: $key is a catalogue key. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | # Exit: never returns. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | # Side effects: prints to STDERR; exits. | ||||||||||||||||||||||||||||||||||||||||||
| 165 | sub fail | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 7 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | 7 | my ($key, $args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | 7 | print STDERR msg('cli.error', { error => msg($key, $args) }), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 170 | 7 | exit $EXIT_USAGE; | |||||||||||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # fail_with | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # Purpose: report an exception as a setup error and exit 2. | ||||||||||||||||||||||||||||||||||||||||||
| 175 | # Entry: $error is $@. | ||||||||||||||||||||||||||||||||||||||||||
| 176 | # Exit: never returns. | ||||||||||||||||||||||||||||||||||||||||||
| 177 | # Side effects: prints to STDERR; exits. | ||||||||||||||||||||||||||||||||||||||||||
| 178 | sub fail_with | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fail_with: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 180 | 1 | my ($error) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 1 | print STDERR msg('cli.error', { error => App::WebPerimeterScan::I18N::clean_error($error) }), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 183 | 1 | exit $EXIT_USAGE; | |||||||||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # parse_ports | ||||||||||||||||||||||||||||||||||||||||||
| 187 | # Purpose: turn --ports into a list of port numbers. | ||||||||||||||||||||||||||||||||||||||||||
| 188 | # Entry: $list is the option value or undef. | ||||||||||||||||||||||||||||||||||||||||||
| 189 | # Exit: arrayref of integers, or undef for the default list. | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # Side effects: exits 2 on a value that is not a port number. | ||||||||||||||||||||||||||||||||||||||||||
| 191 | sub parse_ports | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 14 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_ports: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 14 | my ($list) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 14 | ▶ | return undef unless defined $list; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 10 | my @ports = grep { length } split $PORT_SEPARATOR, $list; | |||||||||||||||||||||||||||||||||||||||||
| 198 | 10 | for my $port (@ports) { | |||||||||||||||||||||||||||||||||||||||||
| 199 | 12 | ▶ | fail('cli.bad_port', { port => $port }) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
$port =~ /\A\d+\z/ and $port >= $MIN_PORT and $port <= $MAX_PORT
$port =~ /\A\d+\z/ and $port >= $MIN_PORT
MC/DC100%3/3
$port =~ /\A\d+\z/ and $port >= $MIN_PORT and $port <= $MAX_PORT
$port =~ /\A\d+\z/
$port >= $MIN_PORT
$port <= $MAX_PORT
Truth table100%4/4
A and B and C
A= $port =~ /\A\d+\z/B= $port >= $MIN_PORTC= $port <= $MAX_PORT
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | unless $port =~ /\A\d+\z/ && $port >= $MIN_PORT && $port <= $MAX_PORT; | ||||||||||||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 7 | return [ map { $_ + 0 } @ports ]; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | # dry_run | ||||||||||||||||||||||||||||||||||||||||||
| 207 | # Purpose: show what would be scanned without sending anything. | ||||||||||||||||||||||||||||||||||||||||||
| 208 | # Entry: $scope is loaded; $ports from parse_ports. | ||||||||||||||||||||||||||||||||||||||||||
| 209 | # Exit: nothing useful. | ||||||||||||||||||||||||||||||||||||||||||
| 210 | # Side effects: prints to STDOUT; DNS lookups for the private check. | ||||||||||||||||||||||||||||||||||||||||||
| 211 | sub dry_run | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
dry_run: called CC=7 SCAR=21.1
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 1 | my ($scope, $ports) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 1 | print msg('cli.dry_run.header'), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 1 | for my $entry (@{ $scope->hosts }) { | |||||||||||||||||||||||||||||||||||||||||
| 217 | 1 | ▶ | my $where = $entry->{port} ? "$entry->{host}:$entry->{port}" : $entry->{host}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | ▶ | my $key = $scope->is_private_target($entry->{host}) ? 'cli.dry_run.private' : 'cli.dry_run.host'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 1 | print msg($key, { where => $where }), "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 220 | } | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 1 | ▶ | print "\n", msg('cli.dry_run.ports', { ports => join(',', @{ $ports || \@App::WebPerimeterScan::Ports::DEFAULT_PORTS }) }), "\n"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$ports || \@App::WebPerimeterScan::Ports::DEFAULT_PORTS
MC/DC0%0/1
$ports || \@App::WebPerimeterScan::Ports::DEFAULT_PORTS
$ports
Truth table50%1/2
A
A= $ports
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | print msg('cli.dry_run.docroots', { dirs => join(', ', @{ $opt{docroot} }) }), "\n" if $opt{docroot}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | print msg('cli.dry_run.source', { dirs => join(', ', @{ $opt{source} }) }), "\n" if $opt{source}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 227 | } | ||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # usage | ||||||||||||||||||||||||||||||||||||||||||
| 230 | # Purpose: print the usage text and exit. | ||||||||||||||||||||||||||||||||||||||||||
| 231 | # Entry: $status is the exit status. | ||||||||||||||||||||||||||||||||||||||||||
| 232 | # Exit: never returns. | ||||||||||||||||||||||||||||||||||||||||||
| 233 | # Side effects: prints to STDERR; exits. | ||||||||||||||||||||||||||||||||||||||||||
| 234 | sub usage | ||||||||||||||||||||||||||||||||||||||||||
| 235 | 3 | ▶ | { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
usage: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | 3 | my ($status) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||
| 238 | 3 | print STDERR msg('cli.usage'); | |||||||||||||||||||||||||||||||||||||||||
| 239 | 3 | exit $status; | |||||||||||||||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||||||||||||||||
| 242 | __END__ | ||||||||||||||||||||||||||||||||||||||||||