Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Mon 3310 authenticated rce minplay command #7245

Merged
merged 2 commits into from
Mar 5, 2019
Merged
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
27 changes: 19 additions & 8 deletions www/include/configuration/configObject/command/minPlayCommand.php
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
<?php
/*
* Copyright 2005-2015 Centreon
* Centreon is developped by : Julien Mathis and Romain Le Merlus under
* Copyright 2005-2019 Centreon
* Centreon is developed by : Julien Mathis and Romain Le Merlus under
* GPL Licence 2.0.
*
* This program is free software; you can redistribute it and/or modify it under
Expand Down Expand Up @@ -54,12 +54,17 @@

/* Get resources in DB and replace by the value */
while (preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches) and $error_msg == "") {
$DBRESULT = $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");
$DBRESULT = $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER" .
$matches[1] . "\$' LIMIT 1");
$resource = $DBRESULT->fetchRow();
if (!isset($resource["resource_line"])) {
$error_msg .= "\$USER".$matches[1]."\$";
} else {
$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
$resource_def = str_replace(
"@DOLLAR@USER" . $matches[1] . "@DOLLAR@",
$resource["resource_line"],
$resource_def
);
}
}

Expand All @@ -79,12 +84,17 @@
$resource_def = str_replace("@DOLLAR@ARG". $match_id ."@DOLLAR@", $args[$match_id], $resource_def);
$resource_def = str_replace('$', '@DOLLAR@', $resource_def);
if (preg_match("/@DOLLAR@USER([0-9]+)@DOLLAR@/", $resource_def, $matches)) {
$DBRESULT = $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER".$matches[1]."\$' LIMIT 1");
$DBRESULT = $pearDB->query("SELECT resource_line FROM cfg_resource WHERE resource_name = '\$USER" .
$matches[1] . "\$' LIMIT 1");
$resource = $DBRESULT->fetchRow();
if (!isset($resource["resource_line"])) {
$error_msg .= "\$USER".$match_id."\$";
} else {
$resource_def = str_replace("@DOLLAR@USER". $matches[1] ."@DOLLAR@", $resource["resource_line"], $resource_def);
$resource_def = str_replace(
"@DOLLAR@USER" . $matches[1] . "@DOLLAR@",
$resource["resource_line"],
$resource_def
);
}
}
if (preg_match("/@DOLLAR@HOSTADDRESS@DOLLAR@/", $resource_def, $matches)) {
Expand Down Expand Up @@ -116,7 +126,8 @@
/*
* for security reasons, we do not allow the execution of any command unless it is located in path $USER1$
*/
$DBRESULT = $pearDB->query("SELECT `resource_line` FROM `cfg_resource` WHERE `resource_name` = '\$USER1\$' LIMIT 1");
$DBRESULT = $pearDB->query("SELECT `resource_line` FROM `cfg_resource` " .
"WHERE `resource_name` = '\$USER1\$' LIMIT 1");
$resource = $DBRESULT->fetchRow();
$user1Path = $resource["resource_line"];
$pathMatch = str_replace('/', '\/', $user1Path);
Expand All @@ -125,7 +136,7 @@
if (preg_match("/\.\./", $command)) {
$msg = _("Directory traversal detected");
} else {
$msg = exec($command, $stdout, $status);
$msg = exec(escapeshellcmd($command), $stdout, $status);
$msg = join("<br/>", $stdout);
if ($status == 1) {
$status = _("WARNING");
Expand Down