CVE-2022-46169 漏洞利用:Cacti 版本早于 1.2.3
此处,remote_client_authorized 函数检查 poller 表中的客户端主机名以进行授权
function remote_client_authorized() {
// ...
$client_addr = get_client_addr();
// ...
$client_name = gethostbyaddr($client_addr);
// ...
$pollers = db_fetch_assoc('SELECT * FROM poller', true, $poller_db_cnn_id);
foreach($pollers as $poller) {
if (remote_agent_strip_domain($poller['hostname']) == $client_name) {
return true;
// ...
get_client_addr 函数用于获取客户端地址,攻击者可以在确定 IP 地址时修改该地址。它使用 IP 解析对应的主机名,并检查 poller 表中是否包含该主机名的条目,从而授权客户端。
<?php
// ...
function get_client_addr($client_addr = false) {
$http_addr_headers = array(
// ...
'HTTP_X_FORWARDED',
'HTTP_X_FORWARDED_FOR',
'HTTP_X_CLUSTER_CLIENT_IP',
'HTTP_FORWARDED_FOR',
'HTTP_FORWARDED',
'HTTP_CLIENT_IP',
'REMOTE_ADDR',
);
$client_addr = false;
foreach ($http_addr_headers as $header) {
// ...
$header_ips = explode(',', $_SERVER[$header]);
foreach ($header_ips as $header_ip) {
// ...
$client_addr = $header_ip;
break 2;
}
}
return $client_addr;
}
因此,修改请求头允许我们绕过身份验证。
此外,这里使用了未经处理的用户输入来执行外部命令
// ... retrieve poller items from database ...
foreach($items as $item) {
switch ($item['action']) {
// ...
case POLLER_ACTION_SCRIPT_PHP: /* script (php script server) */
// ...
$cactiphp = proc_open(read_config_option('path_php_binary') . ' -q ' . $config['base_path'] . '/script_server.php realtime ' . $poller_id, $cactides, $pipes);
配置在确定客户端 IP 时应使用哪些 HTTP 头
由于 poller_id 值需要是整数,因此在传递给 proc_open 之前应验证它