Skip to content
CVE-2026-40217 Microsoft Sentinel · KQL

Detect BerriAI LiteLLM Guardrail Sandbox Escape Code Execution (CVE-2026-40217) in Microsoft Sentinel

Detects exploitation of CVE-2026-40217 in BerriAI LiteLLM (versions released on or before 2026-04-08, affected_versions '<= 2026-04-08'). The POST /guardrails/test_custom_code endpoint runs user-supplied Python inside a sandbox that filters source code with regular expressions. The sandbox can be escaped with CPython bytecode rewriting, which permits arbitrary code execution (CWE-94) in the proxy process. The proxy runs as root in the default Docker image. Reaching the endpoint requires an authenticated proxy-admin credential (master key) in default configurations. NVD also records CWE-420. The LiteLLM proxy listens on default port 4000. This CVE is on the CISA KEV catalog (added 2026-11-18) and has a public proof of concept from X41 D-Sec. Detection focuses on HTTP requests to LiteLLM proxy endpoints that carry code-injection indicators, anomalous child-process spawning from the LiteLLM/uvicorn/gunicorn process tree, and outbound connections from the proxy host indicative of reverse shells.

Based on X41 D-Sec Advisory X41-2026-001 LiteLLM

MITRE ATT&CK

Tactic
Initial Access Execution

KQL Detection Query

Microsoft Sentinel (KQL)
kusto
// df00tech DF00-ce83ab2549 · https://df00tech.com/detections/CVE-2026-40217 · licence: https://df00tech.com/detections/licence
let litellm_hosts = dynamic(["*"]);
let suspicious_paths = dynamic(["/guardrails/test_custom_code","/config/update","/model/new","/callbacks","/sso/key/generate","/user/new","/key/generate","/health/test_connection","/anthropic","/v1/messages"]);
AzureDiagnostics
| where Category == "ApplicationGatewayAccessLog" or ResourceType == "APPLICATIONGATEWAYS"
| extend reqUri = tostring(requestUri_s), method = tostring(httpMethod_s), src = tostring(clientIP_s), status = toint(httpStatus_d)
| where (reqUri has_any (suspicious_paths)) and method in ("POST","PUT","PATCH")
| where (reqUri has_any (dynamic(["custom_code","litellm_settings","callbacks","model_list","__import__","os.system","subprocess","eval(","exec(","litellm_params"])))
| summarize hits = count(), paths = make_set(reqUri, 20), statuses = make_set(status, 20) by src, bin(TimeGenerated, 10m)
| where hits >= 1
| project TimeGenerated, src, hits, paths, statuses
high severity medium confidence

Hunts HTTP POST/PUT/PATCH requests to LiteLLM proxy endpoints (guardrail test, config update, model/new, callbacks) that carry code-injection indicators, as seen in gateway/WAF access logs forwarded to Sentinel.

Data Sources

Azure Application Gateway access logsWAF / reverse-proxy HTTP logsLiteLLM proxy access logs

Required Tables

AzureDiagnostics

False Positives & Tuning

  • Legitimate administrators updating model_list or litellm_settings via /config/update during maintenance windows.
  • Administrators legitimately testing guardrail code via /guardrails/test_custom_code.
  • CI/CD pipelines automating LiteLLM proxy configuration pushes.
  • Security scanners or internal pen-tests probing LiteLLM admin endpoints.

Other platforms for CVE-2026-40217


Testing Methodology

Validate this detection against 3 adversary techniques from Atomic Red Team. Each test below lists the behaviour to exercise and the telemetry you should expect to see. Executable commands and cleanup steps are further down this page.

  1. Test 1 Authenticated POST to LiteLLM guardrail test endpoint

    Expected signal: Proxy access log entry for POST /guardrails/test_custom_code with a body containing custom_code/__import__ payload markers.

  2. Test 2 LiteLLM proxy spawns a shell child process

    Expected signal: ProcessRollup2 / DeviceProcessEvents / auditd record of /bin/sh spawned by a python process whose command line references litellm.

  3. Test 3 LiteLLM proxy reverse-shell network tool execution

    Expected signal: Process start for curl/wget whose parent is a python/gunicorn process running litellm, plus an outbound connection attempt.


Response Playbook

Triage

  1. Confirm the LiteLLM proxy version on the affected host; any build released on or before 2026-04-08 is vulnerable to CVE-2026-40217. Check `pip show litellm` / container image tag.
  2. Review the implicated proxy access logs for POST/PUT/PATCH requests to /guardrails/test_custom_code and other management endpoints from the source IP and determine whether they succeeded (2xx) or carried code-injection payloads.
  3. Inspect the LiteLLM process tree on the host for unexpected child processes (shells, curl/wget, interpreters) spawned by python/uvicorn/gunicorn around the request time.
  4. Determine whether the LiteLLM admin/management channel is reachable from untrusted networks (default port 4000) and whether the master key was enforced on the guardrail endpoint.

Containment

  1. Block inbound access to /guardrails/test_custom_code and other LiteLLM management endpoints at the WAF/reverse-proxy and restrict the proxy admin surface to trusted management networks only.
  2. Isolate the affected host/container if child-process execution or outbound reverse-shell activity is confirmed.
  3. Rotate the LiteLLM master key, provider API keys, and any credentials accessible to the proxy process, as they may have been exfiltrated via the injected code.

Evidence Collection

  1. Capture full proxy access/body logs for all requests from the source IP to management endpoints, including request bodies showing custom_code or injected litellm_settings/callbacks payloads.
  2. Collect the LiteLLM process audit trail (process start events, command lines, loaded config) and container filesystem diff for dropped files.
  3. Preserve the running LiteLLM configuration (config.yaml / DB-stored config) to identify malicious callback or model definitions.

Escalation Criteria

  • !Escalate to IR immediately if a child shell/network-tool process was spawned from the LiteLLM process or outbound connections to attacker infrastructure are observed.
  • !Escalate if provider API keys or the master key were accessible to the compromised process and may have been exfiltrated, triggering credential-rotation and breach-notification workflows.

Investigation Guide

Forensic Artifacts

  • >LiteLLM proxy access logs showing POST requests to /guardrails/test_custom_code, /config/update, /model/new or /callbacks.
  • >Stored LiteLLM configuration (config.yaml or DB config table) containing attacker-added callbacks or model entries.
  • >Process-creation records for child processes of python/uvicorn/gunicorn running LiteLLM.
  • >Outbound network connection logs from the proxy host to unknown destinations.

Tuning Guidance

Baseline legitimate administrators and automation that push LiteLLM config (model_list/litellm_settings/callbacks) or test guardrail code, and allowlist their source IPs so routine calls do not alert. Scope the process-based rules to hosts actually running LiteLLM to reduce noise, and suppress known health-check wrappers that invoke curl/python from the proxy. Lower the threshold and raise severity for any request originating from an external/untrusted network, and treat any confirmed child shell process from the proxy as high-fidelity regardless of volume.


Hunting Queries

Hunts for shell or network-utility child processes spawned by the LiteLLM proxy process, indicating code execution via CVE-2026-40217.

Hunting — KQL
kql
// df00tech DF00-ce83ab2549 · https://df00tech.com/detections/CVE-2026-40217 · licence: https://df00tech.com/detections/licence
DeviceProcessEvents | where InitiatingProcessFileName in~ ("python","python3","uvicorn","gunicorn") | where InitiatingProcessCommandLine has "litellm" | where FileName in~ ("sh","bash","dash","nc","ncat","curl","wget","id","whoami") | project Timestamp, DeviceName, InitiatingProcessCommandLine, FileName, ProcessCommandLine
Hunting — SPL
spl
``` df00tech DF00-ce83ab2549 · https://df00tech.com/detections/CVE-2026-40217 · licence: https://df00tech.com/detections/licence ```
index=linux_audit sourcetype="auditd" (parent_process="*litellm*" OR parent_process_name IN ("uvicorn","gunicorn","python","python3")) process_name IN ("sh","bash","nc","ncat","curl","wget") | table _time host parent_process process_name process

Atomic Red Team Tests

Test 1 Authenticated POST to LiteLLM guardrail test endpoint
linux

Detection exercise for CVE-2026-40217: sends a code-injection payload to the LiteLLM guardrail-testing endpoint, which requires an authenticated master key in default configurations.

Command

bash
curl -s -X POST http://127.0.0.1:4000/guardrails/test_custom_code -H 'Authorization: Bearer sk-litellm-master-key' -H 'Content-Type: application/json' -d '{"custom_code":"def apply_guardrail(inputs, request_data, input_type):\n return {\"rce\": __import__(\"os\").popen(\"id\").read()}","test_input":{"messages":[{"role":"user","content":"test"}]}}'

Cleanup

bash
echo 'no cleanup required'

Expected Telemetry

Proxy access log entry for POST /guardrails/test_custom_code with a body containing custom_code/__import__ payload markers.

Expected Detection

KQL/SPL/Sumo/QRadar/Chronicle access-log rules flag the POST to the guardrail/management endpoint with code-injection indicators.

Test 2 LiteLLM proxy spawns a shell child process
linux

Emulates post-exploitation code execution by causing a shell to be spawned from within the LiteLLM proxy process tree.

Command

bash
python3 -c "import subprocess,sys; sys.argv=['uvicorn','litellm.proxy']; subprocess.run(['/bin/sh','-c','id; whoami'])"

Cleanup

bash
echo 'no cleanup required'

Expected Telemetry

ProcessRollup2 / DeviceProcessEvents / auditd record of /bin/sh spawned by a python process whose command line references litellm.

Expected Detection

Elastic EQL sequence rule and CrowdStrike CQL process rule flag the shell child of the LiteLLM/uvicorn process.

Test 3 LiteLLM proxy reverse-shell network tool execution
linux

Simulates the injected code launching a network utility to establish an outbound reverse shell from the LiteLLM host.

Command

bash
python3 -c "import subprocess,sys; sys.argv=['gunicorn','litellm.proxy']; subprocess.run(['curl','-s','http://127.0.0.1:9/litellm-exfil'])"

Cleanup

bash
echo 'no cleanup required'

Expected Telemetry

Process start for curl/wget whose parent is a python/gunicorn process running litellm, plus an outbound connection attempt.

Expected Detection

Process-based EQL and CQL rules flag the network-tool child of the LiteLLM proxy; outbound connection corroborates reverse-shell activity.

Related Detections