T05 · Unauthorized Access and Privilege Escalation
Error
- Location
- src/agentmesh/hub.py:176
- Finding
- Unauthenticated Agent Registration Enables Identity Replacement and Message Interception<![CDATA[ ## Vulnerability Details **File Location**: `src/agentmesh/hub.py:176-190` **Vulnerability Type**: Unauthenticated registration and public-key replacement **Risk Level**: Critical ### Vulnerable Code ```python if cmd == "REGISTER": agent_id = msg["bundle"]["agent_id"] with self._lock: self._bundles[agent_id] = msg["bundle"] self._agent_socks[agent_id] = conn conn.sendall(b'{"status": "OK"}\n') elif cmd == "GET_BUNDLE": b = self._bundles.get(msg["agent_id"]) conn.sendall((json.dumps({"bundle": b}) + "\n").encode()) elif cmd == "DELIVER": target = msg["envelope"]["to"] with self._lock: s = self._agent_socks.get(target) if s: s.sendall((json.dumps({"cmd": "INCOMING", "envelope": msg["envelope"]}) + "\n").encode()) ``` ### Technical Analysis The hub accepts any `REGISTER` request and directly associates the supplied `agent_id`, public-key bundle, and connection. It does not require authentication, proof of possession of a previously trusted key, administrator approval, or confirmation from an existing registration. Registering an existing identifier silently overwrites both `_bundles[agent_id]` and `_agent_socks[agent_id]`. Other agents obtain public keys from this same unauthenticated directory. Consequently, Ed25519 message signatures do not prevent this attack: recipients verify signatures against the attacker-controlled identity key returned by the compromised directory. ### Attack Path 1. The attacker establishes a TCP connection to the hub. 2. The attacker generates their own Ed25519 and X25519 key pairs. 3. The attacker sends a `REGISTER` command containing the victim's `agent_id` and the attacker's public keys. 4. The server replaces the victim's public bundle and routing socket. 5. A sender calls `GET_BUNDLE` for the victim and receives the attacker's keys. 6. The sender derives a session key using the attacker's X25519 key and encrypts a message intended for the victim. 7. The ...[truncated 765 chars]
- Remediation
- <![CDATA[ ## Remediation Suggestions - Authenticate every registration using a trusted credential or certificate. - Require proof of possession by having the registering agent sign a server-provided challenge. - Reject duplicate agent identifiers unless an authenticated key-rotation protocol is completed. - Pin public-key fingerprints after first verification and alert users to unexpected changes. - Use an authenticated key-transparency mechanism or out-of-band fingerprint verification. - Bind each connection to one authenticated identity and authorize delivery operations against that identity. - Add tests for duplicate registration, unauthorized key replacement, key rotation, and stale-session behavior. ]]>
