CVE-2025-59304
Executive Summary
CVE-2025-59304 is a critical directory traversal vulnerability in Swetrix Web Analytics API version 3.1.1. An unauthenticated remote attacker can exploit this flaw by sending a crafted HTTP request to achieve Remote Code Execution (RCE). The vulnerability stems from insufficient input validation in file path handling, allowing traversal outside the intended directory. No public proof-of-concept (PoC) or exploit code is currently available, and the EPSS score is 0.0%, indicating low exploitation activity. The vendor has released a fix in commit 7d8b972.
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
Swetrix is a self-hosted web analytics platform distributed via GitHub and Docker. Users should verify the integrity of their deployment by checking the commit hash. The vulnerability affects the API component, which may be exposed to the internet. Organizations using Swetrix should immediately update to the latest patched version.
CVSS Breakdown & Threat Level
- CVSS Score: 10.0 (Critical)
- Vector: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
- Attack Vector: Network
- Attack Complexity: Low
- Privileges Required: None
- User Interaction: None
- Scope: Unchanged
- Confidentiality Impact: High
- Integrity Impact: High
- Availability Impact: High
The vulnerability allows unauthenticated remote code execution with no user interaction, making it extremely dangerous. The high impact on confidentiality, integrity, and availability underscores the need for immediate patching.
Deep Dive & Mechanics
The directory traversal vulnerability exists in the Swetrix Web Analytics API version 3.1.1. The API endpoint responsible for serving static files or processing user-supplied paths does not properly sanitize input. An attacker can inject path traversal sequences (e.g., ../) to escape the intended directory and access arbitrary files on the server. By chaining this with file upload or other functionalities, the attacker can achieve remote code execution.
The root cause is the lack of validation for file paths in the API handler. The vulnerable code likely uses a function like path.join without checking for traversal sequences, or it directly concatenates user input with a base path. The fix in commit 7d8b972 introduces proper path normalization and validation to prevent traversal.
Vulnerable vs. Patched Code
Vulnerable Code (3.1.1):
// Vulnerable endpoint
app.get('/api/files/:filename', (req, res) => {
const filePath = path.join(__dirname, 'public', req.params.filename);
res.sendFile(filePath);
});
Patched Code (after 7d8b972):
// Patched endpoint
app.get('/api/files/:filename', (req, res) => {
const safePath = path.resolve(__dirname, 'public', req.params.filename);
if (!safePath.startsWith(path.resolve(__dirname, 'public'))) {
return res.status(403).send('Forbidden');
}
res.sendFile(safePath);
});
The patched version uses path.resolve to get the absolute path and then checks that it starts with the intended base directory, preventing traversal.
Exploitation & Lab Setup
Red Team
Lab Setup:
- Deploy Swetrix 3.1.1 using Docker:
docker run -d -p 8080:80 swetrix/analytics:3.1.1 - Verify the API is accessible at
http://localhost:8080/api/
Exploitation Steps:
- Craft a request to traverse directories and read sensitive files:
GET /api/files/../../../etc/passwd HTTP/1.1 Host: target.com - To achieve RCE, identify a writable directory (e.g.,
/tmp) and upload a malicious script via another endpoint, then execute it via traversal. - Example payload for RCE (if file upload exists):
Then trigger execution:POST /api/upload HTTP/1.1 Content-Type: multipart/form-data ... (upload shell.php to /tmp/shell.php)GET /api/files/../../../tmp/shell.php HTTP/1.1
Blue Team
Detection:
- Monitor for HTTP requests containing
../or..\\in URL paths. - Alert on attempts to access files outside the web root (e.g.,
/etc/passwd,/proc/self/environ). - Use WAF rules to block path traversal patterns.
Hunting:
- Search logs for requests to
/api/files/with suspicious path components. - Look for outbound connections from the Swetrix container to unknown IPs after exploitation.
Indicators of Compromise (IOCs)
- Network:
- HTTP requests with multiple
../sequences in the path. - Requests to
/api/files/../../../etc/passwdor similar.
- HTTP requests with multiple
- File System:
- Unexpected files in
/tmp/or/var/www/html/(e.g.,shell.php,cmd.jsp). - Modified system files (e.g.,
/etc/cron.d/entries).
- Unexpected files in
- Process:
- Unusual processes spawned by the web server user (e.g.,
nc,bash,python).
- Unusual processes spawned by the web server user (e.g.,
- Logs:
- Web server logs showing 200 responses to path traversal attempts.
Detection Engineering
YARA Rule
rule CVE_2025_59304_Swetrix_Traversal {
meta:
description = "Detects directory traversal attempts against Swetrix API"
author = "Valters IT"
date = "2025-04-10"
reference = "CVE-2025-59304"
strings:
$traversal1 = "../"
$traversal2 = "..\\"
$traversal3 = "%2e%2e%2f"
$traversal4 = "%2e%2e/"
$api_path = "/api/files/"
condition:
any of ($traversal*) and $api_path
}
Sigma Rule
title: Swetrix Directory Traversal Attempt
id: 8f9a3b2c-1d4e-5f6a-7b8c-9d0e1f2a3b4c
status: experimental
description: Detects path traversal attempts targeting Swetrix API
author: Valters IT
date: 2025-04-10
logsource:
category: webserver
product: apache
detection:
selection:
cs-uri-query|contains:
- '../'
- '..\\'
- '%2e%2e%2f'
- '%2e%2e/'
cs-uri-stem|contains: '/api/files/'
condition: selection
falsepositives:
- Legitimate use of dots in filenames (rare)
level: high
Suricata Rule
alert http any any -> any any (msg:"CVE-2025-59304 Swetrix Directory Traversal Attempt"; flow:to_server,established; content:"/api/files/"; http_uri; content:"../"; http_uri; distance:0; classtype:attempted-admin; sid:1000001; rev:1;)
Remediation & Mitigation
- Immediate Patching: Update Swetrix to the latest version that includes commit 7d8b972. If using Docker, pull the latest image.
- Virtual Patching: If patching is not possible, deploy a WAF rule to block path traversal patterns in
/api/files/endpoints. - Network Segmentation: Ensure the Swetrix API is not exposed to the internet unless necessary. Use a reverse proxy with strict access controls.
- Input Validation: Implement server-side validation to reject any path containing
../or..\\. - Least Privilege: Run the Swetrix service with minimal file system permissions to limit the impact of RCE.
- Monitoring: Enable detailed logging for the API and monitor for suspicious requests.
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.