kimi-k2-poc / tool_declaration_ts.py
applexml's picture
Upload 4 files
5113b0c verified
"""
Tool Declaration Module - Optional support file for Kimi tokenizer
EXO's tokenizer loader optionally loads this file first via importlib.util.spec_from_file_location.
This demonstrates how arbitrary Python can be executed at model load time.
"""
from pathlib import Path
from datetime import datetime
import json
# This code executes during model load before tokenization_kimi.py
print("[TOOL_DECLARATION_TS] Executed before tokenizer instantiation")
# Log execution for audit trail
log_file = Path("/tmp/exo_tool_declaration_log.txt")
log_file.write_text(
f"Tool declaration executed at {datetime.now().isoformat()}\n"
f"This proves module-level code execution via importlib.util.exec_module()\n"
)
class ToolDeclaration:
"""Stub tool declaration for compatibility"""
def __init__(self):
self.tools = []
@staticmethod
def from_file(path):
return ToolDeclaration()
# Any code here runs at import/exec time, not just on instantiation
# This is key to the RCE: EXO doesn't just load a harmless config,
# it executes arbitrary Python at module initialization