Summary
ZAI Shell's P2P terminal sharing feature exposed an unauthenticated TCP socket on port 5757 that allowed remote connections without any access control.
When running in --no-ai mode, a connected attacker could inject arbitrary system commands into the shared session, which may be executed with the host user's privileges if approved without review, bypassing Sentinel safety checks.
Affected context
This vulnerability affects environments where ZAI Shell is used with the P2P terminal sharing feature (share start) prior to version 9.0.3.
The risk is highest when:
- The host user starts a P2P session that listens on TCP port 5757
- The session is reachable over a network (local, corporate, or internet-exposed)
- ZAI Shell is run in
--no-aimode, relying on user approval instead of automated Sentinel checks
In such setups, remote parties can connect to the open socket and inject commands into the user approval workflow.
Exploit preconditions
- Attack surface: Network-exposed TCP port 5757 opened by the P2P terminal sharing feature (
share start). - Required access: Ability to reach the host over the network on port 5757 (no prior authentication required).
- Trigger point: An active ZAI Shell P2P session running in
--no-aimode with terminal sharing enabled. - User interaction: The host user must approve incoming commands, but may do so without carefully reviewing the content.
- Why exploitation is possible: The P2P listener lacks authentication and input origin verification, allowing any remote party to submit arbitrary command strings that, once approved, execute with the host user's privileges and circumvent Sentinel safety protections.
Why this happens
The core issue is the combination of:
- An unauthenticated network endpoint for command submission, and
- Direct mapping of received strings to executable system commands under user control.
This aligns with CWE-94: Improper Control of Generation of Code ('Code Injection'), because the system accepts externally supplied command text over a network socket and uses it as executable logic without robust origin verification, authorization, or additional safety guards when in --no-ai mode.
Conceptually, the feature treats remote, untrusted input as if it were trusted local commands within an interactive session, relying solely on user approval as the last safety barrier.
Potential impact
- Remote execution of arbitrary system commands with the host user's privileges
- Bypass of internal Sentinel safety checks in
--no-aisessions - Unauthorized access to sensitive files and data on the host system
- Installation of malware, persistence mechanisms, or backdoors
- Lateral movement to other systems reachable from the compromised host
- Disruption of services, data tampering, or environment misconfiguration
General mitigation guidance
Effective mitigation involves both design-level controls and operational safeguards:
- Introduce strong authentication for P2P terminal sharing endpoints so only trusted peers can connect.
- Bind P2P sessions to restricted interfaces or private networks to limit unsolicited remote access.
- Implement strict input validation and separation between proposed commands and execution mechanisms.
- Add clear, high-friction confirmation UX for executing remotely supplied commands (e.g., full diff views, highlighting of dangerous patterns).
- Enforce least-privilege execution for the ZAI Shell environment to limit damage if commands are executed.
- Provide configuration options to disable remote command submission entirely or restrict it to read-only collaboration modes.
- Encourage users to review every incoming command thoroughly instead of relying on habitual approval.
How teams detect issues like this
Organizations can detect and monitor for this class of issue using a combination of code and runtime analysis:
- Static analysis and review:
- Flag network listeners that accept command or script content over unauthenticated channels.
- Identify code paths where received strings are passed directly to command execution APIs or shells.
- Review features that expose CLI or terminal control over the network, ensuring they enforce authentication and authorization.
- Policy and configuration enforcement:
- Enforce secure defaults via policy (e.g., P2P sharing disabled or restricted unless authenticated).
- Integrate secure coding guidelines for interactive agents and remote collaboration features.
- Runtime monitoring:
- Monitor for unexpected listeners on port 5757 (or similar collaboration ports) on production endpoints.
- Log and review remote commands executed through P2P sessions, correlating with user approvals and session context.
- Automated security tooling (SAST/DAST) can be configured to highlight unauthenticated command channels and high-risk remote execution flows during development and testing.

