Skip to content
XSS Write-up Advanced

It’s a (SNMP) Trap: Gaining Code Execution on LibreNMS

LibreNMS versions up to 22.10.0 contain an unauthenticated stored XSS vulnerability in the eventlog when SNMP is enabled, because the HPFault trap handler uses an attacker-controlled value for the event type without encoding. An attacker can send a spoofed SNMP trap to inject JavaScript that executes when an admin views the eventlog, and this can be leveraged via the Alert Template feature to achieve remote code execution.

Stefan Schiller Follow

Published on sonarsource.com

LibreNMS is a fully featured monitoring solution developed in PHP. It is usually deployed at a central position in a company’s network with connectivity to all monitored hosts.

Stefan Schiller (@scryh_), on sonarsource.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely the event type value from the SNMP trap is not encoded before being inserted into the HTML of the eventlog page, and the HPFault handler passes user-controlled data as the event type.

Impact

An unauthenticated attacker could execute arbitrary commands on the LibreNMS server, potentially leading to full infrastructure compromise, though the exploit requires the admin to view the eventlog and the Alert Template feature to be available.

What the attacker needed

SNMP enabled on LibreNMS; Attacker can send spoofed SNMP traps; Admin views the eventlog

The fix

The XSS vulnerability was fixed in LibreNMS version 22.11.0 by encoding the value returned by formatType using htmlspecialchars.

How it was found

  1. Send a spoofed SNMP trap to the LibreNMS server.
  2. The trap injects an XSS payload into the eventlog.
  3. An admin views the eventlog dashboard via the web interface.
  4. The JavaScript payload leverages the Alert Template feature to create a new Blade template.
  5. The Blade template executes arbitrary PHP code, such as establishing a reverse shell.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

LibreNMS is a tool that watches over a company's network. It can receive messages called SNMP traps from devices. The bug is that one type of trap lets an attacker sneak in JavaScript code that runs when an administrator looks at the event log. That code can then be used to run commands on the server.

What is XSS?

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.

More by Stefan Schiller

View all

10 more disclosed reports, best first.

Similar reports

View all

Same bug class and techniques, clearest first.

Cross-site scripting (XSS)

The lesson behind this report.

Script an attacker supplies runs in another user's browser, on the target's origin, with that user's session.