SQL Injection in IPv6 Address Search functionality via address parameter*
A SQL injection vulnerability exists in the ajax_table.php endpoint. The application fails to properly sanitize or parameterize user input when processing IPv6 address searches. Specifically, the address parameter is split into an address and a prefix, and the prefix portion is directly concatenated into the SQL query string without validation. This allows an attacker to inject arbitrary SQL commands, potentially leading to unauthorized data access or database manipulation.
The vulnerability is located in the logic that handles address searching when search_type is set to ipv6.
The application takes the user-supplied address parameter and splits it using the / delimiter:
[$address, $prefix] = explode('/', $vars['address']);
If the search_type is ipv6 and the $prefix variable is not empty, the code constructs the SQL query by directly concatenating the $prefix variable into the string:
} elseif ($vars['search_type'] == 'ipv6') {
// ... code omitted ...
if (! empty($prefix)) {
// VULNERABILITY: Direct concatenation of user input
$sql .= " AND ipv6_prefixlen = '$prefix'";
}
}
Unlike the ipv4 block, which attempts to use prepared statements (binding parameters via $param[]), the ipv6 block treats the prefix as a raw string. By supplying an input containing a /, an attacker can populate the $prefix variable. If this variable contains single quotes ('), it breaks out of the string literal in the SQL statement, enabling SQL injection.
Vulnerable Code Snippet:
if (! empty($prefix)) {
$sql .= " AND ipv6_prefixlen = '$prefix'";
}
To reproduce this vulnerability, an attacker can send a specially crafted HTTP POST request to the ajax_table.php endpoint.
Payload breakdown:
search_type=ipv6: Forces the execution flow into the vulnerable elseif block.
address=snow/1nd'":
26.2.0