T09 · Insecure Skill Coding Practices
- Location
scripts/ml_model.py:184- Finding
Arbitrary Code Execution Through Untrusted Pickle Model Deserialization
- Content
View full analysis
dict: import pickle with open(path, "rb") as f: return pickle.load(f) ``` `scripts/screener.py:339`: ```python ap.add_argument("--model", help="ML概率模型路径(.pkl),启用ML排序") ``` `scripts/screener.py:369-374`: ```python if args.model: try: from ml_model import load_model ml_model = load_model(args.model) m = ml_model.get("metrics", {}) print(f"{CYAN}ML模型已加载: {args.model}({m.get('backend','?')} AUC={m.get('auc','?')}){RESET}") ``` `scripts/portfolio_backtest.py:72-76`: ```python def add_ml_probs(samples: List[dict], model_path: str = MODEL_FILE) -> List[dict]: """批量计算 ML 上涨概率""" with open(model_path, "rb") as f: bundle = pickle.load(f) ``` ### Technical Analysis Python pickle is an executable object serialization format rather than a passive data format. A crafted pickle can define reduction operations that invoke attacker-selected Python callables during `pickle.load()`. Execution occurs before the application can inspect the returned model bundle or validate expected keys. The `screener.py --model` argument permits the caller to select the file passed directly to `pickle.load()`. No signature, trusted digest, ownership check, path restriction, or safe deserialization mechanism is applied. Catching exceptions around model loading does not mitigate the issue because a malicious reduction payload executes while deserialization is in progress. The same underlying issue exists in the portfolio backtest model-loading function. Although its command-line integration does no ...[truncated 1495 chars]- Remediation
View remediation
