Network/Zmap.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 100% 12 / 12 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« Network/Write.pm ↑ Summary Password/Mirai.pm »
1 #
2 # $Id$
3 #
4 # network::zmap Brik
5 #
6 package Metabrik::Network::Zmap;
7 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 ▶use base qw(Metabrik::Shell::Command Metabrik::System::Package);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 sub brik_properties {
13 return {
14 revision => '$Revision$',
15 tags => [ qw(unstable) ],
16 author => 'GomoR <GomoR[at]metabrik.org>',
17 license => 'http://opensource.org/licenses/BSD-3-Clause',
18 attributes => {
19 datadir => [ qw(datadir) ],
20 device => [ qw(device) ],
21 bandwidth => [ qw(bps) ],
22 rate => [ qw(pps) ],
23 max_targets => [ qw(count) ],
24 max_results => [ qw(count) ],
25 max_runtime => [ qw(seconds) ],
26 probes => [ qw(count) ],
27 cooldown_time => [ qw(seconds) ],
28 },
29 attributes_default => {
30 bandwidth => '4M', # 4 Mbps, 512 kBps
31 probes => 1,
32 cooldown_time => 8,
33 },
34 commands => {
35 install => [ ], # Inherited
36 scan => [ qw(port output|OPTIONAL device|OPTIONAL) ],
37 },
38 require_binaries => {
39 zmap => [ ],
40 },
41 need_packages => {
42 ubuntu => [ qw(zmap) ],
43 debian => [ qw(zmap) ],
44 kali => [ qw(zmap) ],
45 },
46 };
47 }
48  
49 sub brik_use_properties {
50 my $self = shift;
51  
52 return {
53 attributes_default => {
54 device => defined($self->global) && $self->global->device || 'eth0',
55 },
56 };
57 }
58  
59 sub scan {
60 my $self = shift;
61 my ($port, $output, $device) = @_;
62  
63 $device ||= $self->device;
64 $output ||= '-';
65 $self->brik_help_run_undef_arg('scan', $port) or return;
66 $self->brik_help_run_undef_arg('scan', $output) or return;
67 $self->brik_help_run_undef_arg('scan', $device) or return;
68  
69 my $bandwidth = $self->bandwidth;
70 my $rate = $self->rate;
71 my $max_targets = $self->max_targets;
72 my $max_runtime = $self->max_runtime;
73 my $max_results = $self->max_results;
74 my $cooldown_time = $self->cooldown_time;
75 my $probes = $self->probes;
76  
77 my $cmd = "zmap -p $port -i $device -o \"$output\" -P $probes -c $cooldown_time";
78  
79 if (defined($max_targets)) {
80 $cmd .= " -n $max_targets";
81 }
82 elsif (defined($max_results)) {
83 $cmd .= " -N $max_results";
84 }
85 elsif (defined($max_runtime)) {
86 $cmd .= " -t $max_runtime";
87 }
88  
89 if (defined($rate)) {
90 $cmd .= " -r $rate";
91 }
92 elsif (defined($bandwidth)) {
93 $cmd .= " -B $bandwidth";
94 }
95  
96 $self->log->verbose("scan: zmap[$cmd]");
97  
98 return $self->sudo_system($cmd);
99 }
100  
101 1;
102  
103 __END__
« Network/Write.pm ↑ Summary Password/Mirai.pm »