Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions src/network/ubiquiti/uap/snmp/mode/listradios.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package network::ubiquiti::uap::snmp::mode::listradios;

use base qw(centreon::plugins::mode);

use strict;
use warnings;

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;

$options{options}->add_options(
arguments => {
'filter-name:s' => { name => 'filter_name' },
'filter-radio:s' => { name => 'filter_radio' }
});

return $self;
}

my @labels = ('name', 'radio', 'channel');

sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}

sub manage_selection {
my ($self, %options) = @_;

my $mapping = {
name => { oid => '.1.3.6.1.4.1.41112.1.6.1.1.1.2' },# unifiRadioName
radio => { oid => '.1.3.6.1.4.1.41112.1.6.1.1.1.3' },# unifiRadioRadio
channel => { oid => '.1.3.6.1.4.1.41112.1.6.1.1.1.6' }# unifiRadioCuTotal
};

my $oid_unifiRadioEntry = '.1.3.6.1.4.1.41112.1.6.1.1.1';

my $snmp_result = $options{snmp}->get_table(
oid => $oid_unifiRadioEntry,
start => $mapping->{name}->{oid},
end => $mapping->{channel}->{oid},
);

my $results = {};

foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);

my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);

if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly interpolating --filter-name into /.../ allows regex injection/ReDoS. Escape (quotemeta) or validate the filter before using it in a regex match.

Details

✨ AI Reasoning
​User-provided --filter-name is used directly in a regex to filter radio names. Unvalidated input controlling regex can lead to injection or ReDoS. Prefer escaping or validating the provided pattern.

🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

$result->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(
long_msg => "skipping '" . $result->{name} . "': no matching filter.",
debug => 1
);
next;
}

if (defined($self->{option_results}->{filter_radio}) && $self->{option_results}->{filter_radio} ne '' &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly interpolating --filter-radio into /.../ allows regex injection/ReDoS. Escape (quotemeta) or validate the filter before using it in a regex match.

Details

✨ AI Reasoning
​The code uses --filter-radio directly inside a regex match for radio values. This is user-controlled input used as a regex and can enable regex injection or ReDoS. Use escaping or restrict allowed characters/patterns.

🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

$result->{radio} !~ /$self->{option_results}->{filter_radio}/) {
$self->{output}->output_add(
long_msg => "skipping '" . $result->{radio} . "': no matching filter.",
debug => 1
);
next;
}

$results->{$instance} = {
instance => $instance,
name => $result->{name},
radio => $result->{radio},
channel => $result->{channel}
};
}

return $results;
}

sub run {
my ($self, %options) = @_;

my $results = $self->manage_selection(snmp => $options{snmp});
foreach my $number (sort keys %$results) {
$self->{output}->output_add(long_msg =>
join('', map("[$_: " . $results->{$number}->{$_} . ']', @labels))
);
}

$self->{output}->output_add(
severity => 'OK',
short_msg => 'List radios'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}

sub disco_format {
my ($self, %options) = @_;

$self->{output}->add_disco_format(elements => [ @labels ]);
}

sub disco_show {
my ($self, %options) = @_;

my $results = $self->manage_selection(snmp => $options{snmp});
foreach (sort keys %$results) {
$self->{output}->add_disco_entry(
%{$results->{$_}}
);
}
}

1;

__END__

=head1 MODE

List radios.

=over 8

=item B<--filter-name>

Filter access point name (can be a regexp)

=item B<--filter-radio>

Filter radio (can be a regexp). Example: '^ng$'

=back

=cut
181 changes: 181 additions & 0 deletions src/network/ubiquiti/uap/snmp/mode/listvaps.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,181 @@
#
# Copyright 2024 Centreon (http://www.centreon.com/)
#
# Centreon is a full-fledged industry-strength solution that meets
# the needs in IT infrastructure and application monitoring for
# service performance.
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.

package network::ubiquiti::uap::snmp::mode::listvaps;

use base qw(centreon::plugins::mode);

use strict;
use warnings;

sub new {
my ($class, %options) = @_;
my $self = $class->SUPER::new(package => __PACKAGE__, %options);
bless $self, $class;

$options{options}->add_options(
arguments => {
'filter-name:s' => { name => 'filter_name' },
'filter-radio:s' => { name => 'filter_radio' },
'filter-usage:s' => { name => 'filter_usage' }
});

return $self;
}

my @labels = ('name', 'bss_id', 'ess_id', 'radio', 'state', 'usage');

sub check_options {
my ($self, %options) = @_;
$self->SUPER::init(%options);
}

my $map_state = { 0 => 'down', 1 => 'up' };

sub manage_selection {
my ($self, %options) = @_;

my $mapping = {
name => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.7' },# unifiVapName
radio => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.9' },# unifiVapRadio
bssId => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.2' },# unifiVapBssId
essId => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.6' },# unifiVapEssId
txUp => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.22', map => $map_state },# unifiVapUp
usage => { oid => '.1.3.6.1.4.1.41112.1.6.1.2.1.23' }# unifiVapUsage
};

my $oid_unifiVapEntry = '.1.3.6.1.4.1.41112.1.6.1.2.1';

my $snmp_result = $options{snmp}->get_table(
oid => $oid_unifiVapEntry,
start => $mapping->{bssId}->{oid},
end => $mapping->{usage}->{oid},
);

my $results = {};

foreach my $oid (keys %{$snmp_result}) {
next if ($oid !~ /^$mapping->{name}->{oid}\.(.*)$/);

my $instance = $1;
my $result = $options{snmp}->map_instance(mapping => $mapping, results => $snmp_result, instance => $instance);

if (defined($self->{option_results}->{filter_name}) && $self->{option_results}->{filter_name} ne '' &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly interpolating --filter-name into /.../ allows regex injection/ReDoS. Escape (quotemeta) or validate the filter before using it in a regex match.

Details

✨ AI Reasoning
​The code is attempting to filter SNMP results using user-provided --filter-name, --filter-radio, and --filter-usage values by interpolating them directly into regex matches. This allows untrusted input to control the regex pattern, which can cause regex injection or catastrophic backtracking (ReDoS) and unintended matches. Escaping or validating the input before use or using safe matching APIs would reduce risk.

🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

$result->{name} !~ /$self->{option_results}->{filter_name}/) {
$self->{output}->output_add(
long_msg => "skipping '" . $result->{name} . "': no matching filter.",
debug => 1
);
next;
}

if (defined($self->{option_results}->{filter_radio}) && $self->{option_results}->{filter_radio} ne '' &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly interpolating --filter-radio into /.../ allows regex injection/ReDoS. Escape (quotemeta) or validate the filter before using it in a regex match.

Details

✨ AI Reasoning
​The code filters by radio using user-provided --filter-radio interpolated directly into a regex. This exposes the matching to attacker-controlled patterns (injection or ReDoS). Input should be validated or escaped before building regex patterns.

🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

$result->{radio} !~ /$self->{option_results}->{filter_radio}/) {
$self->{output}->output_add(
long_msg => "skipping '" . $result->{radio} . "': no matching filter.",
debug => 1
);
next;
}

if (defined($self->{option_results}->{filter_usage}) && $self->{option_results}->{filter_usage} ne '' &&

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Directly interpolating --filter-usage into /.../ allows regex injection/ReDoS. Escape (quotemeta) or validate the filter before using it in a regex match.

Details

✨ AI Reasoning
​The code filters by usage using user-provided --filter-usage interpolated directly into a regex. This permits injection of arbitrary regex patterns and potential ReDoS. Use escaping or stricter validation to mitigate.

🔧 How do I fix it?
Use parameterized queries with placeholders, array-based command execution (no shell interpretation), or properly escaped arguments using vetted libraries. Avoid dynamic queries/commands built with user input concatenation.

Reply @AikidoSec feedback: [FEEDBACK] to get better review comments in the future.
Reply @AikidoSec ignore: [REASON] to ignore this issue.
More info

$result->{usage} !~ /$self->{option_results}->{filter_usage}/) {
$self->{output}->output_add(
long_msg => "skipping '" . $result->{radio} . "': no matching filter.",
debug => 1
);
next;
}

my $mac = join('-', uc(unpack("H*", $result->{bssId})) =~ /(..)/g);

$results->{$instance} = {
instance => $instance,
name => $result->{name},
bss_id => $mac,
ess_id => $result->{essId},
radio => $result->{radio},
usage => $result->{usage},
state => $result->{txUp}
};
}

return $results;
}

sub run {
my ($self, %options) = @_;

my $results = $self->manage_selection(snmp => $options{snmp});
foreach my $number (sort keys %$results) {
$self->{output}->output_add(long_msg =>
join('', map("[$_: " . $results->{$number}->{$_} . ']', @labels))
);
}

$self->{output}->output_add(
severity => 'OK',
short_msg => 'List Virtual Access Points'
);
$self->{output}->display(nolabel => 1, force_ignore_perfdata => 1, force_long_output => 1);
$self->{output}->exit();
}

sub disco_format {
my ($self, %options) = @_;

$self->{output}->add_disco_format(elements => [ @labels ]);
}

sub disco_show {
my ($self, %options) = @_;

my $results = $self->manage_selection(snmp => $options{snmp});
foreach (sort keys %$results) {
$self->{output}->add_disco_entry(
%{$results->{$_}}
);
}
}

1;

__END__

=head1 MODE

List virtual access points.

=over 8

=item B<--filter-name>

Filter access point name (can be a regexp)

=item B<--filter-radio>

Filter radio (can be a regexp). Example: '^ng$'

=item B<--filter-usage>

Filter usage (can be a regexp). Example: '^user$'

=back

=cut
Loading