Skip to content

Commit 046c65c

Browse files
committed
fix(nmap): disable sh interpolation on this plugin
1 parent c674f13 commit 046c65c

File tree

3 files changed

+35
-12
lines changed

3 files changed

+35
-12
lines changed

src/apps/nmap/cli/mode/discovery.pm

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -115,8 +115,9 @@ sub run {
115115
my ($stdout) = $options{custom}->execute_command(
116116
command => 'nmap',
117117
command_options => $self->{option_results}->{nmap_options},
118-
command_options_suffix => $self->{option_results}->{subnet} . ' 2> /dev/null',
119-
timeout => 120
118+
command_options_suffix => $self->{option_results}->{subnet},
119+
timeout => 120,
120+
no_shell_interpretation => 1
120121
);
121122

122123
my $results = $self->decode_xml_response(

src/centreon/plugins/misc.pm

Lines changed: 30 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -177,15 +177,27 @@ sub unix_execute {
177177
} else {
178178
$cmd = 'sudo ' if (defined($options{sudo}));
179179
$cmd .= $options{command_path} . '/' if (defined($options{command_path}));
180-
$cmd .= $options{command} . ' ' if (defined($options{command}));
181-
$cmd .= $options{command_options} if (defined($options{command_options}));
182-
183-
($lerror, $stdout, $exit_code) = backtick(
184-
command => $cmd,
185-
timeout => $options{options}->{timeout},
186-
wait_exit => $wait_exit,
187-
redirect_stderr => $redirect_stderr
188-
);
180+
$cmd .= $options{command} if (defined($options{command}));
181+
$cmd .= ' ' . $options{command_options} if (defined($options{command_options}));
182+
183+
if (defined($options{no_shell_interpretation}) and $options{no_shell_interpretation} ne '') {
184+
my @args = split(' ',$cmd);
185+
($lerror, $stdout, $exit_code) = backtick(
186+
command => $args[0],
187+
arguments => [@args[1.. $#args]],
188+
timeout => $options{options}->{timeout},
189+
wait_exit => $wait_exit,
190+
redirect_stderr => $redirect_stderr
191+
);
192+
}
193+
else {
194+
($lerror, $stdout, $exit_code) = backtick(
195+
command => $cmd,
196+
timeout => $options{options}->{timeout},
197+
wait_exit => $wait_exit,
198+
redirect_stderr => $redirect_stderr
199+
);
200+
}
189201
}
190202

191203
if (defined($options{options}->{show_output}) &&
@@ -863,6 +875,15 @@ Executes a command on Unix and returns the output.
863875
864876
=item * C<timeout> - Timeout for the command execution.
865877
878+
=item * C<wait_exit> - bool.
879+
880+
=item * C<redirect_stderr> - bool.
881+
882+
=item * C<sudo> - bool prepend sudo to the command executed.
883+
884+
=item * C<no_shell_interpretation> - bool don't use sh interpolation on command executed
885+
886+
866887
=back
867888
868889
=back

src/centreon/plugins/script_custom/cli.pm

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,8 @@ sub execute_command {
129129
command => defined($self->{option_results}->{command}) && $self->{option_results}->{command} ne '' ? $self->{option_results}->{command} : $options{command},
130130
command_path => defined($self->{option_results}->{command_path}) && $self->{option_results}->{command_path} ne '' ? $self->{option_results}->{command_path} : $options{command_path},
131131
command_options => $command_options,
132-
no_quit => $options{no_quit}
132+
no_quit => $options{no_quit},
133+
no_shell_interpretation => $options{no_shell_interpretation}
133134
);
134135
}
135136

0 commit comments

Comments
 (0)