
CVE-2023-38408: Critical Remote Code Execution Vulnerability in OpenSSH
A critical remote code execution vulnerability (CVE-2023-38408) in OpenSSH ssh-agent affects versions prior to 9.3p2 through PKCS#11 feature exploitation. This vulnerability, with a CVSS score of 9.8, enables attackers to execute arbitrary code via SSH agent forwarding and shared library manipulation in enterprise SSH infrastructure.
Reading Time: 8 minutes
TLDR :
- Critical RCE Vulnerability: CVE-2023-38408 affects OpenSSH ssh-agent PKCS#11 feature (pre-9.3p2), allowing attackers to execute arbitrary code via SSH agent forwarding.
- Exploitation Method: Attackers place malicious shared libraries in system paths (e.g., /usr/lib/), leveraging ssh-agent to load them through PKCS#11, bypassing ASLR, PIE, and NX protections.
- High Organizational Risk: Exploitation can lead to credential theft, privilege escalation, lateral movement, and full system compromise, especially in DevOps/CI-CD environments.
- Mitigation Steps: Patch to OpenSSH 9.3p2+, disable unnecessary agent forwarding, restrict PKCS#11 module usage, and monitor ssh-agent behavior.
- AccuKnox Protection: Provides runtime enforcement, SSH activity monitoring, microsegmentation, and Zero Trust policies via KubeArmor to detect, contain, and block exploitation attempts in real time.
CVE-2023-38408 represents one of the most critical vulnerabilities discovered in OpenSSH in recent years, earning a CVSS score of 9.8. This remote code execution (RCE) flaw affects OpenSSH’s PKCS#11 feature in ssh-agent versions prior to 9.3p2, potentially allowing attackers to execute arbitrary code on vulnerable systems. Understanding this vulnerability is crucial for cybersecurity professionals and system administrators managing SSH infrastructure, especially in environments relying on SSH agent forwarding for secure connections.
Understanding the CVE-2023-38408 Vulnerability
CVE-2023-38408 stems from an insufficiently trustworthy search path in OpenSSH’s PKCS#11 feature within ssh-agent. The vulnerability was discovered by the Qualys Security Advisory team and disclosed on July 19, 2023. It allows attackers to exploit SSH agent forwarding, enabling remote code execution when connecting to attacker-controlled systems. The flaw exists due to a flaw in handling shared libraries used by ssh-agent, particularly how it interacts with the PKCS#11 standard for cryptographic tokens.
Key Technical Details:
- Affected Component: OpenSSH ssh-agent PKCS#11 feature
- Vulnerable Versions: All versions before 9.3p2
- CVSS Score: 9.8 (Critical)
- Attack Vector: Network-based exploitation
- Root Cause: Incomplete fix for CVE-2016-10009
This vulnerability exploits ssh-agent’s ability to load and unload shared libraries from system directories such as /usr/lib/ via the PKCS#11 interface. When SSH agent forwarding is enabled, attackers can leverage the dlopen() and dlclose() operations to load malicious shared libraries, triggering remote code execution on compromised systems. The exploitation bypasses modern security protections like Address Space Layout Randomization (ASLR), Position Independent Executables (PIE), and No eXecute (NX) protections.
Exploitation Mechanism and Attack Scenarios
CVE-2023-38408 operates through a sophisticated attack chain that involves manipulating shared libraries. The attack requires SSH agent forwarding to be enabled, which is commonly used in environments where SSH agents store and forward SSH keys securely. Once this is established, attackers can manipulate shared libraries to trigger remote code execution.
Attack Requirements:
- SSH agent forwarding must be enabled: SSH agent forwarding allows an attacker to forward the SSH agent from one system to another, effectively inheriting the agent’s environment.
- Agent forwarded to attacker-controlled system: The attacker must control the target system where SSH agent forwarding is directed, allowing them to manipulate the SSH environment.
- Access to manipulate shared libraries: Attackers need the ability to place malicious shared libraries in directories like /usr/lib/, where ssh-agent searches for libraries to load.
Technical Exploitation Process:
- Attacker gains control over a system receiving forwarded SSH agent: The attacker either compromises a system or controls an environment receiving SSH agent connections.
- Malicious shared libraries are placed in /usr/lib/: The attacker places crafted shared libraries designed to exploit the vulnerability in system directories.
- PKCS#11 functionality triggered: The attack leverages ssh-agent’s PKCS#11 feature, which loads libraries from directories like /usr/lib/, triggering malicious code execution in the process.
- Code execution achieved through library loading: By exploiting the shared library loading mechanism, the attacker executes arbitrary code, often with elevated privileges, resulting in a complete system compromise.
The attacker can bypass modern protections, such as ASLR, PIE, and NX protections, by chaining side effects from the shared library loading operations, making it more challenging to defend against.
Impact Assessment and Risk Analysis
CVE-2023-38408 poses significant risks to organizations using SSH infrastructure, particularly those employing agent forwarding in their authentication workflows. Exploitation of this vulnerability can have severe consequences, including complete system compromise, lateral movement within network environments, and exposure of sensitive credentials.
Primary Risk Factors:

Organizational Impact:
- Compromise of development environments: In environments where SSH keys are used for authentication, the compromise of an SSH agent can lead to exposure of sensitive credentials, source code, or infrastructure configurations.
- Potential lateral movement: Attackers who gain access to one system through agent forwarding can use it as a foothold to compromise additional systems, spreading throughout the network.
- Risk to automated systems: Automated systems or continuous integration/continuous deployment (CI/CD) pipelines that rely on SSH agent forwarding for secure connections are particularly vulnerable to this exploit.
- Exposure of sensitive authentication credentials: Malicious actors could steal SSH private keys and other sensitive authentication credentials, allowing for further attacks within the organization.
Detection and Monitoring Strategies
Identifying potential exploitation of CVE-2023-38408 requires proactive monitoring of SSH agent activities and library loading operations. This involves tracking unusual behavior from ssh-agent processes and detecting suspicious library loading activities.
Detection Indicators:
- Unusual shared library loading: Keep an eye out for unexpected shared libraries being loaded into memory, especially from /usr/lib/ directories.
- Unexpected SSH agent forwarding connections: Monitor for SSH agent forwarding that appears anomalous or originates from untrusted systems.
- Anomalous process spawning from ssh-agent: Detect any suspicious processes spawned by ssh-agent, as these may indicate exploitation attempts.
- Suspicious PKCS#11 module loading: Monitor for unexpected or unauthorized PKCS#11 module loading, which may indicate malicious shared library execution.
Monitoring Recommendations:
- Implement SSH connection logging: Log all SSH connection attempts and agent forwarding activities to help identify potential security incidents.
- Monitor file system changes in library directories: Track changes to directories like /usr/lib/ to detect when malicious shared libraries are placed or modified.
- Track ssh-agent process behavior: Monitor the behavior of ssh-agent processes, especially the spawning of unexpected child processes.
- Deploy endpoint detection solutions: Implement endpoint detection and response (EDR) tools that are capable of monitoring SSH activities and identifying abnormal behavior associated with remote code execution.
Organizations should establish baseline SSH usage patterns to identify deviations that could indicate exploitation attempts.
Mitigation and Remediation Steps
To mitigate CVE-2023-38408, organizations must take immediate action by patching vulnerable systems, hardening SSH configurations, and strengthening operational security measures.
Immediate Actions:

Configuration Hardening:
- Disable SSH agent forwarding: If SSH agent forwarding is not required, disable it in SSH configuration files to reduce exposure to potential attacks.
- Implement strict SSH key management policies: Ensure that SSH keys are securely stored and used, limiting access to sensitive systems.
- Configure SSH client restrictions: Apply restrictions on which users or hosts are allowed to use SSH agent forwarding.
- Review and limit PKCS#11 module usage: Limit the use of PKCS#11 modules and ensure that only trusted modules are loaded.
Long-term Security Measures:
- Establish regular SSH software update procedures: Create a schedule for regular software updates and vulnerability scanning to ensure that SSH-related vulnerabilities are promptly addressed.
- Implement network segmentation: Isolate SSH infrastructure to reduce the spread of potential attacks and minimize the impact of successful exploitation.
- Deploy monitoring for SSH agent activities: Continuously monitor for suspicious SSH agent activities that could indicate attempts to exploit this vulnerability.
- Conduct regular security assessments: Regularly assess SSH configurations and infrastructure for security weaknesses to proactively address emerging threats.
How AccuKnox Helps Mitigate CVE-2023-38408
AccuKnox, a Zero Trust CNAPP and runtime security platform, provides policy-driven protection and real-time visibility that can effectively help mitigate OpenSSH vulnerabilities like CVE-2023-38408.
Runtime Enforcement via KubeArmor

AccuKnox’s KubeArmor enforces least privilege policies at runtime, preventing unauthorized library loading (dlopen()) and execution of malicious binaries.
Even if an attacker gains access via SSH forwarding, KubeArmor blocks unauthorized process and file access attempts.
SSH and Agent Activity Monitoring
Using AccuKnox Runtime Observability, organizations can detect:
- Unexpected ssh-agent spawning new processes
- Unapproved shared libraries loaded in /usr/lib/
- Deviations from baseline SSH usage patterns
Microsegmentation and Zero Trust Controls

AccuKnox implements microsegmentation policies to isolate SSH workloads, ensuring even if one node is compromised, lateral movement is contained.
Automated CVE Detection and Compliance
AccuKnox’s CVE scanning and compliance reporting continuously identifies unpatched OpenSSH versions and flags deviations from security benchmarks like CIS and NIST.
Integration with Cloud-Native Infrastructure

For hybrid or Kubernetes-based deployments, AccuKnox integrates directly with containerized environments, protecting OpenSSH services, DevOps pipelines, and PKCS#11-enabled workloads from real-time exploitation attempts.
In summary: AccuKnox enforces proactive runtime security and Zero Trust posture that effectively mitigates vulnerabilities like CVE-2023-38408 by combining policy control, visibility, and runtime prevention.
Conclusion

CVE-2023-38408 reinforces the importance of keeping OpenSSH installations up to date and enforcing strong SSH security practices. Since the flaw stems from an incomplete fix for a prior vulnerability, it highlights the need for continuous vulnerability management, runtime protection, and Zero Trust enforcement.
Organizations should upgrade to OpenSSH 9.3p2 or later, disable unnecessary agent forwarding, and maintain strict monitoring of ssh-agent activities.
With AccuKnox, teams can go beyond patching, leveraging runtime enforcement, SSH activity visibility, and microsegmentation to prevent exploitation attempts like those seen in CVE-2023-38408. By integrating AccuKnox’s Zero Trust CNAPP and KubeArmor runtime protection, organizations can detect, contain, and block malicious library loads and unauthorized SSH behaviors in real time.
Strengthen your OpenSSH security posture with AccuKnox. Schedule a Demo to see how runtime Zero Trust policies can protect your SSH environments from advanced exploits.
FAQs
1. What causes CVE-2023-38408 in OpenSSH?
It’s caused by insecure shared library handling in ssh-agent’s PKCS#11 feature, allowing malicious libraries to load during agent forwarding.
2. Which OpenSSH versions are affected?
All versions prior to OpenSSH 9.3p2 are affected by this vulnerability.
3. How can organizations detect exploitation attempts?
By monitoring ssh-agent behavior, tracking anomalous shared library loads, and using EDR or runtime security tools like AccuKnox KubeArmor.
4. What’s the best immediate mitigation?
Upgrade to OpenSSH 9.3p2+, disable SSH agent forwarding, and limit PKCS#11 module usage.
5. How does AccuKnox protect against such SSH-based attacks?
AccuKnox enforces runtime policies, prevents malicious library loads, monitors SSH activity, and ensures Zero Trust compliance across workloads.
Get a LIVE Tour
Ready for a personalized security assessment?
“Choosing AccuKnox was driven by opensource KubeArmor’s novel use of eBPF and LSM technologies, delivering runtime security”

Golan Ben-Oni
Chief Information Officer
“At Prudent, we advocate for a comprehensive end-to-end methodology in application and cloud security. AccuKnox excelled in all areas in our in depth evaluation.”

Manoj Kern
CIO
“Tible is committed to delivering comprehensive security, compliance, and governance for all of its stakeholders.”

Merijn Boom
Managing Director




