diff --git a/pandora_console/ChangeLog b/pandora_console/ChangeLog index 035b24b24a..9c2bf4bef5 100644 --- a/pandora_console/ChangeLog +++ b/pandora_console/ChangeLog @@ -1,3 +1,12 @@ +2014-05-28 Alejandro Gallardo + + * include/functions_snmp.php: Improved the security + on the function "snmp_generate_trap" by escaping the + command arguments. + + * include/functions_snmp_browser.php: Improved the + Windows compatibility of some commands. + 2014-05-28 Sergio Martin * godmode/agentes/configurar_agente.php: Fixed field that diff --git a/pandora_console/include/functions_snmp.php b/pandora_console/include/functions_snmp.php index 257b126959..440bc46aee 100644 --- a/pandora_console/include/functions_snmp.php +++ b/pandora_console/include/functions_snmp.php @@ -25,7 +25,8 @@ * @param string Snmp especific OID. */ function snmp_generate_trap($snmp_host_address, $snmp_community, $snmp_oid, $snmp_agent, $snmp_data, $snmp_type) { - $command = "snmptrap -v 1 -c $snmp_community $snmp_host_address $snmp_oid $snmp_agent $snmp_type $snmp_data 0 2>&1"; + $command = "snmptrap -v 1 -c " . escapeshellarg($snmp_community) . " " . escapeshellarg($snmp_host_address) . " " . escapeshellarg($snmp_oid) . " " + . escapeshellarg($snmp_agent) . " " . escapeshellarg($snmp_type) . " " . escapeshellarg($snmp_data) . " 0 2>&1"; $output = null; exec($command, $output, $return); diff --git a/pandora_console/include/functions_snmp_browser.php b/pandora_console/include/functions_snmp_browser.php index 524202e0a9..f9eceb7246 100644 --- a/pandora_console/include/functions_snmp_browser.php +++ b/pandora_console/include/functions_snmp_browser.php @@ -162,12 +162,24 @@ function snmp_browser_get_tree ($target_ip, $community, $starting_oid = '.', $ve else { $snmpwalk_bin = $config['snmpwalk']; } + + switch (PHP_OS) { + case "WIN32": + case "WINNT": + case "Windows": + $error_redir_dir = 'NUL'; + break; + default: + $error_redir_dir = '/dev/null'; + break; + } + $oid_tree = array('__LEAVES__' => array()); if ($version == "3") { - exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2>/dev/null', $output, $rc); + exec ($snmpwalk_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redir_dir, $output, $rc); } else { - exec ($snmpwalk_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -Cc -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2>/dev/null', $output, $rc); + exec ($snmpwalk_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -Cc -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($starting_oid) . ' 2> ' . $error_redirection, $output, $rc); } //if ($rc != 0) { // return __('No data'); @@ -264,11 +276,23 @@ function snmp_browser_get_oid ($target_ip, $community, $target_oid, $version = ' else { $snmpget_bin = $config['snmpget']; } + + switch (PHP_OS) { + case "WIN32": + case "WINNT": + case "Windows": + $error_redir_dir = 'NUL'; + break; + default: + $error_redir_dir = '/dev/null'; + break; + } + if ($version == "3") { - exec ($snmpget_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($target_oid) . ' 2>/dev/null', $output, $rc); + exec ($snmpget_bin . ' -m ALL -v 3 -u ' . escapeshellarg($snmp3_auth_user) . ' -A ' . escapeshellarg($snmp3_auth_pass) . ' -l ' . escapeshellarg($snmp3_security_level) . ' -a ' . escapeshellarg($snmp3_auth_method) . ' -x ' . escapeshellarg($snmp3_privacy_method) . ' -X ' . escapeshellarg($snmp3_privacy_pass) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($target_oid) . ' 2> ' . $error_redir_dir, $output, $rc); } else { - exec ($snmpget_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -On -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($target_oid) . ' 2>/dev/null', $output, $rc); + exec ($snmpget_bin . ' -m ALL -M +' . escapeshellarg($config['homedir'] . '/attachment/mibs') . ' -On -c ' . escapeshellarg($community) . ' -v ' . escapeshellarg($version) . ' ' . escapeshellarg($target_ip) . ' ' . escapeshellarg($target_oid) . ' 2> ' . $error_redir_dir, $output, $rc); } if ($rc != 0) {