Skip to content
Open
Show file tree
Hide file tree
Changes from 6 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
45 changes: 45 additions & 0 deletions src/cloud/azure/custom/api.pm
Original file line number Diff line number Diff line change
Expand Up @@ -1149,6 +1149,51 @@ sub azure_list_sqlvms {
return $full_response;
}

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

my $url = $self->{management_endpoint};
$url .= "/" . $options{resource} . "/providers/microsoft.insights/metricDefinitions";
$url .= (defined($options{force_api_version}) && $options{force_api_version} ne '') ? "?api-version=" . $options{force_api_version} : "?api-version=" . $self->{api_version};
return $url;
}

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

my $full_response = [];
my $full_url = $self->azure_list_resource_metrics_set_url(%options);
while (1) {
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');
foreach (@{$response->{value}}) {
push @$full_response, $_;
}

last if (!defined($response->{nextLink}));
$full_url = $response->{nextLink};
}

return $full_response;
}

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

my $url = $self->{management_endpoint} . "/subscriptions/" . $self->{subscription} . "/resourcegroups/" .
$options{resource_group} . "/providers/Microsoft.Network/virtualHubs?api-version=" . $self->{api_version};

return $url;
}

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

my $full_url = $self->azure_list_virtualhubs_set_url(%options);
my $response = $self->request_api(method => 'GET', full_url => $full_url, hostname => '');

return $response->{value};
}

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

Expand Down
39 changes: 39 additions & 0 deletions src/cloud/azure/custom/azcli.pm
Original file line number Diff line number Diff line change
Expand Up @@ -600,6 +600,45 @@ sub azure_get_publicip {
return $self->execute(cmd_options => $cmd_options);
}

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

return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');

my $cmd_options = "monitor metrics list-definitions --resource '$options{resource}' --only-show-errors --output json";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

azure_list_resource_metrics_set_cmd places $options{resource} directly into a shell command string (--resource '$options{resource}'), enabling command/argument injection if resource is untrusted. Use argument arrays or sanitize/encode the value.

Details

✨ AI Reasoning
​A new function returns an Azure CLI command string with the --resource argument directly interpolated from $options{resource} into the command string. If $options{resource} can be controlled by an external user, this direct interpolation into a shell-executed command permits injection of additional CLI options or shell metacharacters. The risk arises where the assembled command is passed to the system execution routine without safe argument separation or sanitization.

🔧 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


return $cmd_options;
}

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

my $cmd_options = $self->azure_list_resource_metrics_set_cmd(%options);
my $raw_results = $self->execute(cmd_options => $cmd_options);

return $raw_results;
}

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

return if (defined($self->{option_results}->{command_options}) && $self->{option_results}->{command_options} ne '');

my $cmd_options = "network vhub list --resource-group '$options{resource_group}' --only-show-errors --output json ";

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

azure_list_virtualhubs_set_cmd concatenates $options{resource_group} and $self->{subscription} into a shell command string; avoid direct interpolation into commands (escape or use safe argument passing).

Details

✨ AI Reasoning
​The newly added function constructs a CLI command with the resource group and subscription values interpolated directly into the command string. If $options{resource_group} or $self->{subscription} are user-controlled, they could include shell metacharacters leading to command injection when executed. There is no escaping or use of safe argument passing in the constructed $cmd_options.

🔧 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

$cmd_options .= " --subscription '$self->{subscription}'" if (defined($self->{subscription}) && $self->{subscription} ne '');

return $cmd_options;
}

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

my $cmd_options = $self->azure_list_virtualhubs_set_cmd(%options);
my $raw_results = $self->execute(cmd_options => $cmd_options);

return $raw_results;
}

1;

__END__
Expand Down
60 changes: 60 additions & 0 deletions src/cloud/azure/network/virtualhub/mode/discovery.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
#
# 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 cloud::azure::network::virtualhub::mode::discovery;

use base qw(cloud::azure::common::discovery);

use strict;
use warnings;

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

$self->{namespace} = 'Microsoft.Network';
$self->{type} = 'virtualHubs';
}

1;

__END__

=head1 MODE

Virtual Hub discovery.

=over 8

=item B<--resource-group>

Specify resource group.

=item B<--location>

Specify location.

=item B<--prettify>

Prettify JSON output.

=back

=cut
76 changes: 76 additions & 0 deletions src/cloud/azure/network/virtualhub/mode/health.pm
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
#
# 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 cloud::azure::network::virtualhub::mode::health;

use base qw(cloud::azure::management::monitor::mode::health);

use strict;
use warnings;

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

$self->{az_resource_namespace} = 'Microsoft.Network';
$self->{az_resource_type} = 'virtualHubs';
}

1;

__END__

=head1 MODE

Check Virtual Hub health status.

=over 8

=item B<--resource>

Set resource name or ID (required).

=item B<--resource-group>

Set resource group (required if resource's name is used).

=item B<--warning-status>

Define the conditions to match for the status to be WARNING (default: '').
You can use the following variables: C<%{status}>, C<%{summary}>.

=item B<--critical-status>

Define the conditions to match for the status to be CRITICAL (default: C<'%{status} =~ /^Unavailable$/'>).
You can use the following variables: C<%{status}>, C<%{summary}>.

=item B<--unknown-status>

Define the conditions to match for the status to be UNKNOWN (default: C<'%{status} =~ /^Unknown$/'>).
You can use the following variables: C<%{status}>, C<%{summary}>.

=item B<--ok-status>

Define the conditions to match for the status to be OK (default: C<'%{status} =~ /^Available$/''>).
You can use the following variables: C<%{status}>, C<%{summary}>.

=back

=cut
Loading