Skip to content

Arbitrary File Read via Parameter Manipulation in ZimaOS

High
LinkLeong published GHSA-hjw2-9gq5-qgwj Oct 24, 2024

Package

https://github.com/IceWhaleTech/ZimaOS/ (ZimaOS)

Affected versions

≤v1.2.4

Patched versions

1.2.5

Description

Summary

The ZimaOS API endpoint http://<Zima_Server_IP:PORT>/v3/file?token=<token>&files=<file_path> is vulnerable to arbitrary file reading due to improper input validation. By manipulating the files parameter, authenticated users can read sensitive system files, including /etc/shadow, which contains password hashes for all users. This vulnerability exposes critical system data and poses a high risk for privilege escalation or system compromise.

Details

The vulnerability occurs because the API endpoint does not validate or restrict file paths provided via the files parameter. An attacker can exploit this by manipulating the file path to access sensitive files outside the intended directory.

PoC

  1. Authenticate to the ZimaOS API and obtain a valid session token.
  2. Use the following request to manipulate the files parameter and read sensitive system files:
    GET http://<Zima_Server_IP:PORT>/v3/file?token=<token>&files=%2Fetc%2Fshadow
    Response
root:$6$abcd1234$...
user1:$6$efgh5678$...

The response includes the contents of the /etc/shadow file, which holds password hashes for system users.

YouTube Video PoC

Unlisted YouTube PoC Link

Impact

  1. Privilege Escalation: The ability to read sensitive system files, such as /etc/shadow, exposes password hashes, which could lead to password cracking and privilege escalation.
  2. Data Exposure: Attackers could access configuration files, database credentials, or other sensitive information stored on the server.
  3. System Compromise: Exposing critical files increases the risk of full system compromise, potentially allowing attackers to gain administrative control over the server.

Recommendation

  1. Input Validation: Implement strict input validation to ensure that the files parameter can only reference files within a safe, predefined directory. Avoid allowing direct input of file paths from the user.
  2. Path Traversal Mitigation:Sanitize the files parameter by removing or blocking special characters such as ../ that may allow directory traversal.Resolve the file path and ensure it is contained within an allowed directory before allowing access.
  3. Access Control: Restrict access to sensitive system files such as /etc/shadow by using file access control mechanisms to ensure that only authorized processes or users can access them.
  4. Logging and Monitoring: Monitor file access attempts for unusual patterns, such as multiple requests for sensitive files, and generate alerts when suspicious activity is detected.

Possible Fix Code:

Here’s an example code snippet that restricts file access to a specific directory and prevents path traversal in Python:

import os

def get_safe_file(file_path):
    # Define the base directory where files are allowed to be read
    base_dir = "/var/safe_directory/"
   
    # Normalize and validate the requested file path
    requested_file = os.path.realpath(os.path.join(base_dir, file_path))
   
    # Check if the file is within the allowed base directory
    if not requested_file.startswith(base_dir):
        return "Access Denied", 403
   
    # Proceed with reading the file
    try:
        with open(requested_file, 'r') as f:
            return f.read(), 200
    except FileNotFoundError:
        return "File Not Found", 404

This code ensures that only files within the /var/safe_directory/ directory can be accessed and prevents traversal outside this directory.

Severity

High

CVSS overall score

This score calculates overall vulnerability severity from 0 to 10 and is based on the Common Vulnerability Scoring System (CVSS).
/ 10

CVSS v3 base metrics

Attack vector
Network
Attack complexity
Low
Privileges required
None
User interaction
None
Scope
Unchanged
Confidentiality
High
Integrity
None
Availability
None

CVSS v3 base metrics

Attack vector: More severe the more the remote (logically and physically) an attacker can be in order to exploit the vulnerability.
Attack complexity: More severe for the least complex attacks.
Privileges required: More severe if no privileges are required.
User interaction: More severe when no user interaction is required.
Scope: More severe when a scope change occurs, e.g. one vulnerable component impacts resources in components beyond its security scope.
Confidentiality: More severe when loss of data confidentiality is highest, measuring the level of data access available to an unauthorized user.
Integrity: More severe when loss of data integrity is the highest, measuring the consequence of data modification possible by an unauthorized user.
Availability: More severe when the loss of impacted component availability is highest.
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:N/A:N

CVE ID

CVE-2024-48931

Weaknesses

Credits